United Kingdom
Asked — Edited
Resolved Resolved by Dunning-Kruger!

Two Distance Sensors (Script)

Hi there,

sorry if this is a duplicated post, my tablet appears not to have posted my original.

i am loving my dev kit and learning stacks, but i apart from some Arduino i have not ventured into programming.

what i am looking at is as follows, i currently have an ultrasonic sensor on a servo "scanning" as Traxx moves forwards, however i have noticed that it sometimes it cause a blind spot. so i was thinking by adding a IR sensor constantly facing forward and some coding i could avoid the blind spot by allowing the EZ-B to "decide" which sensor to listen too, depending upon distance.

thanks


ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

#1  

Very simple to do...



repeatUntil(1=2) #repeat forever
$ping=GetPing(D0,D1) #Read ping sensor
$IR=getADC(adc0) # Read the IR sensor, value increases as distance decreases

If($ping<20)

# do something

elseif($IR>100) 

# do something else

endif

sleep(100)
endrepeatUntil


United Kingdom
#2  

thanks @Richard R, i will try that over the weekend.

:D

PRO
Synthiam
#3  

Or you can use another Ultrasonic Ping Radar control but set the servo to NA - since there isn't one:) And voila! No scripting needed

United Kingdom
#4  

Thanks @DJ Sures, i will also try that to see which works best - the great thing is that both way's expand my knowledge and understanding :D

United Kingdom
#5  

Hi @Richard R,

i have been playing with the code above and trying to work out the best way to have the ez b read the two sensors.

i understand that after the "if" and "else if" funtions i need to add a command, however i believe that i need to put a function in thats says

repeatUntil(1=2) #repeat forever $ping=GetPing(D0,D1) #Read ping sensor $IR=getADC(adc0) # Read the IR sensor, value increases as distance decreases

If($ping>20, $IR<20) = if the ping is greater than 20 Cms and the $IR sensor is less than 20cms

i want it to read the IR sensor and then use the Movement Panel avoid the object endif

sleep(100) endrepeatUntil

but i can't find the code to put the Movement Panel back in control?

regards and thanks once again

stress

United Kingdom
#6  

This looks like the perfect topic to stop me constantly checking my outside camera...

So if I have this correct you have one ping sensor and one IR sensor?

If so the code you need will be similar to below (modify to suit your requirements and sensors)...


# Set a label for a loop (alternative to repeat)
:loop

# Fetch the sensor values
$ping = GetPing(D0, D1)
$ir = GetADC(ADC0)

# Check the sensor values
If($ping &gt; 20 AND $ir &lt; 20)
# If the statement is true
  # Stop the robot
  Stop()
  # Turn left for 250ms
  Left(250)
  # Continue forwards
  Forward()
EndIf

# Sleep for 100ms
Sleep(100)

# Loop back to the start
Goto(loop)

You nearly had the IF statement correct. Think of IFs logically, you wanted to have two values meet the requirements... so IF the ping is more than 20 AND the IR is less than 20. If you wanted it to be true if ping is more than 20 or ir is less than 20 use the OR expression.

Movement panel controls are;


Forward()
Reverse()
Left()
Right()
Stop()

Look them up in the EZ-Script manual for their parameters.

#7  

@Rich... Thanks for cleaning up my code.... You probably should have gotten the credit for this one too...

Anyway.... I kinda' feel bad this break has still got you rattled, though....

United Kingdom
#8  

It'll be fine as soon as I get the moat installed:)

United Kingdom
#9  

Thanks @Rich and @Richard r. My next choice was to add ping_wait funtion to tell traxx to wait until the ping reading was higher than the ir reading, then move away from the object Am I right in thinking that by adding the forward command in, its like telling the system to revert back to scanning when moving forward until the ping sensor/ir sensor detects an object?

United Kingdom
#10  

My latest Ping Roam uses ping_wait in it's turning action, basically;


Left()
Ping_Wait(D0,D1, Higher, 20)
Forward()

Provided somewhere in the script before the whole ping/ir checking process you have a Forward() then ending the checking with a Forward() will make the robot avoid an object then continue on it's way.