![]() |
Drive train PID control
Hello, my team this is looking at solutions for driving more accurately in autonomous. At this moment we are using this to drive a certain distance in autonomous.
Code:
if (encoderDistanceReading >= distance) {Our team is currently using the iterative robot template. The drive train is a four motored tank drive with 8 inch pneumatic tires. I have one encoder setup on the left small output shaft. We have a second encoder coming soon. |
Re: Drive train PID control
The easiest way I can think to do this, is to initialize the motors separately without using the robotDrive class, as from the documentation, I can't find a way to integrate it with PID.
What kind of encoder are you using? continuous analog or digital quadrature? |
Re: Drive train PID control
Quote:
|
Re: Drive train PID control
Be very careful with those encoders. My team has never successfully used these encoders in competition without hilariously disastrous consequences. Make sure you thoroughly test these in the shop and do plenty of research on how to mount them.
now, as to how to implement it. I did a little more research and found that you can infact use the robot drive class. Code:
Encoder leftEncoder = new Encoder(1,2);Code:
leftEncoder.setPIDSourceType(kDisplacement); |
Re: Drive train PID control
Quote:
|
Re: Drive train PID control
It depends on what you're trying to keep track of in auto. If you're concerned only with distance, then one would work, but you would have to make sure all motors follow it. If you're using PWM, my team found it easiest to just splice the PWM cable into 2 end points so it can connect 2 Jags to 1 PWM output. This saves from having to set up sync/follower sets in code. ((obviously you would still need at least 2 PWM, one for each side))
if you're concerned about turning, (like when going over rough terrain) you may wish to use a gyro as well, as encoders will only track wheel spin, and not robot distance |
Re: Drive train PID control
Quote:
Just starting adding some of the code but I am having difficulty with the leftControl. The error I am getting is: "The field RobotDrive.m_frontLeftMotor is not visible" Code:
RobotDrive tankDrive = new RobotDrive(0, 1);RobotDrive(int leftMotorChannel, int rightMotorChannel) Constructor for RobotDrive with 2 motors specified with channel numbers. RobotDrive(int frontLeftMotor, int rearLeftMotor, int frontRightMotor, int rearRightMotor) Constructor for RobotDrive with 4 motors specified with channel numbers. RobotDrive(SpeedController leftMotor, SpeedController rightMotor) Constructor for RobotDrive with 2 motors specified as SpeedController objects. RobotDrive(SpeedController frontLeftMotor, SpeedController rearLeftMotor, SpeedController frontRightMotor, SpeedController rearRightMotor) http://first.wpi.edu/FRC/roborio/rel...obotDrive.html |
Re: Drive train PID control
That is a possibility, which you can fairly easily use if you split the PWM signal cable to both left drive jags. That way, you have one PWM signal, (one jag from the program's point of view) controlled by one PID/encoder.
Now, the gyro will help in keeping straight, but it will not help in going a set distance. for that, you would use an ultra sonic, (or similar range finder) my team is trying to use vision to determine distance, but there is a myrid of other ways to do this. If your plan may involve drive slippage, PID distance control wont much help. now, you might be able to combine that with an accelerometer, and a gyro to use PID after you get across the obstacle. That is, what for the accelerometer to say you are relatively level, use the gyro to straighten out, then use encoders to go forward a distance. IDK how well this will work in conjunction, since there is a lot of variability depending on your drive system. |
Re: Drive train PID control
Sorry, after thought, it may be easier to just use basic the Jaguar class if you continue having issues with robotDrive. You'll have to set up your tank drive yourself, but it is as easy as linking a joystick to the jag's set function.
|
Re: Drive train PID control
Quote:
Code:
RobotDrive tankDrive = new RobotDrive(SpeedController leftMotor, SpeedController rightMotor) |
Re: Drive train PID control
1 Attachment(s)
Quote:
Our pid loop took a lot of time to tune, and we used mecanum drive, so please be aware of that. Hope this helps |
Re: Drive train PID control
More or less yes. So you're using talons. PWM I assume? if so, the following code should be enough to set up your drive.
using only basic classes: Code:
Talon leftDrive=new Talon(1); |
Re: Drive train PID control
Quote:
This is what I thought of doing to have it work for arcade drive I have the PID setup stuff added on I just took it out for this. Code:
public class Robot extends IterativeRobot { |
Re: Drive train PID control
yes, just switch out the teleop init and periodic with the following.
Code:
RobotDrive drive; |
Re: Drive train PID control
Quote:
Code:
public class Robot extends IterativeRobot { |
Re: Drive train PID control
1: you don't need the .get() in auto init. you might want to make it a .reset().
2: you also probably want to set a defined Max and Min output. In auto periodic, you need to set a distance for the PID to get to, but before all that, you have to tune your PID. PID tries to get to it's target with as little error as possible, but it uses coefficients to multiply by this error to get to this point. Now, for your use, it's likely you can get away with PD control, and leave I at 0. First thing you're going to need to do, is set it up such that your bot goes back and forth on it's own. ((be VERY careful with this. you might want the robot on blocks first, as I've had bad experiences with a run away robot while tuning PID)) you do this by using 2 set points, say, 100 and -100. it will set this set point every, say 10 seconds. now, the bot will get to that point, and either over shoot it, or slow down too early and never reach it. you want to only set 1 PID variable at a time. So I typically start with P, and small values like 0.1 should be close. increase this until it starts to over shoot, or decrease it until it no longer overshoots, (then go back up one tick) now you increase D until it no longer overshoots. |
Re: Drive train PID control
PROGRESS! Sorry for doing a double post.
So I just enable autonomous and the robot drove backwards very quickly right. I guess I need to change the direction the robot drives, so going forwards instead of backwards and then make the leftPID mask the rightPID so it drives straight. Code:
public class Robot extends IterativeRobot { |
Re: Drive train PID control
Splendid! Sounds like you're on the right track. Shoot me a msg if you have any more issues, either PM here, or the skype that is connected to this account.
|
| All times are GMT -5. The time now is 11:54. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi