Ryan M.
08-02-2004, 11:32
I was wondering if someone could look this over. I think it should work, but when run on the robot it doesn't behave at all the way it is expected to.
In rampPWMs.c:
unsigned char rampPWMs(
unsigned char currentPWM,
unsigned char goalPWM,
unsigned char sensitivity,
unsigned char deadZone)
{
// Check if we want to be within one of the dead zones.
if((127 + deadZone > goalPWM) && (goalPWM > 127 - deadZone))
goalPWM = 127;
if(255 - deadZone < goalPWM)
goalPWM = 255;
if(0 + deadZone > goalPWM)
goalPWM = 0;
// Determine if we have to go up or down to reach our goal
// Note that if we are within 'sensitivity' from the goal
// we don't do anything yet. This prevents us from "jittering" and
// keeps us from exceeding 0 or 255 and looping around.
if(currentPWM >= goalPWM + sensitivity)
return currentPWM - sensitivity;
if(currentPWM <= goalPWM - sensitivity)
return currentPWM + sensitivity;
// If we reach here we are within 'sensitivity' of 'goalPWM'.
// It is now safe to go directly to the goal.
return goalPWM;
}
In user_routines.c, I have used that function like this:
unsigned char tempLeftMotorValue = 0;
unsigned char tempRightMotorValue = 0;
// Determine where the joystick wants us
tempLeftMotorValue = Limit_Mix(2000 + p1_y + p1_x - 127);
tempRightMotorValue = Limit_Mix(2000 + p1_y - p1_x + 127);
// This line ramps the joystick values using a low pass filter with a built-in dead bands/zones
driveMotorLeft = rampPWMs(driveMotorLeft, tempLeftMotorValue, DRIVER_SENSE, DRIVER_DEAD_ZONE);
driveMotorRight = rampPWMs(driveMotorRight, tempRightMotorValue, DRIVER_SENSE, DRIVER_DEAD_ZONE);
The Limit_Mix() lines are taken directly from the default code, so they should work correctly.
driveMotorRight and driveMotorLeft are #defined as pwm01 and pwm02.
If anyone notices any possible errors in that stuff, could they please tell me?
PS You could also tell me that it's perfect and it's all the drivetrain team's fault. :)
In rampPWMs.c:
unsigned char rampPWMs(
unsigned char currentPWM,
unsigned char goalPWM,
unsigned char sensitivity,
unsigned char deadZone)
{
// Check if we want to be within one of the dead zones.
if((127 + deadZone > goalPWM) && (goalPWM > 127 - deadZone))
goalPWM = 127;
if(255 - deadZone < goalPWM)
goalPWM = 255;
if(0 + deadZone > goalPWM)
goalPWM = 0;
// Determine if we have to go up or down to reach our goal
// Note that if we are within 'sensitivity' from the goal
// we don't do anything yet. This prevents us from "jittering" and
// keeps us from exceeding 0 or 255 and looping around.
if(currentPWM >= goalPWM + sensitivity)
return currentPWM - sensitivity;
if(currentPWM <= goalPWM - sensitivity)
return currentPWM + sensitivity;
// If we reach here we are within 'sensitivity' of 'goalPWM'.
// It is now safe to go directly to the goal.
return goalPWM;
}
In user_routines.c, I have used that function like this:
unsigned char tempLeftMotorValue = 0;
unsigned char tempRightMotorValue = 0;
// Determine where the joystick wants us
tempLeftMotorValue = Limit_Mix(2000 + p1_y + p1_x - 127);
tempRightMotorValue = Limit_Mix(2000 + p1_y - p1_x + 127);
// This line ramps the joystick values using a low pass filter with a built-in dead bands/zones
driveMotorLeft = rampPWMs(driveMotorLeft, tempLeftMotorValue, DRIVER_SENSE, DRIVER_DEAD_ZONE);
driveMotorRight = rampPWMs(driveMotorRight, tempRightMotorValue, DRIVER_SENSE, DRIVER_DEAD_ZONE);
The Limit_Mix() lines are taken directly from the default code, so they should work correctly.
driveMotorRight and driveMotorLeft are #defined as pwm01 and pwm02.
If anyone notices any possible errors in that stuff, could they please tell me?
PS You could also tell me that it's perfect and it's all the drivetrain team's fault. :)