Sharp Distance Sensor 20-150cm

I have been having some problems programming this sensor. I have it correctly connected to a maestro servo controller(12channel). I get an input voltage proportional to the distance of an object. I also have some 10cm sensors also programmed and these work properly. I want my robot to run a sequence when it gets something around its max input of around 130… when I program this input to run the sequence, the robot ignores my isolated distance and runs the corresponding sequence continuously no matter what the distance is. I want my robot to ignore any input less than 130, and anything greater to run the sequence.

I’m sure my problem is in my programming:


if right_turn goto start endif

if left_turn goto start endif

if half_right_turn goto start endif

if half_left_turn goto start endif

if back left_turn goto start endif

goto start

sub Left_bump
10 get_position 0 greater_than

sub Right_bump
1 get_position 0 greater than

sub Left_IR
0 get_position 245 less_than

sub Right_IR
11 get_position 245 less_than

sub 150cm_sensor
9 get_position 130 gretaer_than

I left out my sequence sub routines… The 150cm_sensor is the one giving me problems… everything else works great!


I have edited your post, but in the future please put [code ] and [/code ] tags (without spaces) around your code to make it more readable.

Could you tell me the values of all your inputs at the time when the robot is not behaving as expected? A screenshot of the status tab of the Maestro Control Center would be sufficient, because we can see the values of all the inputs in the Position column.

If any of the other functions ( Left_bump, Right_bump, Left_IR, Right_IR ) return true (1), then the 150cm_sensor function will not be run.

Also, try stepping through your script using the Maestro Control Center to figure out at which point the program stops behaving as you expect.


I have enclosed screenshots of the robot working and the robot not working. I have made sure the other functions are not running when the 150_sensor triggers the sequence. It looks like any value over 30 causes the sequence to run. I need the sequence to run at the input of 130. In these pictures, “top sensor” is the 150_sensor we are looking at. Thanks for your time to help!
robot not behaving.doc (84.5 KB)
robot behaving.doc (84 KB)

Okay… I believe I have solved the problem… I am slightly confused though. I was playing around with numbers in the sub routine for 150_sensor. The number that responds to the correct input is 515. I don’t know why it works, but it does. Maybe you could explain it to me! thanks for all the help!!!

The numbers displayed in the position column of the Maestro Control Center are one quarter of the actual value returned by get_position. This is because for servo channels we wanted to display them in units of microseconds while still internally supporting quarter microsecond resolution.


Thanks for your help. I learn new things every day!!! I appriciate your help!