Trying to get tank drive with Joysticks

Hello!

I am a mentor on team 3098 having trouble with programming. I’m not the best programmer, but I know enough to get by; we don’t have any students for programming.

After years of working on the 2022’s code (I know what I said), I’m having trouble trying to program a test board with CAN talons with a Logitech “extreme 3D pro” joystick. I was able to get an xbox controller to work on another test board, but the team has requested the use of two joysticks for tank controls.

I have tried many different attempts at getting the Y value of the joystick, ranging from importing JoystickBase to leftJoystick.getAxis(Joystick.AxisType.kY); to attempting to assigning 3 variables to new Joystick(0,2,0). I’ve basically been going down the list on the Joystick class found here.

leftDriveSpeed = leftJoystick.getY(); 
rightDriveSpeed = rightJoystick.getY();
m_driveTrain.drive(leftDriveSpeed, rightDriveSpeed);

I’m still confused on trying to get it to work. All the talons turn on with solid orange when the board is enabled, but I receive no red/green indication that the talons are receiving data. Both the FRC Driver’s Station program and Windows 10 receive the inputs of the joysticks, but it does not reflect such inputs on the electronics board via the talons.

Full zip of program is here

We meet again on Thursday, so I’ll check chief delphi again then.

Many thanks,
Aaron

Plug the joystick into a PC, open the FRC driver station application, then switch to the USB tab and see what values you get for the joystick in different positions. It’ll tell you what port and axis number to use in code, as well as which direction is positive.

1 Like

Where is this code in your zip file? I didn’t see it in any of the places I expected to see it.

Yes, sharing your code will help.

A few quick questions.
Did you set the CAN ids in the CTRE Tuner?
Also, when you instatiate the motors in code, do you use the CAN ids you set?
Are you getting any errors in code?
Do you use the drivetrain object?
Are you using the WPI_Talon class rather than the CTRE_Talon class?

You set the default command of the DriveTrain subsystem to be an instance of TankDrive.

In your TankDrive implementation on dropbox you have an empty execute() method.

Here is an implementation from our 2022 training project this year with a simplified default drive command. This example is mostly transferable to what you are looking to do for your team, you’d just need to change the axis values to be correct and probably need to fixup whether or not you have.

That project is designed to run in the simulator, so if you build that and plug in your joystick you should be able to realistically drive the robot in the field2d space and see it work. If you’ve got a laptop and a joystick you don’t need to wait until you have the robot to test.

Apologies for the late reply.

I plugged the joysticks into the computer, left joystick is on port 1, right joystick is on port 2, with the xbox controller on port 0. It’s labelled as Axes 1: Y Axis. With such information, I used rightJoystick.getAxis(1); for the appropriate joystick. I still receive an error for doing so:

TankDrive.java:76: error: cannot find symbol
            rightDriveSpeed = rightJoystick.getAxis(1);
                                           ^
  symbol:   method getAxis(int)
  location: variable rightJoystick of type Joystick

I have no idea what that means.

Lines 75-79 under public void execute() in the TankDrive.java file.

We tuned the CAN IDs for what we desired using phoenix tuner. So the appropriate ports on the CAN IDs listed in the program are correct in reference to our circuit board.
I’ve just tried the CTRE_Talon class and the CTRE_TalonSRX class with proper importing and reassigning as appropriate, but all came up as errors and that the variables could not be found.
I don’t know what the drivetrain object is, or how to use it. I’m unsure what you mean by instatiate the motors in code. If you meant initiate, I’m still unsure. My apologies.
I set those CAN IDs with Phoenix tuner.
All errors are noted in another reply.

There isn’t a method called getAxis. Do you mean getRawAxis?

This is what I see in execute of the TankDrive.java file in the zip you uploaded

    // Called every time the scheduler runs while the command is scheduled.
    @Override
    public void execute() {
    }

My apologies, I sent the wrong code.

Please let me know if this doesn’t work or has missing content.

Yes I realized I sent the wrong code.

There’s a link in another reply

I wish to amend that I’m getting this same error with the current code:
ERROR  1  DifferentialDrive... Output not updated often enough.  edu.wpi.first.wpilibj.MotorSafety.check(MotorSafety.java:96)

    public void drive(double left, double right) {
        left = 0;
        right = 0;//to combat error of diff drive not updated enough - doesnt work
        drive.tankDrive(left, right);
    }

Setting left and right to 0 will guarantee that the robot never moves.

Where do you schedule the TankDrive command? It looks like setting it as default command is commented out. If you never call a DifferentialDrive drive method, that’s what causes the Output not updated often enough.

1 Like

Thank you so much! I knew exactly what you meant when you said I commented it out (robotcontainer.java, lines 66 to 101 right?). I did so because I kept getting an error with FRC driver’s station on no robot code being installed. The error is as follows:

ERROR  1  Unhandled exception: java.lang.NullPointerException  frc.robot.commands.TankDrive.<init>(TankDrive.java:41) 
 Error at frc.robot.commands.TankDrive.<init>(TankDrive.java:41): Unhandled exception: java.lang.NullPointerException 
 	at frc.robot.commands.TankDrive.<init>(TankDrive.java:41) 
 	at frc.robot.RobotContainer.<init>(RobotContainer.java:86) 
 	at frc.robot.RobotContainer.<clinit>(RobotContainer.java:42) 
Warning  1  The robot program quit unexpectedly. This is usually due to a code error.
  The above stacktrace can help determine where the error occurred.
  See https://wpilib.org/stacktrace for more information.  edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:388) 
ERROR  1  The startCompetition() method (or methods called by it) should have handled the exception above.  edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:395) 
 	at frc.robot.Robot.robotInit(Robot.java:43) 
 	at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107) 
 	at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373) 
 	at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:463) 
 	at frc.robot.Main.main(Main.java:31)

The issue is that the TankDrive command is created in the RobotContainer constructor but it calls the RobotContainer getJoystick methods as static initialization. At that point RobotContainer isn’t fully constructed, so you get a null pointer. In the TankDrive command, you can move getting the joysticks to the initialize method, or just get the values in execute to fix it.

thank you so much!

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