6542 | Code Functions, Robot does not drive

Not sure what’s wrong with it, the robot refuses to drive. We have 0% packet loss, and no errors are being shown through any system. So, here’s our code:

package frc.robot;

import edu.wpi.first.wpilibj.Joystick;

import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;

import edu.wpi.first.wpilibj.TimedRobot;

import edu.wpi.first.wpilibj.drive.DifferentialDrive;

import edu.wpi.first.wpilibj.Spark;

import edu.wpi.first.wpilibj.XboxController;

import edu.wpi.first.wpilibj.GenericHID.Hand;

public class Robot extends TimedRobot {

  private final WPI_VictorSPX m_leftMotor = new WPI_VictorSPX(1);

  private final WPI_VictorSPX m_rightMotor = new WPI_VictorSPX(2);

  private final Spark m_outputMotor = new Spark(0);

  private final DifferentialDrive m_robotDrive = new DifferentialDrive(m_leftMotor, m_rightMotor);

  private final Joystick m_stick = new Joystick(0);

  public final XboxController m_xboxController = new XboxController(1);

  private boolean m_toggleState = false;

  

  @Override

  public void teleopPeriodic() {

  }

  void start() {

    // Drive with Xbox drive.

    // That means that the Y axis drives forward

    // and backward, and the X turns left and right.

    double throttle = (-0.25*m_stick.getThrottle())+0.75;

    double ySpeed = throttle * m_xboxController.getTriggerAxis(Hand.kRight); { 

      if (m_xboxController.getTriggerAxis(Hand.kLeft) > 0) 

     ySpeed = -(throttle * m_xboxController.getTriggerAxis(Hand.kLeft));

    }

    double xSpeed = throttle * m_xboxController.getX(Hand.kLeft);

   // double outputThrottle 

    if (m_stick.getRawButtonPressed(2)) {

      m_toggleState = !m_toggleState;

    }

    System.out.println("Throttle: " + throttle);

    System.out.println("YSpeed: " + ySpeed);

    System.out.println("XSpeed: " + xSpeed);

    m_robotDrive.arcadeDrive(ySpeed, xSpeed);

    boolean triggerState = m_stick.getTrigger();

    double output = 0;

    if (triggerState == true) {

      if (m_toggleState) {

        m_outputMotor.set(-0.3);

      

      } else{

        m_outputMotor.set(-1);

      }

    }

    else{m_outputMotor.set(0);}

    System.out.println("Output motor: " + m_outputMotor.get());

  }

}

Why do you have all of your code in a start method? You’re not calling it in teleopPeriodic, which is why it’s not doing anything.

Ah, thank you. One of our newer programmers was fiddling with it yesterday, trying to add a video stream. I’ll look into it. -Mason J.S., Team 6542.

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