Novice Velocity PID Instructions?

Questions about using encoders with the Roboclaw product line
nickosinski
Posts: 31
Joined: Mon Oct 03, 2016 8:52 am
Novice Velocity PID Instructions?

Post by nickosinski »

Hello,

I've hunted through these forums as well as on Google so I apologize if this information is already posted somewhere, but I've been unable to locate it.

I'm a complete novice when it comes to PID and configuring motor controllers like the RoboClaws. I have two old 2x5a RCs each running two motors (4 motors total). My objective is to get all 4 motors:

1) accelerating at the same rate,
2) running at the same speed, and
3) covering the same total distance

I have tried using the "default" values found in the manual (below) and elsewhere on the web, but I do not understand how to go about adjusting these values (via Arduino - I know that this is not the idea way, but it's the only option that I have), in order to achieve my objectives above:

#define Kp_1 1.0
#define Ki_1 0.5
#define Kd_1 0.25

or

#define Kp_1 1.0
#define Ki_1 0
#define Kd_1 0

(btw, I'm using the SetM1VelocityPID command with the above values) Do I need to set Position PID too?

Clearly, using the same values on both controllers and each motor on each controller is not getting me anywhere and each RC, and likely each motor, requires unique values. Can someone give "dummy"-type instructions for how to adjust the above values for each motor to get the motors "synchronized" and achieve my objectives?

I suppose the basic question applies to anyone with more than one motor, so my question boils down to how to go about adjusting the P, I and D values such that one motor matches the accel, speed and distance of another motor.

I would love instructions such as: Set the values of one motor at X, Y and Z (for PID), and then increment the values on the 2nd motor up or down accordingly... something like that. Is that possible?

Thank you to anyone who can help... I've been struggling with this for a while! :)

Nick.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Novice Velocity PID Instructions?

Post by Basicmicro Support »

The basic manual tuning description is shown in the Roboclaw manual. Basically you start with a low value of P and zero for I and D. For velocity control D will most likely remain 0.

You then increase P until the motor runs close to some setpoint(eg speed) you specify. What you rae looking for is to reach a point where the motor starts not running smoothly(eg has a significant change in vibration compared to much low P values. YOu are looking to find the exact P value this vibrations tarts. Ballpark is cloes enough though. Once you have this value multiply it by 2/3rds. This is you approx P value. Now set I to 1/10 of P as a starting piont and again test the motor at some speed. Add and remove load from the motor(if its a wheeled robot have it up off the ground and just add friction using you hand if you can do it safely. You want to be displaying the speed of the motor when running these tests. Once P and I are good enough you should see little if any speed change under changing firction/load, upto the maximum load the motor can drive at the given speed.

For velocity control thats really all you have to do. If all the motors and loads are similar you can just copy and past the values for the other motor controller.
nickosinski
Posts: 31
Joined: Mon Oct 03, 2016 8:52 am
Re: Novice Velocity PID Instructions?

Post by nickosinski »

Thank you so much!

Let me give this a try and hopefully I don't have to bug you again :P

Again, very much appreciated!

Nick.
nickosinski
Posts: 31
Joined: Mon Oct 03, 2016 8:52 am
Re: Novice Velocity PID Instructions?

Post by nickosinski »

Thank you again for your instructions - they were very helpful.

I do have a follow-up question, however. The PID values that I set, seem to work well for a given distance - say a distance value of 80,000, but when I use the same PID values with a distance much shorter, such as 10,000, then the distances traveled by the motors vary greatly/widely. Is this normal? Should I need to set different PID values dyanmically based on the commands being issued? It seems wrong, but I don't understand why the distances traveled by the motors can be so inconsistent.

Your advice/direction, again, would be much appreciated. Thank you again,

Nick.
nickosinski
Posts: 31
Joined: Mon Oct 03, 2016 8:52 am
Re: Novice Velocity PID Instructions?

Post by nickosinski »

Sorry... one more question.

The library I have (yes, I know it's old) shows the function as follows:

bool SetM1VelocityPID(uint8_t address, float Kd, float Kp, float Ki, uint32_t qpps);

...so the order is DPI, not PID, correct?

Thanks again,

Nick.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Novice Velocity PID Instructions?

Post by Basicmicro Support »

nickosinski wrote:Thank you again for your instructions - they were very helpful.

I do have a follow-up question, however. The PID values that I set, seem to work well for a given distance - say a distance value of 80,000, but when I use the same PID values with a distance much shorter, such as 10,000, then the distances traveled by the motors vary greatly/widely. Is this normal? Should I need to set different PID values dyanmically based on the commands being issued? It seems wrong, but I don't understand why the distances traveled by the motors can be so inconsistent.

Your advice/direction, again, would be much appreciated. Thank you again,

Nick.
No you should not need see significant differences is postion error over different distances if the PID is tuned correctly.

The accel/deccel values can hide problems in tuning if the distance traveled is long enough to take advantage of accel/deccel.

What commands are you using to move a distance(Position commands or distance commands). If the later(distance commands) you may not be calculating the deccel distance properly(over very short distances your calculation must take into account that you may not reach the specified speed before you need to start deccelerating to reach your calculated position at 0 speed.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Novice Velocity PID Instructions?

Post by Basicmicro Support »

nickosinski wrote:Sorry... one more question.

The library I have (yes, I know it's old) shows the function as follows:

bool SetM1VelocityPID(uint8_t address, float Kd, float Kp, float Ki, uint32_t qpps);

...so the order is DPI, not PID, correct?

Thanks again,

Nick.
Yes, in older libraries for the arduino that was the order. IIRC the new library has them arranged in P,I and D.
nickosinski
Posts: 31
Joined: Mon Oct 03, 2016 8:52 am
Re: Novice Velocity PID Instructions?

Post by nickosinski »

Thank you again for your reply and assistance.

Here are the settings that I'm using... as a starting point:

#define Kp_1 1.0
#define Ki_1 0.5
#define Kd_1 0.25
#define qpps_1 32000

in the Setup(), I have

roboclaw.SetM1VelocityPID(address,Kd_1,Kp_1,Ki_1,32500);
roboclaw.SetM2VelocityPID(address,Kd_1,Kp_1,Ki_1,32500);
roboclaw.SetM1VelocityPID(address1,Kd_1,Kp_1,Ki_1,32500);
roboclaw.SetM2VelocityPID(address1,Kd_1,Kp_1,Ki_1,32500);

In the loop():

uint32_t accel = 5000;
uint32_t speed = 5000;
uint32_t distance = 40000;

roboclaw.SpeedAccelDistanceM1(address,accel,speed,distance);
roboclaw.SpeedAccelDistanceM2(address,accel,speed,distance);
roboclaw.SpeedAccelDistanceM1(address1,accel,speed,distance);
roboclaw.SpeedAccelDistanceM2(address1,accel,speed,distance);

// To stop and not "decel" and avoid "hidden problems" due to decel

roboclaw.SpeedAccelDistanceM1(address,0,0,0);
roboclaw.SpeedAccelDistanceM2(address,0,0,0);
roboclaw.SpeedAccelDistanceM1(address1,0,0,0);
roboclaw.SpeedAccelDistanceM2(address1,0,0,0);

The results that we get are very inconsistent and we cannot figure out why.

Thank you again for any suggestions you may offer,

Nick.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Novice Velocity PID Instructions?

Post by Basicmicro Support »

Thos e are just the example PID settings we use because they are neutral. They wont cause any motor to go crazy. They, however, are no where near what any motor I have every used required to be properly tuned. I highly recommend you handle tuning the motors in the IonMotion software and just save the settings to the Roboclaws non-voltaile memory instead of trying to set them in the arduino program. Then you can remove all the PID settup code from your arduino program as well which will also reduce the overall size of the code on the arduino.

The IonMotion application can be used to autotune the motors in most cases. You just have to make sure the encoders are turning in the right direction compared to the motor(eg the encoder value must increase when the motor is moving foward. If it is decreasing you need to reverse your motor wires or your encoder signal wires(on a quadrature encoder). Then you can use the Velocity conntrol auto tuner to determine the QPPS and PID values for the motor.

Note: your distance commands are missing the last argument. It tells the Roboclaw to execute the command immediately(clearing any active commands in its motor command buffer) or buffer the command to be executed in the order they are received. This may indicate a very old arduino library but Im pretty sure we had that argument in the commands since day one.
nickosinski
Posts: 31
Joined: Mon Oct 03, 2016 8:52 am
Re: Novice Velocity PID Instructions?

Post by nickosinski »

Thank you,

but per my earlier messages in this thread, I have the older 2x5a models that do not have on-board USB capability, so there's no way to connect to your software.

Yes, the library has the last variable for buffer, but it's an optional value, I understand - is that not correct?

Thanks again - I guess I just have to trial-and-error my way through this.

Nick.

Post Reply