Errors when running

Hi,
Our code uses the command based robot template, and builds and downloads with no problems. However, there is an error message that comes in waves through the console, and sometimes creates lag issues. It looks like this:

Assertion failed: “(rawValue >= GetMinNegativePwn()) && (rawValue <= GetMaxPositivePwn())” in SetSpeed() in C://WindRiver/workspace/WPILib/PWM.cpp at line 241

This message then repeats itself a bunch of times and then stops, and comes back again sometime later.

When it happens, it often creates lag, which might be detrimental when it comes to the competition. Any help would be greatly appreciated.

What’s the rest of that statement? Are you calling an ASSERT? Without seeing the entire command one can only guess what the issue may be.

The errors happen in the console, and no where in our code do we use anything directly from a PWM class. I’m thinking somehow, the jaguars and victors are causing it. Do you want me to post code that operates on those objects?

I’m sure you include WPILib and by extension you are also including the PWM.cpp. I bet if you look in the PWM.cpp file at the line specified there will be an assertion of some kind made by that code that is then failing and that’s why you’re getting this error. I’m at work and don’t have the libraries in front of me to try and find it myself. Some part of your inputs the PWM doesn’t like.


/**
 * 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

Thanks!

I looked through the code again, and I found a place where I divide the driver input value by itself. This gives NaN when the values are 0, and this created the assertion error.

Thank you everyone, I appreciate everyone’s help!