![]() |
PID Speed control with encoders
Hello, I am trying to set up a PID loop where I can tell my drive motors to move the robot at a certain velocity. I am using encoders to measure my current velocity, and I want to set up a PID loop to bridge the two.
I don't know how to set it up, but I will show what I have so far. I've cut it down to show only the left half of the drive train. We call the drive function to give it a throttle amount where 1 is max speed. Could somebody give example code, or correct my mistakes here so I can fix it? Thanks! DriveTrain.java: Code:
public class DriveTrain extends Subsystem {Code:
public class DualMotorPID implements PIDOutput{ |
Re: PID Speed control with encoders
Not sure if you are still fighting with this issue or not, but here are some things we have found useful when setting up speed/rate control PIDs:
1. Use the SmartDashboard to display the PID control editor (so you can play with your P, I, D and F values). 2. Use the SmartDashboard to display the output power (pidWrite value) that the PIDController has determined, the sensor input value for the PID, the current error and the target value. 3. For a rate controlled PID, we found that wpilib seems to be slightly different this year and that you need to play with the P, D and F values. Rate PIDs are slightly different in nature from position PIDs. Here is an example of putting out the PID controller for your left side PID (add to the bottom of your DriveTrain() constructor): Code:
SmartDashboard.putData("Left PID", leftPID);Code:
// Value starts big and goes to zero as your PID reaches the setpoint.Hope that helps. |
| All times are GMT -5. The time now is 08:58 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi