A simple robot I’m developing. Right now all it does is obstacle avoidance, but I would like to develop it into a self-made platform for any task I wish. The next step is probably to mount a servo in the center with a cross bar so I can swivel all the distance sensors with one servo and get better avoidance. I’ll probably also probably need to add bump sensors to compensate for the dead zone of the sensors.
Materials:
24 channel Maestro
4 analogue distance sensors
2 springrc continuous rotation servos
4xAA battery pack with built in on/off switch
zip ties and lots of hot glue
jumper wires were added to everything so it can easily be debugged and upgraded
Code:
#Range Sensors |Null| .8m| .7m| .6m| .5m| .4m| .3m| .2m|
#Front 7 |20 | 40| 50. | 60.| 70. | 90 .| 110| 130|
#Left 8
#Right 6
#Servos Neutral| Forward| Reverse|
# Left 0 6000 | 4400 | 7600 |
#Right 1 6000 | 7600 | 4400 |
begin
start:
check_sensors #adds 6 true/false values to stack
if #Looking for front, left, and right to be blocked
drop drop drop drop drop
about_face
goto start
endif
if #Looking for front and right to be blocked
drop drop drop drop
veer_left
goto start
endif
if #Looking for front and left to be blocked
drop drop drop
veer_right
goto start
endif
drop drop #dropping unused left and right values
if #Looking for front to be blocked
veer_left
goto start
endif
forward
repeat
sub forward
5200 0 servo
6900 1 servo
100 delay
return
sub turn_right
6800 0 servo
6800 1 servo
1000 delay
return
sub turn_left
5200 0 servo
5200 1 servo
1000 delay
return
sub veer_right
7 get_position 520 greater_than if
turn_right
else
5200 0 servo
#increasing motor speed inversely proportional to distance from obstacle
7 get_position 2 times 6800 plus 1 servo
1000 delay
endif
return
sub veer_left
7 get_position 520 greater_than if
turn_left
else
#increasing motor speed inversely proportional to distance from obstacle
7 get_position 2 times 5200 minus negative 0 servo
6800 1 servo
1000 delay
endif
return
sub about_face
begin
6800 0 servo
6800 1 servo
2000 delay
7 get_position 440 less_than if
goto start
endif
repeat
return
sub check_sensors
#adds the following true/false values to stack(top first)
#all
#front and right
#front and left
#right
#left
#front
7 get_position 160 greater_than
8 get_position 160 greater_than
6 get_position 160 greater_than
7 get_position 160 greater_than 8 get_position 160 greater_than logical_and
7 get_position 160 greater_than 6 get_position 160 greater_than logical_and
7 get_position 160 greater_than 8 get_position 160 greater_than
logical_and 6 get_position 160 greater_than logical_and
return
Feedback on the code and ideas for additions would be greatly appreciated. (this is my first real project so its far from perfect at this point)