No announcement yet.

Changing direction of robot with button

  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing direction of robot with button

    This answer may be somewhere on this forum, but I may not have been searching under the correct title. We would like to be able to push a button on the controller to reverse the direction of the motors. This is so that when we have to drive the robot in reverse, the button can be pushed and it will not act as it is driving forward for the driver. This will also make is easier for the driver to turn instead of having to think backwards. I have seen other robots do this in the past and I wanted to inquire how to do it.

  • #2
    First, setup a boolean to be toggled when a button on the gamepad is pressed. Then simply check that boolean in your drivetrain code, and either negate all the powers or not, depending on the state of the boolean.


    • #3
      Just keep in mind that if you do this, turning will also be reversed (assuming you're using a tank drive). That is what used to be turn left is now turn right and vice versa. When our drivers did this we also had to switch the sides so that turning worked like they expected.


      • #4
        I probably should have explained a little bit more. We are using a holynomic drive train, so each will has it's own motor. I'm also a little sketchy on the programming still and trying to teach my team. Does anyone have an example of the programming?


        • #5
          I would suggest using the gyro instead and doing field relative.

          The short version of what you do is
          1) convert the x,y of the joystick to polar coordinates.
          2) change the theta of the polar coordinates from field relative to robot relative by subtracting the heading angle of the gyro
          3) convert back to cartesian to get a forward and strafe amounts to pass to your holonomic drive train.

          You can see our field relative code from the pre-season. (Yes, it has been tested and it works)

          Hope this helps!

          Coach FTC #16072, Quantum Quacks