PDA

View Full Version : Getting arbotix_python diff_controller to hold a straight line



Pi Robot
12-21-2011, 12:23 PM
Hey Fergs,

I am testing out the arbotix_python diff_controller for the first time on a new robot base that (as you know) uses these Pololu motors and encoders (http://www.pololu.com/catalog/product/1443). After launching my arbotix_python node with my PID parameters (see below), I put the robot on a linoleum floor and published a /cmd_vel message to move straight ahead at 0.2 m/s for a few seconds before hitting Ctrl-C. Instead of going straight, the robot drifted to the right 0.0904 meters in 0.957 meters. I got these numbers from the /odom topic which showed the position coordinates as x: 0.904 and y: -0.0957 at the end of the run. So the odometry "knows" that the robot drifted to the right. Is there something I need to adjust to my PID parameters to fix this?

My yaml file looks like this:


port: /dev/ttyUSB0
baud: 115200
write_rate: 25.0
controllers: {
# Pololu motors: 1856 cpr = 0.3888105m travel
base_controller: {type: diff_controller, base_width: 0.249, ticks_meter: 4773, Kp: 15, Kd: 15, Ki: 0, Ko: 200, accel_limit: 1.0 }
}
analog_sensors: {
voltage: {pin: 6, rate: 1}
}

EDIT: I just tried the test using the default PID parameters as listed here (http://www.ros.org/wiki/arbotix_python/diff_controller) and got nearly identical results--same drift to the right.

Thanks!
patrick

lnxfergy
12-21-2011, 01:00 PM
What is the "theoretical" max speed of the robot? If you're getting close to that, it may be that one motor literally cannot provide enough power to keep up. If you set speed to 0.1m/s, does it work better?

If the issue isn't a weak motor, we can calculate some K values (I've been meaning to write a tutorial on this). So a couple off the-cuff-calculations:
ticks/meter = 4773
so 0.2m/s = ~1000 ticks/s
PID runs at 30hz = ~30 ticks/frame

So, at start, when motor is not running we have an error of 30 (cur value will be 0, desired is 30), so motor PWM is increased by (Kp*30 + Kd*(30-0))/Ko = 4 (integer divide). If we guess that 0.2m/s is half speed (or 128/256 for motor speed), it will take at least 1s to ramp up to full speed (and might be bouncy around the setpoint).

You'll notice that the 15,15 that works for Maxwell is based on 81k ticks/meter. The default values were based on about 30k ticks/meter if I recall. What I would do is the following:

1. Set Ko to 50 (10% of ticks/meter)
2. Set Kp to 10, Kd to 0. Increase Kp in increments of 3-5 until you get a bit of oscillation (you'll hear the motors revving up/down)
3. When Kp causes oscillation, back it off to the previous good value, and start ramping Kd until you get something you like.

-Fergs

Pi Robot
12-21-2011, 06:45 PM
Thanks Fergs--this sounds very promising. Not sure if I'll get time to test it before tonight's HBRC SIG meeting but I'll post back the results when I do. In the meantime, the theoretical max speed for the robot is 100 RPM (no load) with a 4 7/8" diameter wheel or 0.65 m/s. (I pointed to the wrong motors in my original post. I actually have the 100:1 version shown here (http://www.pololu.com/catalog/product/1446).)

--patrick

Pi Robot
12-23-2011, 10:14 AM
Success! Your estimate of Kp=10 was almost bang on. Setting Kp=12 seemed to give the best result. After that, setting Kd=12 also seemed to give the best result. I'm now getting around 4-6% lateral drift over about 1.5 meters ; for example, 8.3cm in 1.7m.

Next I'll try setting some simple move_base goals and then on to SLAM.

--patrick