|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Sorry but that doesn't really help me. Like I understand how it works but I don't know how I would implement this in Java.
|
|
#2
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Why? What part is not clear?
|
|
#3
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
|
|
#4
|
|||||
|
|||||
|
Re: Getting Gyro Working w/ Mecanum Drive
I recommend using one of the WPIlib MecanumDrive methods, and just make corrections to the "twist" input when you want to go straight based on the error. Do not use the fourth "gyroscope" input to MecanumDrive_cartesian; this is only used for "field coordinates".
The correction could be a full PID, but because of the amount of friction in a mecanum drive system, you should be able to get away with a simple proportional correction; D will be mechanical, and I is usually not needed when seeking a position. To do this, you will need to create a numeric variable to hold the desired heading, say azi. In your joystick-reading loop:
|
|
#5
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
How do I set the robotdrive to the MecanumDrive method?
Quote:
|
|
#6
|
|||||
|
|||||
|
Re: Getting Gyro Working w/ Mecanum Drive
mecanumDrive_cartesian() is a method within the standard RobotDrive class in both C++ and java WPIlibs. For what are hopefully obvious reasons, you must use one of the four-controller forms of the new RobotDrive() constructor in order to use the mecanum methods.
|
|
#7
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Code:
RobotMap.driveRobotDrive41.mecanumDrive_Cartesian(OI.joystick0.getX(), OI.joystick0.getY(), OI.joystick0.getZ(), 0); |
|
#8
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
As explained in earlier posts in this thread, passing the gyro angle to the fourth parameter gives you field-centric control. You said that's not what you want.
Quote:
Quote:
Quote:
Last edited by Ether : 26-04-2015 at 09:16. |
|
#9
|
||||
|
||||
|
The code is not particularly well documented, but here's the code we used this year:
https://github.com/CopperBots/Copper...obot.java#L632 We pass in the rotation joystick value that has already been deadband'ed. If the joystick is at zero rotation, we use a proportional controller to keep the robot straight. If the joystick is not at zero, we update the current heading of the robot and pass the joystick value back to the drive system unchanged. We also have the option to disable gyro mode at any time in case something goes wrong like a bad calibration, or a loose cable. There is also an option to update the kP value from the smart dashboard and some diagnostic information sent back to help troubleshoot when things go wrong. |
|
#10
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Thanks, this helps a BUNCH! The problem is mixing mecanum drive with your code
Quote:
|
|
#11
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
|
|
#12
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Well what I'm asking is what do I put in for the fourth parameter, because I have to put something in it.
Quote:
|
|
#13
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Quote:
Code:
public void mecanumDrive_Cartesian(double x, double y, double rotation, double gyroAngle) {
if(!kMecanumCartesian_Reported) {
UsageReporting.report(tResourceType.kResourceType_RobotDrive, getNumMotors(), tInstances.kRobotDrive_MecanumCartesian);
kMecanumCartesian_Reported = true;
}
double xIn = x;
double yIn = y;
// Negate y for the joystick.
yIn = -yIn;
// Compenstate for gyro angle.
double rotated[] = rotateVector(xIn, yIn, gyroAngle);
Now look at the WPILib code for rotateVector(): Code:
/**
* Rotate a vector in Cartesian space.
*/
protected static double[] rotateVector(double x, double y, double angle) {
double cosA = Math.cos(angle * (3.14159 / 180.0));
double sinA = Math.sin(angle * (3.14159 / 180.0));
double out[] = new double[2];
out[0] = x * cosA - y * sinA;
out[1] = x * sinA + y * cosA;
return out;
}
|
|
#14
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Thank you Ether, that helps tons.
Quote:
|
|
#15
|
||||
|
||||
|
Re: Getting Gyro Working w/ Mecanum Drive
Do you think this will work? (I only included the drive code)
Code:
public void teleopInit(){
gyroMode = true;
}
public void teleopPeriodic() {
Jx = OI.joystick0.getX(); //Drive Joystick X
Jy = OI.joystick0.getY(); //Drive Joystick Y
Jz = OI.joystick0.getZ(); //Drive Joystick Z
rotationSpeedForError = RobotMap.GyroMod(Jz);
RobotMap.driveRobotDrive41.mecanumDrive_Cartesian(Jx, Jy, Jz + rotationSpeedForError, 0);
}
public double GyroMod(double rotation){
if (gyroMode == true) {
double error = gyro.getAngle() - gyroHeading;
double kP = .05;
if (rotation == 0) {
rotation = rotation + kP * error;
} else {
gyroHeading = gyro.getAngle();
}
}
return rotation;
}
}
Last edited by WillNess : 26-04-2015 at 23:00. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|