Hi,
our team is having issues with our drive having inverted turning.
We’re using 4 drive motors, all with VictorSP’s. We’ve also confirmed that they’re in ordered ports. the 2 motors on the left are in ports 0, and 1, and the two motors on the right are in ports 2, and 2.
Here’s our code.
package org.usfirst.frc.team6077.robot;
import edu.wpi.first.wpilibj.SampleRobot;
//import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.TalonSRX;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class Robot extends SampleRobot {
// Declarations
RobotDrive drive;
CameraServer camserver;
Compressor compressor;
DoubleSolenoid ds;
//Solenoid s;
Joystick xboxController;
TalonSRX slideMotor;
Victor armMotor;
VictorSP drivemotor1;
VictorSP drivemotor2;
VictorSP drivemotor3;
VictorSP drivemotor4;
// Autonomous Names
final String defaultAuto = "Default";
final String customAuto = "Autonomous Choice 1";
final String customAuto2 = "Autonomous Choice 2";
final String customAuto3 = "Autonomous Choice 3";
final String customAuto4 = "Autonomous Choice 4";
final String customAuto5 = "Autonomous Choice 5";
// Chooser
SendableChooser chooser;
public Robot() {
//Change values later
drivemotor1 = new VictorSP(0);
drivemotor2 = new VictorSP(1);
drivemotor3 = new VictorSP(2);
drivemotor4 = new VictorSP(3);
compressor = new Compressor(0);
drive = new RobotDrive(drivemotor1, drivemotor2, drivemotor3, drivemotor4);
drive.setExpiration(0.1);
xboxController = new Joystick(0);
armMotor = new Victor(5);
slideMotor = new TalonSRX(4);
ds = new DoubleSolenoid(0, 1);
//s = new Solenoid(2);
chooser = new SendableChooser();
camserver = CameraServer.getInstance();
camserver.setQuality(50);
camserver.startAutomaticCapture("cam0");
}
public void robotInit() {
compressor.setClosedLoopControl(true);
chooser.addDefault("Default Autonomous", defaultAuto);
chooser.addObject("Autonomous Choice 1", customAuto);
chooser.addObject("Autonomous Choice 2", customAuto2);
chooser.addObject("Autonomous Choice 3", customAuto3);
chooser.addObject("Autonomous Choice 4", customAuto4);
chooser.addObject("Autonomous Choice 5", customAuto5);
SmartDashboard.putData("Autonomous Chooser", chooser);
}
public void autonomous() {
drive.setSafetyEnabled(false);
String autoSelected = (String) chooser.getSelected();
System.out.println("Autonomous Mode selected: " + autoSelected);
switch (autoSelected) {
case customAuto5:
/*Only use if have to
* Goal: Go through the portcullis & pick up a ball
* Note: Values might change as testing is done
*/
//Drive forwards while lowering arms to default
drive.drive(1, 0);
armMotor.set(-0.5);
Timer.delay(1);
armMotor.set(1);
Timer.delay(1);
drive.drive(1, 0);
Timer.delay(2);
drive.drive(0.5, 1);
ds.set(DoubleSolenoid.Value.kForward);
Timer.delay(1);
ds.set(DoubleSolenoid.Value.kOff);
break;
case customAuto4:
/*Hallway autonomous test
* Goal: Drive forwards, turn around, come back
*/
drive.drive(-0.25, 0);
Timer.delay(3);
drive.drive(0.50, 1);
Timer.delay(1.75);
drive.drive(-0.1, 0);
break;
case customAuto3:
break;
case customAuto2:
break;
case customAuto:
break;
case defaultAuto:
default:
/*Preferred w/ preferred spawn point
Goal: Go through the low bar and pick up a ball. */
//Drive forwards
drive.drive(1, 0);
Timer.delay(1);
//Turn to low bar
drive.drive(0, 0.5);
Timer.delay(1);
//Drive through low bar and approach ball in center
drive.drive(1, 0.25);
Timer.delay(2);
//Pick up the ball
ds.set(DoubleSolenoid.Value.kForward);
Timer.delay(1);
ds.set(DoubleSolenoid.Value.kOff);
break;
}
Scheduler.getInstance().run();
}
public void operatorControl() {
drive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
compressor.start();
// Move robot using left and right joystick
//drive.tankDrive(xboxController.getRawAxis(1), xboxController.getRawAxis(5));
drive.arcadeDrive(xboxController);
// Lift and lower the arms using the right and left bumper.
if (xboxController.getRawButton(5)) {
armMotor.set(1);
} else if (xboxController.getRawButton(4)) {
armMotor.set(-1);
} else {
armMotor.set(0);
}
//Wait for motor update times
Timer.delay(0.005);
// Move sliding mechanism forwards and backwardss
if (Math.abs(xboxController.getRawAxis(5)) > .1) {
slideMotor.set(xboxController.getRawAxis(5));
} else {
slideMotor.set(0);
}
//Wait for motor update times
Timer.delay(0.005);
// Open and close the claw
if (xboxController.getRawButton(2)) {
ds.set(DoubleSolenoid.Value.kForward);
} else if (xboxController.getRawButton(1)) {
ds.set(DoubleSolenoid.Value.kReverse);
}
//Wait for motor update times.
Timer.delay(0.005);
}
}
public void test() {
}
}
Thanks!