Hello all,
Trying to get our autonomous working, but running into issues. Can anyone tell us what we’re doing wrong? We were using if and elseif statements but get error messages.
package frc.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.MotorController;
import edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup;
import edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX;
import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.cscore.UsbCamera;
import edu.wpi.first.cscore.VideoSink;
import edu.wpi.first.cscore.VideoSource.ConnectionStrategy;
/*
- import edu.wpi.first.wpilibj.Timer;
*/
/**
This is a demo program showing the use of the DifferentialDrive class, specifically it contains
the code necessary to operate a robot with tank drive.
*/
public class Robot extends TimedRobot {
private DifferentialDrive m_myRobot;
private Joystick m_DriverJoystick;
private final MotorController m_leftMotor = new PWMVictorSPX(3);
private final MotorController m_rightMotor = new PWMVictorSPX(5);
private final MotorController m_leftMotor2 = new PWMVictorSPX(4);
private final MotorController m_rightMotor2 = new PWMVictorSPX(6);
private final MotorController m_armMotor = new PWMVictorSPX(7);
private final MotorController m_armMotor2 = new PWMVictorSPX(8);
private final MotorController m_intakeMotor = new PWMVictorSPX(9);
UsbCamera camera1;
UsbCamera camera0;
VideoSink server;
Timer timer;
@Override
public void robotInit() {
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot’s
// gearbox is constructed, you might have to invert the left side instead.
CameraServer.startAutomaticCapture();
camera1 = CameraServer.startAutomaticCapture(1);
camera0 = CameraServer.startAutomaticCapture(0);
server = CameraServer.getServer();
camera1.setConnectionStrategy(ConnectionStrategy.kKeepOpen);
camera0.setConnectionStrategy(ConnectionStrategy.kKeepOpen);
m_leftMotor.setInverted(true);
m_leftMotor2.setInverted(true);
MotorControllerGroup rightControllerGroup = new MotorControllerGroup(m_rightMotor,m_rightMotor2);
MotorControllerGroup leftControllerGroup = new MotorControllerGroup(m_leftMotor,m_leftMotor2);
m_myRobot = new DifferentialDrive(leftControllerGroup, rightControllerGroup);
m_DriverJoystick = new Joystick(0);
}
@Override
public void autonomousInit() {
timer.reset();
timer.start();
}
@Override
public void autonomousPeriodic() {
//lift arm up 100 degrees
if (timer.get() < 2.0); {
m_armMotor.set(0.5);
m_armMotor2.set(0.5);
} else{
m_armMotor.set(0); // stop robot arm
m_armMotor2.set(0);}
}
@Override
public void teleopPeriodic() {
m_myRobot.tankDrive(-m_DriverJoystick.getRawAxis(1) * 0.75, -m_DriverJoystick.getRawAxis(3) * 0.75);
if(m_DriverJoystick.getRawButton(6)){
m_armMotor.set(0.5);
m_armMotor2.set(0.5);
} else if(m_DriverJoystick.getRawButton(8)) {
m_armMotor.set(-0.35);
m_armMotor2.set(-0.35);
} else {
m_armMotor.set(0);
m_armMotor2.set(0);
}
if(m_DriverJoystick.getRawButton(5)){
m_intakeMotor.set(0.75);
} else if(m_DriverJoystick.getRawButton(7)) {
m_intakeMotor.set(-0.75);
} else {
m_intakeMotor.set(0);
}
}
}