What's wrong with our code?

Below is our code for our pre-season bot to help us practice code. Could anybody tell us if you see any errors? Currently, it is not running! Help would be immensely appreciated!

-Team 4501:D

Can you explain in what manner is it not running?

Overall, the code seems fine, have you tried checking the driver station logs? Those can be your best friend in resolving most code issues.

  • Roshan
    Team 4909

In DriveManual, you never initialize OI. I’m guessing you get an error message telling you there’s a null pointer exception on line 29 of org.usfirst.frc.team4501.robot.commands.DriveManual. In the future, you’ll get help much faster if you post the error message, and you can most likely find the error yourself by looking at the error message, WPILib generally has pretty good messages.

Thanks so much guys! We are currently waiting for the RIO to be connected. Will post the error log if your suggestions didn’t work.

I’m on my phone so its going to be hard to fully note what i seen. Why are you even creating an instance of OI in drivemanual? You already have one created here

public void robotInit() {
		oi = new OI();

Use this to get the values

Robot.OI.gettriggers

you could make a copy of the OI. That might work.

public class DriveManual extends Command {
	
	**private final** OI oi = Robot.oi;

    public DriveManual() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
    	requires(Robot.driveTrain);
    	
    	
    }

Again I would just

package org.usfirst.frc.team4501.robot.commands;

import org.usfirst.frc.team4501.robot.OI;
import org.usfirst.frc.team4501.robot.Robot;

import edu.wpi.first.wpilibj.command.Command;

/**
 *
 */
public class DriveManual extends Command {
	
	//Remove
        //OI oi;

    public DriveManual() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
    	requires(Robot.driveTrain);
    	//Remove
        //OI oi;
    	
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    	Robot.driveTrain.drivemanual(Robot.oi.getTriggers(), Robot.oi.getLeftXboxX());
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
         //Maybe Shut it down if the command ends?
         Robot.driveTrain.drivemanual(0,0);
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
          end();
    }
}

Another thing I see is in the Drivetrain subs system is and I’m going from memory

public void drivemanual(double move, double turn) { //double speed1, double speed2) {

                //I like to be more descriptive with the variable name. Arcade is move, turn. Tank is speed, speed

                drive.arcadeDrive(move, turn);
		//drive.arcadeDrive(speed1, speed2);
	}
	
	public void driveauto(double speedx, double speedy) {
		drive.tankDrive(speedx, speedy);
		drive.setSafetyEnabled(false);
	}