![]() |
PID cmd_drive can't drive straight?
Am I missing something?
I've been thinking about the PID system and scripting system provided in Navigation_FRC2005_01_08, and I think that there is a fundamental problem with the way the PID system is being used by cmd_drive() in robot.c. cmd_drive sets the left and right target positions WAY out in front of the robot, and then just lets the PID system try to get there. The last state of cmd_drive() sets these positions: Code:
case COMPLETE:With the PWM values limited (clipped), the feedback loop cannot make any changes to the motor's speed. So the "loop gain" has gone to zero. And a loop gain of zero is another way of saying that the feedback loop is open! If there are differences in the left and right motor characterstics, the robot will not go straight, and the PID system is powerless to do anything about it, because its outputs are clipped. At the very end, when the encoders have nearly reached their targets, the PID system kicks in (becomes linear and therefore closed loop). And the drive distance is indeed accurately met. But this distance is around the arc of a circle, not necessarily on a straight line. I think that to maintain control, the PID system must never be put in a position where it must clip or limit its values. I have implemented a version of cmd_drive() that does not simply set a target position once and sit back to let the PID system max out, but rather continually increments the target positions a little at a time. (The amount of the increment is the desired velocity.) The PID system "chases" a moving target, and is able to stay linear the whole time. Here is my sDrive() ("script drive") routine, so you can see how the target position is continually incremented. The calling form is Code:
{ CMD_DRIVE, <distance>, <velocity>, <tolerance> },Code:
unsigned char sDrive(void)With some integration (I expect -- I haven't tried it yet) it will turn back to eventually be parallel to the desired path. To get back on the path, I think one would need to additionally integrate the "off path" error and apply it. But that additional integration would require very careful tuning to make it stable. I intend to try this in the coming days. Comments? |
Re: PID cmd_drive can't drive straight?
Yes, we saw something similar. Our solution was to set the velocity for the startup, is several steps to ramp up the speed, then when the distance is close, switch to position.
It is common for PID implementations to inhibit accumulating an integral of the error when the output is clamped to a limit (high or low). You can put in code like: Code:
// Only integrate if not driving at a limit |
Re: PID cmd_drive can't drive straight?
Quote:
Quote:
I didn't get any time today to experiment with integration for the PID position mode. I notice that the default code has the integrator turned off (KI_P is zero): Code:
#define KP_P (50)I also noticed that he is dividing the (apparently unused) integrator by the "pid_time" (counts since invoking CMD_DRIVE). Code:
motor_info[motor].pwm = (KP_P * motor_info[motor].pos_error) + Has anyone tried using integration with the position mode? -norm |
Re: PID cmd_drive can't drive straight?
I comented on the use of "/ pid_time" earlier. Someone suggested that this may be a way to deal with wind up, but I think it just makes the itegral correction ineffective after the beginning. It was pointed out that the original code always calls set_pid_stop() which zeros pid_time.
We have removed this dividing by pid_time, and used the conditional integration I posted above. This stops integration while the system is limited. But leaves it working to correct errors later after the system gets close. There will still be some accumulated integral value that has to be removed by going beyong the the set point, but much less than otherwise. |
Re: PID cmd_drive can't drive straight?
Hey gnormhurst,
I just found the exact same problem looking at the cmd_drive command, thanks for your solution : ) ... Bye Felix |
| All times are GMT -5. The time now is 23:18. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi