Need help with auton and joystick slider programming

Hello my team for our second competition would like to have select-able autons that we can use with the default driver station, we would also like to be able to control the drive trains speed with the joysticks slider but everything that I have tried hasn’t worked. Our programmer graduated last year and used Labview but I decided to switch to java can anyone help with the mentioned things?
Here is the code
package frc.robot;

import edu.wpi.first.cameraserver.CameraServer;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.PWMVictorSPX;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.buttons.JoystickButton;

public class Robot extends TimedRobot {
private final DifferentialDrive m_robotDrive = new DifferentialDrive(new PWMVictorSPX(0), new PWMVictorSPX(1));
private final Joystick stick = new Joystick(0);
private final Timer m_timer = new Timer();

JoystickButton button1;
JoystickButton button2;
JoystickButton button3;
JoystickButton button4;
JoystickButton button5;
JoystickButton button6;
JoystickButton button7;
JoystickButton button8;
JoystickButton button9;
JoystickButton button10;
JoystickButton button11;
JoystickButton button12;

PWMVictorSPX climber = new PWMVictorSPX(5);
PWMVictorSPX conveyor = new PWMVictorSPX(6);
PWMVictorSPX intake = new PWMVictorSPX(7);
PWMVictorSPX shooter = new PWMVictorSPX(8);
PWMVictorSPX winch = new PWMVictorSPX(9);

Solenoid solenoid = new Solenoid(0, 0);
Solenoid solenoid1 = new Solenoid(0, 1);
Solenoid solenoid2 = new Solenoid(0, 4);
Solenoid solenoid3 = new Solenoid(0, 5);

Compressor compressor;
CameraServer server;

public void robotInit() {
compressor = new Compressor(0);
server = CameraServer.getInstance();

public void autonomousInit() {

public void autonomousPeriodic() {
// Drive for 3 seconds
if (m_timer.get() < 3.0) {
m_robotDrive.arcadeDrive(0.5, 0.0); // drive forwards half speed
//else if (m_timer.get() > 8){
else {
m_robotDrive.stopMotor(); // stop robot

public void teleopInit() {

public void teleopPeriodic() {
m_robotDrive.arcadeDrive(stick.getY(), stick.getX());
button1 = new JoystickButton(stick, 1);
button2 = new JoystickButton(stick, 2);
button3 = new JoystickButton(stick, 3);
button4 = new JoystickButton(stick, 4);
button5 = new JoystickButton(stick, 5);
button6 = new JoystickButton(stick, 6);
button7 = new JoystickButton(stick, 7);
button8 = new JoystickButton(stick, 8);
button9 = new JoystickButton(stick, 9);
button10 = new JoystickButton(stick, 10);
button11 = new JoystickButton(stick, 11);
button12 = new JoystickButton(stick, 12);
if (button2.get()) {
} else {
if (button4.get()) {
} else {
if (button1.get()) { //toggleOn1 for toggle
} else {
if (button12.get()) {
} else if (button11.get()) {
} else {
if (button6.get()) {
} else {
if (button9.get()) {
} else {
if (button10.get()) {
} else {
if (button5.get()) {
} else {
if (button3.get()) {
} else {
//double motorSpeed = stick.getRawAxis(3);
//motorSpeed = motorSpeed + 1;
//motorSpeed = motorSpeed / 2;

boolean toggleOn = false;
boolean togglePressed = false;
boolean toggleOn1 = false;
boolean togglePressed1 = false;

public void updateToggle2()
toggleOn1 = !toggleOn1;
togglePressed1 = true;
togglePressed1 = false;

public void testPeriodic() {

The code saying “double motorspeed” and so on is what I tried for the slider on the joystick but it says something like undefined for the type differentialDrive when deployed is there a way I can use the slider without reprogramming how the robot drives?

You can’t access the joystick whatsoever in autonomous. FMS or wpilib (unclear on the details) blocks OI access during auton. You can accomplish this instead by using the dashboard to send your speed via networktables, or by plugging a pot into an analog input on the rio and reading that.

After rereading your code I think I misunderstood your question. Are you trying to adjust your speed in teleop or in auton?

I am trying to adjust drive train speed during teleop using the slider sorry for being confusing but at the same time I need a way to select different autons that do different things the speed adjustment doesn’t have anything to do with what i need for auton help with either would be amazing

I’m not sure that DifferentialDrive has a set method, however if the goal is to limit the drive speed during teleop with the slider, you can do so as follows in place of your arcadeDrive call:

double limit = (stick.getRawAxis(3)+1)/2.0;
m_robotDrive.arcadeDrive(stick.getY()*limit, stick.getX()*limit);

The (stick+1/)2.0 changes the slider to give values between 0 and 1 instead of -1 and 1, you can then use that number as a multiplier on the joystick inputs.

Thank you I’ll see if this work at the meeting tomorrow but can you help with having multiple autons to chose from? Say one of them moves off of the initiation line but another one shoots and then moves off the line.

FYI … that isn’t my code but a better way then what our students did… we just input a number from shuffleboard.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.