After a long weekend I finally got the Python code to work the way I wanted it to and I am able to more easily control the motors. Most of my time over the last several days has been spent figuring out how Python works and not really messing with the robot motion directly. Because of that I'm tired and don't have the time to get a really smooth walking motion today. What I currently have does work but it jerks along the floor and doesn't make the 'forward motion' that it should be doing based on how much the legs are actually moving. I do count this as some success because it should be easier from where I am at now to get it to at least walk.
What you can see from the video is that all 4 of the legs are moving in cyclical 'walking' motions but they are not coordinated enough to really get the robot to move forward. This is because at a few points in the cycle some of the legs are moving forward and others are not. So when it's trying to walk on the floor the legs that are not moving are being dragged along!!! Oh well like I mentioned I have spent all my energy getting the code to work and not on actually the motion.
The progress that I did make this weekend was I managed to figure out how to use the import statement in Python to bring in a chunk of code that defines some custom commands that I wrote. What that means is now I can write a script like this:
PS.ServoPos(6,2200)
PS.ServoPos(7,4300)
time.sleep(.2)
Below is the Python code that I wrote to help with the programming of the Pololu board. The Pololu requires position commands that range from 500 to 5500 to position the motors. When sending the position to the Pololu board you have to take a position like 3800 and convert it into 2 bytes of data with the Most Significant Bit of each of those two bytes set to 0, shifting bits around as needed.
Anyway doing that by hand is a pain so I wrote the program below to do it for me. This was handy when figuring out positions that I wanted to have defined in the function calls that I wrote.
# Pololu Range Converter
# Written By Otto Belden Oct 2009
# http://ottobelden.blogspot.com/search/label/Robotics
# This will take a input from the console and print out the
# high and low byte that the Pololu needs to position the servo
# with the MSB of each of the two bytes 0 as required by Pololu
#
import sys
# Set a default position
pos = 2500
while pos != 0:
pos = int(raw_input("Give me a number or 0 to exit "))
if pos == 0:
print "Exiting..."
break
# get the data 1 byte (high byte)
data1 = (pos-(pos&127))/128
# get the data 2 byte (low byte)
data2 = pos&127
print " Position = ", pos, "High Byte = Ox%x"%data1,"Low Data = 0x%x"%data2
The progress that I did make this weekend was I managed to figure out how to use the import statement in Python to bring in a chunk of code that defines some custom commands that I wrote. What that means is now I can write a script like this:
PS.ServoPos(6,2200)
PS.ServoPos(7,4300)
time.sleep(.2)
So what is going on in the above code is I can just directly address the particular motor I want and send it to a particular position. For example the first command PS.ServoPos(6,2200) is sending servo number 6 to position 2200 !!! WOW! I'm sure all you Python gurus out there are laughing at me but considering I'm not a programmer and I have only been using Python now for 12 days or so it's an accomplishment.
Here are the steps that I listed in my Last Post that I wanted to get done with updates to each:
1) figuring out a clean way to mount the Pololu board to the robot base with it's one mounting hole
I mounted the board and made a strain relief for the cables (see picture below)
2) cable management to make sure the servo wires don't get all tangled up while it's running
2) cable management to make sure the servo wires don't get all tangled up while it's running
I can't say that they are under control but the cables now don't get tangled!!! (see picture below)
3) using the jog program to get the remaining leg hard stop values
3) using the jog program to get the remaining leg hard stop values
I got this done and wrote a little converter program to help (see source code below)
4) hours of coding and testing to make this thing walk!!!
4) hours of coding and testing to make this thing walk!!!
When I wrote hours of coding and testing I was underestimating the task... lets say DAYS of coding!
A picture of the Pololu board mounted to the Epson Printer Base that I cut up and turned into the robot base. The black plastic on top of the board with the wires coming out of it is a piece of 0.04" thick ABS plastic that I cut and screwed to the base. There is a second piece of ABS as well that is sandwiching the wires in there with some rubber bands to hold it together. It's not elegant but it works to keep the Futaba servo connectors from being pulled or worked off the Pololu board while the robot is running.
The next thing to do at this point is refine the walk cycle to get all the legs to move together so it can walk instead of dragging its feet along the floor. As soon as I get that done I'll post another video of it walking.
Below is the Python code that I wrote to help with the programming of the Pololu board. The Pololu requires position commands that range from 500 to 5500 to position the motors. When sending the position to the Pololu board you have to take a position like 3800 and convert it into 2 bytes of data with the Most Significant Bit of each of those two bytes set to 0, shifting bits around as needed.
So 3800 decimal =
00001110 11011000 binary
which then has to be converted to
00011101 01011000
which is equal to two bytes of
0x1D 0x58
# Pololu Range Converter
# Written By Otto Belden Oct 2009
# http://ottobelden.blogspot.com/search/label/Robotics
# This will take a input from the console and print out the
# high and low byte that the Pololu needs to position the servo
# with the MSB of each of the two bytes 0 as required by Pololu
#
import sys
# Set a default position
pos = 2500
while pos != 0:
pos = int(raw_input("Give me a number or 0 to exit "))
if pos == 0:
print "Exiting..."
break
# get the data 1 byte (high byte)
data1 = (pos-(pos&127))/128
# get the data 2 byte (low byte)
data2 = pos&127
print " Position = ", pos, "High Byte = Ox%x"%data1,"Low Data = 0x%x"%data2
Nice mounting job! I'm excited to see how well it walks; 4 legged bots tend to be harder to balance than their 6 legged counterparts.
ReplyDeleteBryan,
ReplyDeleteThanks! It does walk right now but I need to tweak the leg movements to make it smooth. Hopefully by the end of the week!
- Otto