Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Any help appreciated (http://www.chiefdelphi.com/forums/showthread.php?t=143308)

jayjay 06-02-2016 14:46

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(Rob ot.java:38), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:72), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:241)]

Here is my code:

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.

rich2202 06-02-2016 15:39

Re: Any help appreciated
 
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.

Joe Ross 06-02-2016 16:00

Re: Any help appreciated
 
Quote:

Originally Posted by rich2202 (Post 1536060)
I don't know Java, but my guess is skip using robotdrive.motortype. That class presumes 4 control signals, whereas you only have 2.

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

jayjay 07-02-2016 09:52

Re: Any help appreciated
 
Rich/Joe, thanks for the helpful advice.

I will do what Joe has suggested. Thanks again.


All times are GMT -5. The time now is 00:38.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi