Java TankDrive code

Anyone have any working code for TankDrive on bot? Our first year using tank drive and we’re trying to find an example. Last year we did mecanum and that worked well. We’re having issues building the tank drive code to the robot though this year and am looking to isolate whats wrong. Whether it is an error in building the code that isn’t being shown or if the code itself is wrong.

Usually, with the code on the robot right now, whenever it is run, only the right side of the robot runs and the joystick has no effect on it.

This is the code we built that is currently not working.

/----------------------------------------------------------------------------/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. /
/
Open Source Software - may be modified and shared by FRC teams. The code /
/
must be accompanied by the FIRST BSD license file in the root directory of /
/
the project. /
/
----------------------------------------------------------------------------*/

package frc.robot;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.PWMVictorSPX;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.drive.RobotDriveBase;

/**

  • This is a demo program showing the use of the RobotDrive class, specifically
  • it contains the code necessary to operate a robot with tank drive.
    */
    public class Robot extends TimedRobot {
    private DifferentialDrive m_myRobot;
    private static final int kJoystickChannel = 0;

private Joystick m_stick;

int rightMotorPort = 0;
int leftMotorPort = 1;

Talon left = new Talon(leftMotorPort);
Talon right = new Talon(rightMotorPort);;

@Override
public void robotInit() {

m_stick = new Joystick(kJoystickChannel);

}

@Override
public void teleopPeriodic() {
m_myRobot.tankDrive(m_stick.getY(), m_stick.getX());
}
}

If you have the time to crawl through code, our repo from last year is at https://github.com/LakeEffectRobotics/LER2017_VS. A good starting point is in DriveCommand.java.

I would expect a NullPointerException in teleopPeriodic since the code is not initializing m_myRobot. Is that what you are seeing or are we missing some of the code? As for why the right side is moving at all, I do not know. Really looks like some code is missing from the post.

Steve

Here are some presentations that will take you through getting a drivetrain setup with running code.

http://team2363.org/topics/programming/

I would also suggest using arcade style over tank style.

Definitely follow the presentation from Triple Helix linked above, very good explanation of how things are working.

Feel free to use our Github for pointers. We have a drivetrain subsystem setup that has both tankDrive and arcadeDrive methods that you can use for reference.

I suggest printing your joystick values to the console to verify those values are correct. And if they are, then start verifying your PWM wiring and motor wiring is correct.

Thank you for the link, glanced through it and it’s a great resource. Turns out problem was that although I configured the router, I forget to re-image the roborio so none of our code was building.

1 Like

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