Kitbot code not Turning

has anyone ran into the issue of the kit bot code not wanting to turn because we are very confused on it and have tried multiple ways we know of fixing it any help would be amazing

Is it able to drive forward and backwards correctly? And are the joystick/controllers IDs set correctly in code and being detected correctly?

yes it all set fine and is running forward and backwards smoothly

Can you please send the code?

discoduck39/javacodefrc2024 (github.com)

can you access this

Here is our teams kitbot code. It uses joysticks. Is your but doing anything you try to turn it or nothing?

1 Like

it not doing anything when we try to turn it

I would recommend printing the values being sent to the drive command and make sure that rotation actually has a value.
You can do this with a System.out.println
or using SmartDashboard

Could you possibly explain how to do this I have never done ether of those and it would be a really big help.

Of course! You can add the lines to the drive method.
A print statement will print the string it is given directly to your driver station log. Here is an example of that, note that I am adding in the variables and they are converted into the string.

 /*Method to control the drivetrain using arcade drive. Arcade drive takes a speed in the X (forward/back) direction
   * and a rotation about the Z (turning the robot about it's center) and uses these to control the drivetrain motors */
  public void arcadeDrive(double speed, double rotation) {
    m_drivetrain.arcadeDrive(speed, rotation);
System.out.println(“Speed :  “ + speed + “ Rotation : “ + rotation);
  }

SmartDashboard is a little more complicated since it uses network tables but there is a lot more you can do with it. These values will post to the Shuffleboard tab.

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

public void arcadeDrive(double speed, double rotation) {
  // Drive the robot using arcade controls
  m_drivetrain.arcadeDrive(speed, rotation);

  // Output the speed and rotation values to the SmartDashboard
  SmartDashboard.putNumber("Speed", speed);
  SmartDashboard.putNumber("Rotation", rotation);
}

Here is the FIRST docs on smart dashboard. And here are some more GUI examples with Smart Dashboard.

1 Like

Looking at this code, I see that you’ve configured speed to be controlled by “left Y” and rotation by “right X”. Sorry to ask the obvious, but can you confirm that you’re moving the right stick when trying to turn (as opposed to the left stick, which controls speed)?

2 Likes

What game pad controller are you using to drive you robot?

Yes we are but still not getting anything

An Xbox controller

Can you see the axis move on the USB Devices Tab? Have you tried switching it to getLeftX?

You’re code isn’t working because you’re using a Joystick class, instead of the CommandXboxController.

Your current code calls getTwist() which is looking for data for axis 3, but the right X isn’t value 3.

Change the code here: to instantiate CommandXboxControllers.
private final CommandXboxController m_driver = new CommandXboxController(OperatorConstants.kDriverControllerPort);

Then change the default command binding to:

m_drivetrain.setDefaultCommand(
        new RunCommand(
            () ->
                m_drivetrain.arcadeDrive(
                    -m_driver.getLeftY()*Constants.OperatorConstants.kDriverSpeedMultiplier,
                    -m_driver.getRightX()*Constants.OperatorConstants.kDriverSpeedMultiplier),
            m_drivetrain));

Edit to add:
If you open Driverstation and click the USB icon on the left. When you move the joystick axis you should see the values change. The right axis on the xbox controller is the fifth axis (index 4)…I think.

2 Likes

Thank you