Obstacle Avoider

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)

Awesome! I think this is the first complete robot we’ve seen where a Maestro is the only controller and that isn’t based on our little walking bug example. Thanks for sharing. What other programming experience did you have going into this, and how has working with the Maestro been?

- Jan

Thanks! Eventually my Physics students will be doing this as their first robotics project next year. So I need to minimize cost and get as much as I can out of just the maestro. Ultimately though I would like my students to build their own ideas. This will hopefully just becoming a way for them to learn and have something they can take home as a starting point. I only took 2 semesters of Java while I was in college(you can probably see the remnants of that in my code lol). Working with the stack has been a fun challenge. Right now I’m working on developing structures to make future projects much easier to code. I have a basic for loop, a switch statement, and a sort of fuzzy way to store a variable.

In any case the Maestro is awesome.

That’s really cool, and I am glad you are having so much fun with the Maestro! Have you been using PEEK and POKE to store variables?

One thing I wanted to mention is that you can get rid of some of the dead zone of your distance sensors by mounting them as far back as possible rather than right on the edge of the chassis.

Anyway, good luck with your class and please let us know how it goes!

-Paul

I hadn’t even though about moving the sensors. A silly oversight. I have modified the code a bit. I change a few of the conditions to be a little more aggressive and also reduced the delays. I found an old servo and will probably start working on making the sensors swivel now.

Thats a cool robot, I’m trying to do something similar using a PIC micro controller with the whole thing built on the frame of an rc car but I have yet to have any great success, still seeing stuff like your robot just makes me want to try even harder so that I can say this is my achievement. Well done, it looks great!