Support » Sample Project: Simple Hexapod Walker »
5. Using a Script for Obstacle Avoidance
The Micro Maestro has an internal scripting language that can store sequences, read sensors, and link everything together to form intelligent behaviors, making your hexapod truly autonomous. For complete documentation on the scripting language, see Section 6 of the Micro Maestro User’s Guide.
Once you have set up all of your basic gaits, erase your script, then click the “Copy All Sequences to Script” button on the Sequence tab. This button adds a set of subrountines that you can use to access the various gaits from within a script.
You can then call these subroutines from your script. For example,
begin forward left repeat
will cause the hexapod to repeatedly step forward then turn left, over, and over. You will probably want to take into account the sensor readings, which can be accessed using the GET_POSITION command. Here is an example of a very simple program that uses the sensor readings to try to avoid objects – customize this to get the behavior you want!
start: # back up if both sensors see an object left_sensor right_sensor logical_and if back back back goto start endif # back up and turn right if the left sensor sees an object left_sensor if back right right right goto start endif # back up and turn left if the right sensor sees an object right_sensor if back left left left goto start endif # otherwise, if there is nothing ahead, walk forward forward goto start # returns true if the left sensor sees an object sub left_sensor 4 get_position 512 less_than return # returns true if the right sensor sees an object sub right_sensor 3 get_position 512 less_than return ### Sequence subroutines: ### # back sub back 100 4992 5312 5056 frame_0_1_2 # Frame 0 120 7168 6976 frame_0_2 # Frame 1 100 6528 frame_1 # Frame 2 120 4992 5056 frame_0_2 # Frame 3 return # forward sub forward 100 7168 5312 6976 frame_0_1_2 # Frame 1 120 4992 5056 frame_0_2 # Frame 2 100 6528 frame_1 # Frame 3 120 7168 6976 frame_0_2 # Frame 0 return # left sub left 100 7168 5312 5056 frame_0_1_2 # Frame 0 150 4992 6976 frame_0_2 # Frame 1 100 6528 frame_1 # Frame 2 150 7168 5056 frame_0_2 # Frame 3 return # right sub right 100 4992 5312 6976 frame_0_1_2 # Frame 1 120 7168 5056 frame_0_2 # Frame 2 100 6528 frame_1 # Frame 3 120 4992 6976 frame_0_2 # Frame 0 return sub frame_0_1_2 2 servo 1 servo 0 servo delay return sub frame_0_2 2 servo 0 servo delay return sub frame_1 1 servo delay return