Quote:
|
Originally Posted by mattsavela
One of the students on the team were saying something about how our left motor seems to move faster than our right motor. What I think I need to know is how to make our motors adjust to this...
|
You can rescale the power output of the faster motor to more closely match the slower motor using something proportional like:
Code:
#define LEFT_MOTOR_CORRECTION 42; // example value at full pwm (254)
signed int LeftPwm;
...
//Proportional drop in power
LeftPwm = (int)pwm15; //assume pwm15 has already been set by the joystick mixing code
LeftPwm -= 127; //Just because math is clearer if we make 0 neutral (-127 reverse, 127 forward)
if (LeftPwm > 0)
{
LeftPwm = LeftPwm - (LeftPwm / 127 * LEFT_MOTOR_CORRECTION);
}
else if (LeftPwm < 0)
{
LeftPwm = LeftPwm + (LeftPwm / 127 * LEFT_MOTOR_CORRECTION);
}
pwm15 = (unsigned char)(LeftPwm + 127); // restore the normal 0-254 range
This reduces the Left Motor pwm by an amount proportional to the “speed” requested by the joystick.
You’ll have to discover through measurement or trial & error what pwm value (e.g., 220 instead of 254) for the left motor matches the max pwm value on the right motor at full speed.
Also, be aware that reverse on your machine might require a completely different offset value, i.e., the right motor might be faster than the left motor in reverse. So measure in both directions and correct for them separately.
If that’s the case then something like the following might help:
Code:
#define LEFT_MOTOR_CORRECTION 42; // Correction value at full forward pwm (254)
#define RIGHT_MOTOR_CORRECTION 22; // Correction value at full reverse pwm (254)
// Assumes pwm15 is the Left motor, pwm13 is the Right motor
…
if (pwm15 > 127) // Forward, slow the Left motor
{
pwm15 -= (pwm15-127) / 127 * LEFT_MOTOR_CORRECTION;
}
if (pwm13 < 127) // Reverse, slow the Right motor
{
pwm13 += (127 - pwm13) / 127 * RIGHT_MOTOR_CORRECTION;
}