View Single Post
  #18   Spotlight this post!  
Unread 24-01-2004, 20:35
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: Effectiveness of Casters

I dont know if I can give enough info in a post to explain how to use them if your are not familiar with PID control loops.

The idea behind it is simple. If you are using single joystick control then the X axis is indicating how fast your driver wants to turn

if you just feed this into the single joystick equation that comes with the default code - then the stick postition is mapped directly to a PWM output, which ends up telling the motor how much force to apply (you can think of this as how much voltage is on the motor)

problem is - there is friction in your drivetrain that will resist movement - so putting a small pwm command on the motor will not be enough to make it move - once you have moved the stick enough to make it move, you have overcome the static friction and now you are dealing with kinetic friction, which is less, so once the motor moves a little, that pwm command is enough to make it move noticeably more

to make matters worse, the left and right drivetrains will not have exactly the same amount of static friction, so one will start sooner than the other. If you are telling the bot to go straight, it will goto one side a little.

The yaw rate sensor detects how fast the robot is turning - if you mount it with its bolt holes up and down.

the way a PID control loop works is, instead of taking the signal from the joystick and driving the motors pwm with that, you take the joystick X axis signal and you subtract the yaw rate sensor signal.

so if the driver is commanding a slight turn, and the yaw rate sensor says "im not seeing any turning going on here!" you end up with an error signal - the error is the difference between what the driver wants, and what the robot is doing.

the simplist form of closing the loop would be to use the error signal to drive the motors - replace the joystick X axis signal with the error signal and feed it into the one joystick equation. You have to adjust the error signal for 127 being zero, something like this:

yaw_error = (((2127 + p1_x - yaw) Min 2000 Max 2254)-2000)
yaw_command =(((2063 + yaw_error/2) Min 2000 Max 2254) -2000)

BTW - this is in basic from last year - wont take much to change it to C

In PID lingo this is a Proportional loop. The output to the motors is proportional to the difference between the commanded value and the actual (the feedback) value. how responsive the system will be depends on the gain. in the code example above, the error is divided by 2, so the gain is 0.5

thats not a bad place to start with a machine that is using two wheels and castors, esp if your weight is balanced towards the two drive wheels. if you try the code and the bot is sluggish, you can increase the gain ( and you have to adjust the 2063 number so that a yaw error of 127 (zero) stays zero

if you have a bot with 4 wheels, you might need more gain, like 2 maybe - in that case you would adjust the 2063 down to 1873.

if you crank the gain up too high, what will happen is, when the loop corrects itself it will over correct, and overshoot the turn rate - then the yaw rate sensor will say "you went too far" and try to correct it back, which will overshoot again, and the bot will twist back and forth. If the gain is just slightly too high, the bot will respond like its nervious and twitchy - if its way too high the bot will swing back and forth all by itself.

one thing you have to be carefull here - make sure your yaw rate sensor is mounted in the right orientation - for the code above we had our sensor mounted upside down, the holes were upward (simply because that was a convient place to put it on our frame). Also the sensor has to be solidly attached to the frame. If you tie wrap it on, and it can move around, it will go nuts on you.

so what are the I and D parts of PID? I is intergral - if you move the stick a little bit, the error signal might not be enough to get the motors to move - so to add an intergral part you take part of the error signal and you sum it, or accumulate it over many cycles - so if the driver is telling it to move, and its not moving, the error signal keeps increasing until it does.

The D is differential. sometimes you want the bot to respond quickly to changes in the joystick position, so you can either keep track of where the joystick was last time, and subtract where it is now, to tell when it has been moved, and apply a gain to that signal to sort of give the motors a 'kick' when the joystick has been moved - or you can use D on the error signal in the same way.

For our bot last year, all we needed was the P part of the PID loop - the equation I listed above. We ended up with the best response with the gain at 2, but I would try it at lower values and work your way up.

If you want to learn more about PID control loops, try searching the web - lots of companies make equipement that is used professionally, and I have seen some excellent websites that explain the concept better than I have here.

PID loops can also be used for thing like postioning an arm on the bot, or using pots to tell where your wheels are pointing if you use crab steering, or your front wheels turn left and right to steer.

hope this has been useful.