Asked — Edited
Resolved Resolved by Rich!

Ultrasonic Sensor And Sharp Ir Sensor

Looking for some help / sample of a script combining the 2 for navigation. This is on a omnibot 5402. I have the IR sensor mounted above his speaker. The ultra sonic is on a sweeping servo right above the IR sensor. I tried playing with Richs ping roam script and he just spins in circles. I would be grateful for any help with this.

Skip to comments


Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

United Kingdom

The thing to remember is ultrasonic measures how far away something is (i.e. the greater the distance the larger the result) and IR measures how close something is (i.e. the closer the object the higher the number).

To get the IR data from the sensor, assuming it's connected to ADC0, you would use a GetACD() command i.e.

$IRSensor = GetADC(ADC0)

To get the ping you use

$PingSensor = GetPing(D0, D1)

Then use those within an if i.e.

IF($IRSensor > 200 OR $PingSensor < 100)
  Say("There is an object in my path")

@ Rich how would I intergrate this into your ping roam script?

United Kingdom

Edit the "GetPing" script in the script manager so it also fetches the IR reading, so adding in something like this;

$IRdistance = GetADC(ADC0)

where the comment about adding in extra sensor code is.

The editing the "Detection" script (as indicated in bold);

# Check the current distance against the max allowed distance
IF ($currentdistance &lt;= $maxdistance <strong>OR $IRdistance &gt; $maxirdistance</strong>)
  # If the current distance is below the max distance start avoiding
  CONTROLCOMMAND(&quot;PingRoam&quot;, SCRIPTSTARTWAIT, &quot;Avoidance&quot;)

It would require a new variable for $maxirdistance to be added to the "Start" script so it knows what the maximum/minimum distance for the IR should be for the above IF nest.

More work would be required for the turning as the latest PingRoam had smart turning which basically let the ping sensor determine when it was OK to stop turning. Using both ping and ir you would need to alter this from using a PingWait() command, most likely by using a new script which checks both the ping and the adc and when one or the other says it is OK to move then stop turning.

It would be quite a big edit to the script but it shouldn't be too difficult. It is something I have been trying to get on to for a while since Melvin also uses both ping and IR sensors but I haven't had time to touch it yet.


I would say the Richard Nailed it. Please, Don't forget the Thank him and close the thread.


Thanks rich just the info I was looking for