![]() |
Encoders, Mecanum, and PID
How do I set up a velocity PID to work with my existing Mecanum Drive code using the encoders (US Digital E4P-360-250-D-H-D-B) I have on all four wheels? I found some threads on it and understand it conceptually (I think), but actually implementing it leaves me puzzled.
|
Re: Encoders, Mecanum, and PID
Quote:
|
Re: Encoders, Mecanum, and PID
Quote:
Code:
public class DriveTrain extends Subsystem { |
Re: Encoders, Mecanum, and PID
Yes, you want to take the four wheel speeds that are computed from the driver commands, and use each one as a setpoint for the PID (or other controller) for the corresponding wheel. The encoder signal for each wheel serves as the process variable for that wheel. As with all closed-loop controllers, you need to make sure that your setpoint and process variable are appropriately scaled and offset so they work together properly. I'm not a Java guru so I'll leave the Java coding questions to someone else. |
Re: Encoders, Mecanum, and PID
If I understand you correctly, you are using the PID loop to maintain a certain rate (how quickly your wheels spin) and not distance (how many times to rotate the wheels).
We've found that the standard PID controller assumes that you are always trying to "move a distance". It tries to get the error to 0 and basis the power value directly on the error. This works well for distance (where you want 0 power when you have 0 error). This doesn't work well for rate based PIDS (where you want the power to settle in to a good non-zero value when the error goes to 0). Basically, when we run into this situation, we use a wrapper class around our speed controllers that can be used as the parameter to the PIDController constructer. The wrapper class implements PIDOutput and treats each write as an adjustment to the current power setting instead of a direct setting. For example, it would look something like: Code:
rightBackPID = new PIDController(Kp, Ki, Kd, rightBackEncoder, new RateContollerMotor(rightBack));Code:
package com.techhounds.robot.subsystems;Code:
rightBackPID = new PIDController(Kp, Ki, Kd, rightBackEncoder, new RateContollerMotor(rightBack)); |
Re: Encoders, Mecanum, and PID
Quote:
|
Re: Encoders, Mecanum, and PID
Feedforward is implemented in the PIDController class you are using now, see WPILib screensteps
It's a direct scaling factor between setpoint units and and output variable which for a motor controller is [-1, 1]. So if your max speed is N in encoder units then set the feedforward term to 1/N. |
| All times are GMT -5. The time now is 11:02. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi