|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Greetings,
Our robot does not drive straight with the current code we have. We are using different methods to make it drive straight with encoders and gyros. However, these methods are causing it to veer to one side. Code:
public class AutonomousDrive extends CommandBase {
double left = .5;
double right = .475;
public AutonomousDrive() {
requires(driveTrain);
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
}
// Called just before this Command runs the first time
protected void initialize() {
driveTrain.resetEncoder();
driveTrain.gyro.reset();
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
driveTrain.driveXboxTank(left, right);
double rightEncoderCompensation = driveTrain.leftEncoder.getDistance() - driveTrain.rightEncoder.getDistance();
double increaseFactor = rightEncoderCompensation/200.0;
if (rightEncoderCompensation > 0)
{
if (right >= 0.5) {
left -= increaseFactor;
} else {
right += increaseFactor;
}
} else if (rightEncoderCompensation < 0) {
if (left >= 0.5) {
right -= increaseFactor;
} else {
left += increaseFactor;
}
}
/*if (driveTrain.gyro.getAngle() > 0.5) {
if (right == 1.0) {
left -= .0025;
} else {
right += .0025;
}
} else if (driveTrain.gyro.getAngle() < -0.5) {
if (left == 1.0) {
right -= .0025;
} else {
left += .0025;
}
}*/
}
|
|
#2
|
||||
|
||||
|
Re: Help in Driving Straight
How severely does it veer to one side?
Does it always veer to the same side? What are the units of the getDistance methods? There would be a big difference between adjusting your turn if one wheel was ahead of the other by 0.5 feet vs 0.5 inches. How did you pick your increaseFactor to divide the distance error by 200? If the increaseFactor is too small your system will not respond quickly enough to compensate for deviations off your desired heading. For reference, last year our drive straight code would compensate if we were +/- 1 degree off our heading. Our slow wheel's commanded value would be increased by 10%. this yielded good results on our robot at speeds that were pretty close to our top travel speeds. Last edited by otherguy : 29-01-2014 at 21:23. Reason: changed response, didn't see you were using two encoders in the code block, makes more sense now |
|
#3
|
|||
|
|||
|
Re: Help in Driving Straight
Quote:
|
|
#4
|
||||
|
||||
|
Re: Help in Driving Straight
2 problems our team found:
As mentioned before, calibrate your talons (if that's what you're using). Second, make sure the bearings flanges inside of your gearbox is in the right orientation, so they're not grinding together, slowing one side down. |
|
#5
|
||||
|
||||
|
Re: Help in Driving Straight
[emphasis added by me] THIS. Our robot could hardy even move when we first drove it (a few days ago :P ). We implemented a crude feedback loop to correct for it using the gyro (which worked fairly well), but we later disassembled the gearboxes to find out the problem. We checked our individual wheel speed and two of them were severely off. It turns out that two of our four gearboxes had the bearings improperly installed, causing them not to function properly. From what I heard, it was really difficult to spot, and was only found out when attempting to disassemble and reassemble the entire thing (meaning it wasn't blatantly obvious, regardless of whether or not the gearbox was assembled).
|
|
#6
|
|||
|
|||
|
Re: Help in Driving Straight
How do you calibrate a Talon?
|
|
#7
|
||||
|
||||
|
Re: Help in Driving Straight
The Talon manual is located on the crosstheroadelectronics.com website, and it explains the calibration procedure in detail.
|
|
#8
|
|||
|
|||
|
Re: Help in Driving Straight
The calibration sounds easy. Thank you.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|