Code:
/**
* Set the PWM value based on a speed.
*
* This is intended to be used by speed controllers.
*
* @pre SetMaxPositivePwm() called.
* @pre SetMinPositivePwm() called.
* @pre SetCenterPwm() called.
* @pre SetMaxNegativePwm() called.
* @pre SetMinNegativePwm() called.
*
* @param speed The speed to set the speed controller between -1.0 and 1.0.
*/
void PWM::SetSpeed(float speed)
{
if (StatusIsFatal()) return;
// clamp speed to be in the range 1.0 >= speed >= -1.0
if (speed < -1.0)
{
speed = -1.0;
}
else if (speed > 1.0)
{
speed = 1.0;
}
// calculate the desired output pwm value by scaling the speed appropriately
INT32 rawValue;
if (speed == 0.0)
{
rawValue = GetCenterPwm();
}
else if (speed > 0.0)
{
rawValue = (INT32)(speed * ((float)GetPositiveScaleFactor()) +
((float) GetMinPositivePwm()) + 0.5);
}
else
{
rawValue = (INT32)(speed * ((float)GetNegativeScaleFactor()) +
((float) GetMaxNegativePwm()) + 0.5);
}
// the above should result in a pwm_value in the valid range
wpi_assert((rawValue >= GetMinNegativePwm()) && (rawValue <= GetMaxPositivePwm()));
wpi_assert(rawValue != kPwmDisabled);
// send the computed pwm value to the FPGA
SetRaw((UINT8)rawValue);
}
What speed are you calling the function with (or some object that calls the function). If it's not x|-1.0<=x<=1.0 then that might be the cause of your issues.
Edit: The assert that's failing is the second-to-last assert