Reverse Driver Controls with Button Press

We’d like to press a button and have the driver controls reversed. So, the back of the robot becomes the front of the robot. Any suggestions on how to? Thanks!

1 Like

Define a variable:

drive_mode=0/1
change drive mode with a button press

Put that variable into your chassis control code:

if drive_mode=0
then normal controls
motors_left = left stick percent
motors_right = right stick percent

if drive_mode=1
then reverse controls
motors_left = right stick negative percent
motors_right = left stick negative percent

2 Likes

I’m not too familiar with this, but wouldn’t this mean you can only drive forward? regardless of direction?

The controller axis values map from -100 → 100. So it would continue to allow both forwards and backwards movement, just inverting the controller output.

1 Like

No. My ‘code’ was hasty but overall should work. Might need tweaks, but hopefully the OP gets the idea.

Let me guess, is this to have two modes, one for disc pickup and one for shooting??

Thanks for the response. We use VEXcode IQ Blocks. Does your suggestion work for that programming language?

Yes, exactly. Any suggestion? We use VEXcode IQ Blocks.

Yes. However, you can use ‘shift’ keys. Where you hold a button down and the actions of other buttons are shifted to new actions.

Because it’s easy, we program the driver controls with the default ‘tank mode’ drive train. Could a ‘shift button’ work with that? Or would the shift only work if we manually program the drive controls?

Seems honestly inconvenient to drive and hold a button, our team has it binded to a button that toggles drive modes.

Not sure… probably only manually. Have not checked personally. That said… I would strongly encourage coding… will give more bot abilities.

And, learning to think, plan, code, etc is all part of the fun/learning.

You don’t have to go straight to python/etc. Blocks are MUCH more capable than they are given credit for. If you don’t believe me, search for the “m&m” bot thread under my name.

1 Like

Just flip your wires in the code. If yours is ports 10,9 - 1,2 make it 1,2-10,9

messing with your code setup probably isn’t a good idea
there’s a reason its only accessible if you turn on advanced editor

I havn’t tested this on a robot yet, and it is a bit convoluted, but I might be able to give you the gist


You could actually make it simpler by setting velocity, example bellow.

Blocks
Screenshot 2022-12-12 11.14.21 AM


Python (The formatting is weird I apologise I have it in something)

    lMotor.spin(FORWARD)
    rMotor.spin(FORWARD)
    while True:
        while not Reversed:
            if math.fabs(controller.axisA.position()) > Deadzone and math.fabs(controller.axisC.position()) > Deadzone:
                lMotor.set_velocity((controller.axisA.position() + controller.axisC.position()), PERCENT)
                rMotor.set_velocity((controller.axisA.position() - controller.axisC.position()), PERCENT)
            elif math.fabs(controller.axisA.position()) > Deadzone:
                lMotor.set_velocity(controller.axisA.position(), PERCENT)
                rMotor.set_velocity(controller.axisA.position(), PERCENT)
            elif math.fabs(controller.axisC.position()) > Deadzone:
                lMotor.set_velocity(controller.axisC.position(), PERCENT)
                rMotor.set_velocity((controller.axisC.position() * -1), PERCENT)
            else:
                lMotor.set_velocity(0, PERCENT)
                rMotor.set_velocity(0, PERCENT)
            while Reversed:
                if math.fabs(controller.axisA.position()) > Deadzone and math.fabs(controller.axisC.position()) > Deadzone:
                    lMotor.set_velocity((controller.axisA.position() * -1 + controller.axisC.position()), PERCENT)
                    rMotor.set_velocity((controller.axisA.position() * -1 - controller.axisC.position()), PERCENT)
                elif math.fabs(controller.axisA.position()) > Deadzone:
                    lMotor.set_velocity((controller.axisA.position() * -1), PERCENT)
                    rMotor.set_velocity((controller.axisA.position() * -1), PERCENT)
                elif math.fabs(controller.axisC.position()) > Deadzone:
                    lMotor.set_velocity(controller.axisC.position(), PERCENT)
                    rMotor.set_velocity((controller.axisC.position() * -1), PERCENT)
                else:
                    lMotor.set_velocity(0, PERCENT)
                    rMotor.set_velocity(0, PERCENT)
                wait(20, MSEC)
            wait(20, MSEC)
        wait(20, MSEC)

If you have any questions feel free to ask!

Only if you manually program the driving controls.