Two param constructor added to C++/java CANTalon so caller can optionally specify the periodMs at which the talon control frame is sent.

The param is capped in the HAL C++ class to [1ms, 95ms] so that zero and negative periods are caped to 1ms, and so that caller can't pass an absurdly large value, which causes TALON is appear disabled.

Change-Id: I4207194be25a33bbd6ad281a75301ce6684659a5
This commit is contained in:
Omar Zrien
2014-12-14 17:09:52 -05:00
parent 77997e52fb
commit 6a7e7cf611
4 changed files with 34 additions and 1 deletions

View File

@@ -242,6 +242,11 @@ typedef struct _TALON_Param_Response_t {
CanTalonSRX::CanTalonSRX(int deviceNumber,int controlPeriodMs): CtreCanNode(deviceNumber), _can_h(0), _can_stat(0)
{
/* bound period to be within [1 ms,95 ms] */
if(controlPeriodMs < 1)
controlPeriodMs = 1;
else if(controlPeriodMs > 95)
controlPeriodMs = 95;
RegisterRx(STATUS_1 | (UINT8)deviceNumber );
RegisterRx(STATUS_2 | (UINT8)deviceNumber );
RegisterRx(STATUS_3 | (UINT8)deviceNumber );

View File

@@ -28,6 +28,7 @@ public:
EncFalling=5
};
explicit CANTalon(int deviceNumber);
explicit CANTalon(int deviceNumber,int controlPeriodMs);
virtual ~CANTalon();
// PIDController interface

View File

@@ -24,7 +24,24 @@ CANTalon::CANTalon(int deviceNumber)
SetControlMode(m_controlMode);
m_impl->SetProfileSlotSelect(m_profile);
}
/**
* Constructor for the CANTalon device.
* @param deviceNumber The CAN ID of the Talon SRX
* @param controlPeriodMs The period in ms to send the CAN control frame.
* Period is bounded to [1ms, 95ms].
*/
CANTalon::CANTalon(int deviceNumber,int controlPeriodMs)
: m_deviceNumber(deviceNumber)
, m_impl(new CanTalonSRX(deviceNumber,controlPeriodMs)) /* bounded underneath to be within [1 ms,95 ms] */
, m_safetyHelper(new MotorSafetyHelper(this))
, m_profile(0)
, m_controlEnabled(true)
, m_controlMode(kPercentVbus)
, m_setPoint(0)
{
SetControlMode(m_controlMode);
m_impl->SetProfileSlotSelect(m_profile);
}
CANTalon::~CANTalon() {
delete m_impl;
delete m_safetyHelper;

View File

@@ -76,6 +76,16 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
setProfile(m_profile);
changeControlMode(ControlMode.PercentVbus);
}
public CANTalon(int deviceNumber,int controlPeriodMs) {
m_deviceNumber = deviceNumber;
m_impl = new CanTalonSRX(deviceNumber,controlPeriodMs); /* bound period to be within [1 ms,95 ms] */
m_safetyHelper = new MotorSafetyHelper(this);
m_controlEnabled = true;
m_profile = 0;
m_setPoint = 0;
setProfile(m_profile);
changeControlMode(ControlMode.PercentVbus);
}
@Override
public void pidWrite(double output)