|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
We have a code to run our robot with mecanum drive that works, and we are using an xbox controller. All is well except for the fact that we can't turn with the right trigger, only with the left. How do I add something in to be able to turn with the right trigger?
Code:
package org.usfirst.frc.team3229.robot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.RobotDrive.MotorType;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Timer;
/**
* This is a demo program showing how to use Mecanum control with the RobotDrive class.
*/
public class Robot extends SampleRobot {
RobotDrive robotDrive;
Joystick stick;
SpeedController elevatorMotor;
// Channels for the wheels
final int frontLeftChannel = 3;
final int rearLeftChannel = 4;
final int frontRightChannel = 2;
final int rearRightChannel = 1;
final int elevator = 6;
private static final int LIFT_BUTTON=2; //or whatever button raises
private static final int LOWER_BUTTON=1; //or whatever button lowers
// The channel on the driver station that the joystick is connected to
final int joystickChannel = 0;
public Robot() {
robotDrive = new RobotDrive(frontLeftChannel, rearLeftChannel, frontRightChannel, rearRightChannel);
robotDrive.setInvertedMotor(MotorType.kFrontLeft, true); // invert the left side motors
robotDrive.setInvertedMotor(MotorType.kFrontRight, true);
robotDrive.setExpiration(0.1);
stick = new Joystick(joystickChannel);
elevatorMotor=new Jaguar(elevator);
}
/**
* Runs the motors with Mecanum drive.
*/
public void operatorControl() {
robotDrive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
// This sample does not use field-oriented drive, so the gyro input is set to zero.
robotDrive.mecanumDrive_Cartesian(-stick.getY(), -stick.getX(), stick.getZ(), 1);
if(stick.getRawButton(LIFT_BUTTON)) {
elevatorMotor.set(0.5);
} else if(stick.getRawButton(LOWER_BUTTON)) {
elevatorMotor.set(-0.5);
} else {
elevatorMotor.set(0);
}
Timer.delay(0.010); // wait 5ms to avoid hogging CPU cycles
}
}
}
|
|
#2
|
||||
|
||||
|
Re: Turning with the right trigger?
I'm assuming that the z-axis on your controller doesn't exist and that is why you want the triggers to rotate. So, here you go.
Code:
public final int rightTrigger = 4;
public final int leftTrigger = 5;
int rotationDirection;
if(stick.getRawButton(rightTrigger)) {
rotationDirection=1;
}
if(stick.getRawButton(leftTrigger)) {
rotationDirection=-1;
else{
rotationDirection=0;
}
robotDrive.mecanumDrive_Cartesian(-stick.getY(), -stick.getX(), rotationDirection, 1);
Btw, you wouldn't have to invert the Y and X axis if you put the ports in as 0-3 -- frontleft, rearLeft, frontRight, rearRight Just found this: https://github.com/FRC3571/2015/blob...ontroller.java It might help but thank Team 3571. Last edited by JacobD : 16-02-2015 at 13:38. |
|
#3
|
|||
|
|||
|
Re: Turning with the right trigger?
Thanks!
|
|
#4
|
||||
|
||||
|
Re: Turning with the right trigger?
No problem, if you need anymore help just message me.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|