billbo911
25-01-2008, 14:16
OK, I am no programming Guru, so I am asking for help.
I am coding a simple torque limiting function. I have very carefully checked my work, yet when I "Build All", MPLAB says I made a Syntax error. When I comment out the entire function, the error goes away. Please take a look at it and comment to your hearts content. The error is on line 111, which is where my first "if" takes place.
/************************************************** ****** ****************************
* Function name: Torque_Limit
*
* Purpose: Reduce max torque to allow smoother driving transitions
*
* Called from: autonomous./Autonomous(), and teleop.c/Teleop()
*
* Arguments: Target value from code or joystick, Previous value of pwm,
* Max change (MAXTORQUE). DO NOT FORGET TO STORE FINAL PWM VALUE TO CORRECT
* VARIABLE (lastpwmXX) WHEN RETURNED!!!
*
* Returns: (int) pwm value
*
*
************************************************** ************************************/
int Torque_Limit (int target, int previous)
{
int setpmw;
if((target - previous) > MAXTORQUE)
{
setpwm = (previous + MAXTORQUE);
}
else if((previous - target) > MAXTORQUE)
{
setpwm = (previous - MAXTORQUE);
}
else
{
setpwm = target;
}
return setpwm;
}
See the screen shot for the error.
I am coding a simple torque limiting function. I have very carefully checked my work, yet when I "Build All", MPLAB says I made a Syntax error. When I comment out the entire function, the error goes away. Please take a look at it and comment to your hearts content. The error is on line 111, which is where my first "if" takes place.
/************************************************** ****** ****************************
* Function name: Torque_Limit
*
* Purpose: Reduce max torque to allow smoother driving transitions
*
* Called from: autonomous./Autonomous(), and teleop.c/Teleop()
*
* Arguments: Target value from code or joystick, Previous value of pwm,
* Max change (MAXTORQUE). DO NOT FORGET TO STORE FINAL PWM VALUE TO CORRECT
* VARIABLE (lastpwmXX) WHEN RETURNED!!!
*
* Returns: (int) pwm value
*
*
************************************************** ************************************/
int Torque_Limit (int target, int previous)
{
int setpmw;
if((target - previous) > MAXTORQUE)
{
setpwm = (previous + MAXTORQUE);
}
else if((previous - target) > MAXTORQUE)
{
setpwm = (previous - MAXTORQUE);
}
else
{
setpwm = target;
}
return setpwm;
}
See the screen shot for the error.