Exemple #1
0
/**
 * Set the output set-point value.
 *
 * The scale and the units depend on the mode the Jaguar is in.
 * In PercentVbus Mode, the outputValue is from -1.0 to 1.0 (same as PWM Jaguar).
 * In Voltage Mode, the outputValue is in Volts.
 * In Current Mode, the outputValue is in Amps.
 * In Speed Mode, the outputValue is in Rotations/Minute.
 * In Position Mode, the outputValue is in Rotations.
 *
 * @param outputValue The set-point to sent to the motor controller.
 * @param syncGroup The update group to add this Set() to, pending UpdateSyncGroup().  If 0, update immediately.
 */
void CANJaguar::Set(float outputValue, uint8_t syncGroup)
{
    uint32_t messageID;
    uint8_t dataBuffer[8];
    uint8_t dataSize;

    if (m_safetyHelper && !m_safetyHelper->IsAlive())
    {
	EnableControl();
    }

    switch(m_controlMode)
    {
    case kPercentVbus:
	{
	    messageID = LM_API_VOLT_T_SET;
	    if (outputValue > 1.0) outputValue = 1.0;
	    if (outputValue < -1.0) outputValue = -1.0;
	    dataSize = packPercentage(dataBuffer, outputValue);
	}
	break;
    case kSpeed:
	{
	    messageID = LM_API_SPD_T_SET;
	    dataSize = packFXP16_16(dataBuffer, outputValue);
	}
	break;
    case kPosition:
	{
	    messageID = LM_API_POS_T_SET;
	    dataSize = packFXP16_16(dataBuffer, outputValue);
	}
	break;
    case kCurrent:
	{
	    messageID = LM_API_ICTRL_T_SET;
	    dataSize = packFXP8_8(dataBuffer, outputValue);
	}
	break;
    case kVoltage:
	{
	    messageID = LM_API_VCOMP_T_SET;
	    dataSize = packFXP8_8(dataBuffer, outputValue);
	}
	break;
    default:
	return;
    }
    if (syncGroup != 0)
    {
	dataBuffer[dataSize] = syncGroup;
	dataSize++;
    }
    setTransaction(messageID, dataBuffer, dataSize);
    if (m_safetyHelper) m_safetyHelper->Feed();
}
/**
 * Configure the maximum voltage that the Jaguar will ever output.
 * 
 * This can be used to limit the maximum output voltage in all modes so that
 * motors which cannot withstand full bus voltage can be used safely.
 * 
 * @param voltage The maximum voltage output by the Jaguar.
 */
void CANJaguar::ConfigMaxOutputVoltage(double voltage)
{
	UINT8 dataBuffer[8];
	UINT8 dataSize;

	dataSize = packFXP8_8(dataBuffer, voltage);
	setTransaction(LM_API_CFG_MAX_VOUT, dataBuffer, dataSize);
}
Exemple #3
0
/**
 * Set the maximum voltage change rate.
 *
 * When in PercentVbus or Voltage output mode, the rate at which the voltage changes can
 * be limited to reduce current spikes.  Set this to 0.0 to disable rate limiting.
 *
 * @param rampRate The maximum rate of voltage change in Percent Voltage mode in V/s.
 */
void CANJaguar::SetVoltageRampRate(double rampRate)
{
    uint8_t dataBuffer[8];
    uint8_t dataSize;

    switch(m_controlMode)
    {
    case kPercentVbus:
	dataSize = packPercentage(dataBuffer, rampRate / (m_maxOutputVoltage * kControllerRate));
	setTransaction(LM_API_VOLT_SET_RAMP, dataBuffer, dataSize);
	break;
    case kVoltage:
	dataSize = packFXP8_8(dataBuffer, rampRate / kControllerRate);
	setTransaction(LM_API_VCOMP_IN_RAMP, dataBuffer, dataSize);
	break;
    default:
	return;
    }
}
/**
 * Set the output set-point value.  
 * 
 * In PercentVoltage Mode, the input is in the range -1.0 to 1.0
 * 
 * @param outputValue The set-point to sent to the motor controller.
 */
void CANJaguar::Set(float outputValue)
{
	UINT32 messageID;
	UINT8 dataBuffer[8];
	UINT8 dataSize;

	switch(m_controlMode)
	{
	case kPercentVoltage:
		{
			messageID = LM_API_VOLT_T_SET;
			dataSize = packPercentage(dataBuffer, outputValue);
		}
		break;
	case kSpeed:
		{
			messageID = LM_API_SPD_T_SET;
			dataSize = packFXP16_16(dataBuffer, outputValue);
		}
		break;
	case kPosition:
		{
			messageID = LM_API_POS_T_SET;
			dataSize = packFXP16_16(dataBuffer, outputValue);
		}
		break;
	case kCurrent:
		{
			messageID = LM_API_ICTRL_T_SET;
			dataSize = packFXP8_8(dataBuffer, outputValue);
		}
		break;
	default:
		return;
	}
	setTransaction(messageID, dataBuffer, dataSize);
}