Hi. My teacher is making me post this despite the fact that I am almost certain this isn’t a programming issue.
I’ve been testing each motor individually in the autonomous periodic method because for some reason the one labeled ‘rightBottom’ is not turning. The Spark that controls the motor is lighting up green yet the motor will not turn.
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package org.usfirst.frc.team6871.robot;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.SpeedControllerGroup;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the build.properties file in the
* project.
*/
public class Robot extends IterativeRobot {
private static final String kDefaultAuto = "Default";
private static final String kCustomAuto = "My Auto";
private String m_autoSelected;
private SendableChooser<String> m_chooser = new SendableChooser<>();
Joystick gamePad = new Joystick(0);
//create a new joystick named gamePad
Spark leftTop = new Spark(3);
Spark leftBottom = new Spark(2);
Spark rightTop = new Spark(1);
Spark rightBottom = new Spark(4);
//declare the speed controllers for the motors
SpeedControllerGroup m_left = new SpeedControllerGroup(leftTop, leftBottom);
SpeedControllerGroup m_right = new SpeedControllerGroup(rightTop, rightBottom);
//group the two sets of motors together into one group for each side
DifferentialDrive m_drive = new DifferentialDrive(m_right, m_left);
//sets up drive into DifferentialDrive object
// note: DifferentialDrive expects left then right but it is inversed on this robot.
// may fix later.
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
@Override
public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);
}
/**
* This autonomous (along with the chooser code above) shows how to select
* between different autonomous modes using the dashboard. The sendable
* chooser code works with the Java SmartDashboard. If you prefer the
* LabVIEW Dashboard, remove all of the chooser code and uncomment the
* getString line to get the auto name from the text box below the Gyro
*
* <p>You can add additional auto modes by adding additional comparisons to
* the switch structure below with additional strings. If using the
* SendableChooser make sure to add them to the chooser code above as well.
*/
@Override
public void autonomousInit() {
m_autoSelected = m_chooser.getSelected();
// autoSelected = SmartDashboard.getString("Auto Selector",
// defaultAuto);
System.out.println("Auto selected: " + m_autoSelected);
}
/**
* This function is called periodically during autonomous.
*/
@Override
public void autonomousPeriodic() {
switch (m_autoSelected) {
case kCustomAuto:
break;
case kDefaultAuto:
default:
rightBottom.set(0.5);
break;
}
}
/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {
double axisY = gamePad.getRawAxis(1);
double axisX = gamePad.getRawAxis(0);
// double axisZ = gamePad.getRawAxis(3);
//get the value of the joysticks periodically
m_drive.arcadeDrive(-1 * axisX, axisY);
//initialize arcade drive. axisX is inverted to match vide-game like controls.
}
/**
* This function is called periodically during test mode.
*/
@Override
public void testPeriodic() {
}
}