UNOFFICIAL: basic auto straight

@Kevin, I am creating this thread to allow for unofficial help from other programmers not on RobotC’s staff. With regard to the question posted here, what kind of encoder are you using? I would assume the red quadrature encoders with 2 wires, since they count up and down. One solution to your problem is simply switching the ports the left encoder is plugged into. That will reverse the count direction. Another option is putting a negative sign (-) in front of nMotorEncoder[leftMotor], since it counts backwards.

I’m Using IME’s so they are daisy chained into the I2C port. If I put a - sign in front of nMotorEncoder like this?

if(-nMotorEncoder[leftMotor] < nMotorEncoder[rightMotor])

The encoder itself is still rotating in a negative direction isn’t it? I’m trying figure out if it is actually checking all 3 if statements or not.

Another way to fix the problem you’re having is to reverse the polarity of the motor’s connection to the Cortex or motor controller it’s plugged into by flipping the 2-wire connector so that the red wire goes to black and vice versa. Then, reverse the motor in ROBOTC and the encoder will count up and the motor will move “forward” when you send it a positive power.

Yes, it is still counting backwards, but that doesn’t matter since the if statement will use the opposite of whatever value the encoder returns, so -500 becomes 500 and 400 becomes -400 (for the purposes of the if statement’s condition only, in the sense that this doesn’t actually change the value of the encoder count).

I second this. This is how we have solved this “problem” in the past. It is one of the few times it seems acceptable to have wiring “backwards”. With the old school quad encoders you could simply reverse the 2 wires of the sensor, but because IME are built into the motor itself the only way to “fool” it is to reverse the polarity of the motor.

With the motors wired correctly, I don’t think I’ve ever had that issue with IMEs. I’ve always found that the left side is normal and the right side is reversed, except with gears on the drive. You might check all of your wires on the left motor. Also, is the right side reversed?

If you’re using RobotC a simple solution would be to store the encoder ticks to a global variable in a while loop and store the correct value.

int realLeftEncoder;
int realRightEncoder;

while (true){
	realLeftEncoder = -(SensorValue[leftEncoder]);
	realRightEncoder = SensorValue[rightEncoder];

That way every time you reference your encoder ticks you’re getting the correct readings

But if you’re using IMEs then you would have to just do as stated above, by reversing the polarity of the connection

When setup correctly, nMotorEncoder will always return incrementing values for positive motor control.

Forgot about that, haven’t used IMEs much recently

Excellent advice, thank you James, but I would like to share a problem that my team, 9594C, experienced this year for the fist time … the red and black motor wires, on two brand new motors, were internally switched, so a positive signal made the motor spin backwards! Another issue we are still having, is motors, that were working properly, suddenly start running backwards … in this case we simply redownload the firmware and all goes back to normal. Apparantly a static electricity issue.