Any help appreciated

I have written a simple java program to test our 2016 bot. I have update the firmware, image and jre on our 2015 roborio, and updated to the latest version of Eclipse. Our drive consists of four motors – one Talon controller with a y-splitter controls the two left motors, and another Talon with a y-splitter controls the two right motors.

The bot works with a simple arcade drive coded in the teleop method. When I add the setInvertedMotors code (which worked last year), I get “no code” on the bot, a red comm light on the roborio, and the following error:

ERROR Unhandled exception: java.lang.NullPointerException at [edu.wpi.first.wpilibj.RobotDrive.setInvertedMotor(RobotDrive.java:703), org.usfirst.frc.team4951.robot.Robot.robotInit(Robot.java:38), edu.wpi.first.wpilibj.IterativeRobot.startCompetition(IterativeRobot.java:72), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:241)]

Here is my code:

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.RobotDrive.MotorType;

public class Robot extends IterativeRobot {
    final String defaultAuto = "Default";
    final String customAuto = "My Auto";
    String autoSelected;
    SendableChooser chooser;
    
    RobotDrive myDrive;
    Joystick stick0, stick1;
	
    public void robotInit() {
        chooser = new SendableChooser();
        chooser.addDefault("Default Auto", defaultAuto);
        chooser.addObject("My Auto", customAuto);
        SmartDashboard.putData("Auto choices", chooser);
        
        myDrive = new RobotDrive(0,1); // 0 = left, 1 = right

        stick0 = new Joystick(0);
        stick1 = new Joystick(1);
        
        myDrive.setInvertedMotor(MotorType.kFrontLeft, true);
        myDrive.setInvertedMotor(MotorType.kRearLeft, true);
        
    }
    
    public void autonomousInit() {
    	//autoSelected = (String) chooser.getSelected();
//		autoSelected = Smart;Dashboard.getString("Auto Selector", defaultAuto);
		//System.out.println("Auto selected: " + autoSelected);
    }

    public void autonomousPeriodic() {
    	switch(autoSelected) {
    	case customAuto:
        //Put custom auto code here   
            break;
    	case defaultAuto:
    	default:
    	//Put default auto code here
            break;
    	}
    }

    public void teleopPeriodic() {
        myDrive.arcadeDrive(stick0);
    }

    public void testPeriodic() {
    
    } 
}

Any help with the error would be appreciated. Thanks.

I don’t know Java, but my guess is skip using robotdrive.motortype. That class presumes 4 control signals, whereas you only have 2.

Use robotdrive(left channel, right channel) to set your motor channels.

Also, I presume you are using one motor controller per motor, and splitting the Pwm signal. You can’t drive 2 cim motors with one controller.

Close. It should work with 2, but you have to use the correct 2. It should be kRearLeft and kRearRight.

Rich/Joe, thanks for the helpful advice.

I will do what Joe has suggested. Thanks again.