Inverted Turning

Our robot goes forward and backwards fine, but right=left and left=right. It appears the speed controllers are wired properly, if did notice however that the LED on the speed controller is flashing green on one and red on one when the stick is pushed forward and the robot is going forward. To verify that it was not an electrical problem i reversed the leads from one of the motors then forward and backward = turn and vice versa.

This is for 2 motor drive, left = PWM 1, right = PWM 2. This is with the simple robot template.

I did verify that the speed controller’s + and - are wired correctly and the motor’s are wired in the same direction (+ to red and - to black)

I just don’t know whats going on. Any help is appreciated, I just got the camera to work and here we are another problem…

The reason one speed controller goes green and the other goes red is that the motors need to turn in opposite directions for the wheels to go in the same direction. That’s not a problem.

Can you make absolutely certain that the PWM cables are going to the speed controllers they ought to? (If you accidentally swap the cables between PWM1 and PWM2, the robot will behave as you observe.)

I did swap them to test, and instead of inverting the turning it inverted forward and backward. I tried this in both software and hardware (rebooting the cRIO in between to be sure the code changed, also verified that by changing something in autonomous to confirm the code made it. ).

I’ll give it another try tmrw, I just got home, internet at school was a bit funky.

I flipped the PWM’s again just now, the robot just inverts forward and backwards now.

I find that it’s a lot easier to diagnose these issues in tank drive rather then arcade, because it’s easier to see the input directly affect the output. In tank mode, once the correct side goes forward at the correct time, then arcade mode will work properly.

Don’t just blindly start swapping things around. Look at how the program has the left and right motors defined, and make sure those are the motors actually being controlled by the relevant PWM outputs. You have to make the code consistent with physical reality. :slight_smile:

Then, when you find that a motor is going in the direction opposite the way you think it should, change the “Invert” constant for that motor on the Drive Open vi.

(If you have wired the motors the way I think is most natural, the left motor should not be inverted and the right one should be. It’s possible that your wiring is backwards from the way I expect, or perhaps your gearboxes are doing an extra reversal from the actual motor direction. It’s not really important which one is which, only that the wheels go in the direction you want them to.)

How would I invert the motors in C++?

By my understanding shoulden’t the robot invert its turning if I switch the PWM channels? It doesn’t seem to make sense to me that the robot goes backwards when the PWM’s are switched.

Ive tried to switch the motors and use setinverted motor. It still seems to turn the wrong way, forwards and backwards seems to be right though…

Think about which way the motors turn in order for the robot to move forwards. Drivetrain designs with both motors going the same direction are vanishingly rare. Almost invariably, one spins clockwise and the other spins counterclockwise.

When you swap the motor control, you’re telling each motor to turn the way the other one used to. That runs the robot in the other direction.

Just look at the code, and at the robot wiring, and make sure that the PWM signal configured as the left motor is the same one physically connected to the left motor. Do the same for the right motor. Then if either side of the robot runs in the wrong direction, invert that motor’s control in the code.

It appears the motor is turning the right way, I have checked PWM 1 is connected to left motor and PWM 2 is connected to the right motor.

Both motors seems to be turning in the right direction, else the bot would be going backwards. The bot still turns the wrong way.

If you’re confident that the wiring is correct, then let’s go ahead and look at the programming. Have you changed anything from the defaults? Show us how you’re initializing the drive motors, and how you’re controlling them.

PWM 1 is connected to the Jaguar controlling the LEFT motor, and PWM is controlling the RIGHT motor

This is the whole program

#include “WPILib.h”
#include “vxWorks.h”
#include “Vision/AxisCamera2010.h”
#include “PCVideoServer.h”

class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick;

Compressor airc;

public:
RobotDemo(void):
myRobot(1, 2), // these must be initialized in the same order
stick(1), // as they are declared above.

    airc(1,1)
{
   
    GetWatchdog().SetExpiration(1.0);
    GetWatchdog().SetEnabled(false);
    
    AxisCamera &camera = AxisCamera::getInstance();
    camera.writeResolution(k640x480);
    camera.writeBrightness(10);
    camera.writeCompression(25);
    
    airc.Start();
}

void Autonomous(void)
{
GetWatchdog().SetEnabled(false);
Solenoid *s1;
Solenoid *s2;

    s1 = new Solenoid(1);
    s2 = new Solenoid(2);
    
  Wait(3.000);
  s1->Set(true);
  s2->Set(false);
  Wait(3.000);
  s1->Set(false);
  s2->Set(true);

}

void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
while (IsOperatorControl())
{
GetWatchdog().Feed();
myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
Wait(0.005); // wait for a motor update time
}
}
};

START_ROBOT_CLASS(RobotDemo);