Algorithm Structure
The algorithms for this project was written in Python. 6 files were made. The reason there were so many was both for readability and because this was a group project. Each member could work on a separate stage of the project. Below are the files and what they contain:
- DynDefs: Holds functions to interface with the dynamixels. Every other file imports this file.
- ForwardWalk: Holds the code to make the robot legs move forward.
- BackwardsWalk: Holds the code to make the robots legs move backward
- TurnLeft: Holds the code to make the robot legs turn left
- TurnRight: Holds the code to make the robot legs turn right
- main: Holds the code that contains the key controller. This is the code that should be run from the terminal. Allows the user to control the robot.
Moving the Joints
The first functions to be written were the simple functions that would move the dynamixel servos to a certain angle. The first code that was needed was to convert an angle to dynamixel ticks. A dynamixel has 0-1023 ticks that go from 0-300 degrees. You would not want to have to calculate the tick value for each angle you use. Below is the code for doing this conversion:
def rad2dyn(rad):
return np.int(np.floor( (rad + (np.pi*300/360))/(2.0 * np.pi * 300/360) * 1024 ))
def dyn2rad(en):
return (en / 1024.0 * 2.0 * np.pi – np.pi) * 300/360
After we have these conversions, we needed a one line function that would set the goal of a certain dynamixel by its ID. This function made the code much more readable. Below is this code:
def setGoal(myActuators,ID,val):
for actuator in myActuators:
if actuator.id==ID:
_________actuator.goal_position = rad2dyn(val)
Keeping Balance
To keep balance we used ZMP(Zero Moment Point) walking. This means that we moved very slowly and always kept our center of gravity over our feet. This is by far the slowest way to walk, though it is very easy to implement. We take walking by phases:
- Bend Knees.
- Move center of gravity over left leg.
- Lift the right leg into the air.
- Put the right leg back down further forward than before.
- Put the center of gravity over right leg.
- Lift the left leg into the air.
- Put the left leg back down further forward than before.
- REPEAT 2-7 as many times as desired.
- Stand straight up.
These phases are called keyframe phases. We made Phase structures like this for every movement: Walking Forward, Walking Backward, Turning Left, Turning Right.
Below is and example of executing a keyframe phase. This is from the Walking Forward code:
#<PHASE 6> move the left leg into the air
amount=0.42
while(amount<=.72):
____setGoal(myActuators,LHP,amount)
____setGoal(myActuators,LKN,2*amount)
____setGoal(myActuators,LAP,-amount)
____net.synchronize()
____time.sleep(0.3)
____amount +=0.1
setGoal(myActuators,RHP,-0.42)
net.synchronize()
time.sleep(1)