Re:Ultrasonic sensor programming

  1. 9 years ago

    MarkO

    10 Sep 2009 Albany, Oregon, USA, North Wes...

    @guitarmaster I recently tried to program my robot using the Ultrasonic sensor along with the Rc control. it is programed in an if else statement so that it will report to the Rc transmitter unless it gets to close to an object 12'' away. at that point the robot will reverse for .5 seconds and turn right for .5 seconds. the problem is, when I drive op to an object the sensor doesn't seem to respond (except for the extremely rare occasion when I drive very slowly up to the object, it will sometimes function) however when I back away from an object I have collided with it will reverse and turn on its own for the instructed amount of time.

    Which Compiler are you using?

    Can you Post Your Code??

    How many Ultrasonic Sensors are you using?

    It might be as Simple as the Test Criteria being so Narrow, that the only time it is met is when you travel Slow..

  2. LegoMindstormsmaniac

    11 Sep 2009 Owings Mills, Maryland BNS

    the most obvious thing i can think of is, are you asking if the object is EXACTLY 12" away? or are you asking if the object is LESS than 12" away, that is what seems to be the problem, because when you drive fast, it doesn't get the reading in time, but when you drive slowly it is, make sure you always make the amount you are checking less than or greater in a situation like this, so that even if it misses the number it will get it the next time it checks :)

  3. I am using one sensor, I can't seem to upload my code, and if by compiler you mean the programing software, I am using easyC version 2.8.0.1. About the moving slow, it only does that on the rare occasion. it almost always works going backward.

  4. MarkO

    11 Sep 2009 Albany, Oregon, USA, North Wes...

    @guitarmaster I am using one sensor, I can't seem to upload my code, and if by compiler you mean the programing software, I am using easyC version 2.8.0.1. About the moving slow, it only does that on the rare occasion. it almost always works going backward.

    One Ultrasonic.

    EasyC 2.8.0.1 Compiler.

    OK... That is a good start...

    No conflict between two Ultrasonic Sensors.

    The Ultrasonic Sensor has two cables, One Marked "Input" and One Marked "Output". I don't know quite what the difference is, but could these be backwards.

    The "current" Inventors Guide , shows both the "Input" and the "Output" being "plugged in" to the Interrupts Block.
    EasyC needs to have the "Input", "plugged in" to the Analog/Digital Block and the "Output", "plugged in" to the Interrupts Block.

    Make a note on which Port Numbers you use, and check that EasyC has the correct Port Numbers for each Sensor Cable.

    Also, can you Cut and Paste you EasyC Main.C routine here, or Zip up your .BDS and .ECP files of your Project and attache them so we can look at your Code??

    I would guess that your Code is the most likely issue...

  5. The cables are plugged into the correct ports (input in analog/digital port 11, output in interrupts port 1). My code is attached (hopefully).

  6. MarkO

    12 Sep 2009 Albany, Oregon, USA, North Wes...

    @guitarmaster The cables are plugged into the correct ports (input in analog/digital port 11, output in interrupts port 1). My code is attached (hopefully).

    You only Ziped the .ECP file. We need both, or at least the .BDS file.

  7. Here is the file you wanted.

  8. MarkO

    12 Sep 2009 Albany, Oregon, USA, North Wes...

    @guitarmaster Here is the file you wanted.

    OK... It was my first thought..

    "It might be as Simple as the Test Criteria being so Narrow, that the only time it is met is when you travel Slow.. "

    ..... if ( Sonic == 12 ) .....With EasyC 2.x, the return Value from "GetUltrasonic (...)" is between 2 - 100.

    Your Automatic Code will only activate with the value of 12, all other values are Operator Control..

    If the Robot is moving Fast, the Reading from the Sensor might never read "12". It would read Greater than "12", and then the next reading it would read Less than "12".

    I have the PING))) Ultrasonic Sensors, not the Vex Ultrasonic Sensors.

    Here is the readings I received with the PING))) Sensors, with a good Reflector Surface.

    (Tested from a Linoleum Floor, PING))) is 4.25 Inches from the floor)
    08-10 at 01 Inch distance.
    24-26 at 12 Inches distance.
    40-42 at 24 Inches distance.
    58-60 at 36 Inches distance.
    75-77 at 48 Inches distance.
    93-95 at 60 Inches distance.
    99 is the Max Value.

    You might get different Return Values with the Vex Ultrasonic Sensors, you will need to test and find out.

    But, assuming that the Vex Ultrasonic Sensors report the same or similar values as the PING))) Ultrasonic Sensors, my Table above indicates with a Good Reflector Surface, the reading for ~12" is 24-26. Since you want Operator Control, with a distance over 12", you would change your above code to read like this:
    ..... if ( Sonic < 28 ) .....The FULL PROGRAM would read like this:
    #include "Main.h" void main ( void ) { int Sonic; StartUltrasonic ( 1 , 11 ) ; while ( 1 == 1 ) { Sonic = GetUltrasonic ( 1 , 11 ) ; if ( Sonic < 28 ) { SetMotor ( 3 , 0 ) ; SetMotor ( 2 , 255 ) ; Wait ( 500 ) ; SetMotor ( 3 , 0 ) ; SetMotor ( 2 , 0 ) ; Wait ( 500 ) ; } else { Tank2 ( 0 , 3 , 2 , 3 , 2 , 1 , 1 ) ; } } }The moment the Robot gets closer than 12" to an object, the Automatic Code will take over. Depending on the type of Surface or Angle you are approaching, you might get closer than 12". Also, remember that since the Back of the Robot has no sensor, it won't detect objects when backing up..

    Read the thread Ping)) Ultrasonic sensor , for the Full Description of the above table, and the Pictures..

    Also, other important Ultrasonic information can be found in these threads:
    Ultrasonic sensor
    Trying to use two Ultrasonic Sensors
    Ultrasonic Sensor Hard Code Help
    Problem With Ultrasonic Sensor Coding

    And a compilation of links:
    Need Assistance- Ultrasonic sensor

    Thank You for posting your Code.. It was a great help... ;)

  9. Perfect, I just need to play with the distances a little bit.

  10. Rick TYler

    14 Sep 2009 Teachers/Coaches, Event Partner, V5 Beta Moderator Redmond, Washington Founder of Exothermic Robotics

    MarkO is a treasure on this forum. :)

  11. MarkO

    14 Sep 2009 Albany, Oregon, USA, North Wes...

    @guitarmaster Perfect, I just need to play with the distances a little bit.

    So you tried the Code and it seems to work???

    That is good..

    I used a "PrintToScreen(...)" to display the Return Values from the Ultrasonic Sensor, so I could see the Values to make that Table..

    If you have a Laptop or place the Robot on Blocks and move a Highly Reflective Surface closer and farther from the Robot.

    You can then leave the Programming Cable "plugged in", and with a Small Code Modification, and changing to the Terminal Window in the IFI/Intelitek downloader..

          ....
          PrintToScreen ( "%d\n" , (int)Sonic ) ;
          ....
    

    The FULL PROGRAM would read like this:
    #include "Main.h" void main ( void ) { int Sonic; StartUltrasonic ( 1 , 11 ) ; while ( 1 == 1 ) { Sonic = GetUltrasonic ( 1 , 11 ) ; PrintToScreen ( "%d\n" , (int)Sonic ) ; if ( Sonic < 28 ) { SetMotor ( 3 , 0 ) ; SetMotor ( 2 , 255 ) ; Wait ( 500 ) ; SetMotor ( 3 , 0 ) ; SetMotor ( 2 , 0 ) ; Wait ( 500 ) ; } else { Tank2 ( 0 , 3 , 2 , 3 , 2 , 1 , 1 ) ; } } }You can see what the Ultrasonic Sensor is reporting for various Distances.

    Try Different Material for your Reflective Surface as well, so that you can see how they reflect the Sonar Waves differently..

  12. MarkO

    14 Sep 2009 Albany, Oregon, USA, North Wes...

    @Rick TYler MarkO is a treasure on this forum. :)

    Thanks!!! I appreciate the "kind words".. I am always glad to help..

  13. Thanks mark.

  14. MarkO

    15 Sep 2009 Albany, Oregon, USA, North Wes...

    @guitarmaster Thanks mark.

    Your Welcome...

    What value did you find was the correct one for the Vex Ultrasonic sensors at 12"??

  15. 4 days ago
    Edited 4 days ago by jeyssa512

    For this year turning point I am trying to come up with a autonomous code and I think it would be a good idea to use a ultrasonic sensor to tell the robot when it is close to a flag then I can shoot the flag. I also was wondering how for is one move for a robot and when you program how do you make the robot go a certain distance.

  16. Barin

    Oct 11 Arizona

    @jeyssa512 For this year turning point I am trying to come up with a autonomous code and I think it would be a good idea to use a ultrasonic sensor to tell the robot when it is close to a flag then I can shoot the flag. I also was wondering how for is one move for a robot and when you program how do you make the robot go a certain distance.

    Please create a new thread with your post. Do not revive old threads, especially for such a generic question.

 

or Sign Up to reply!