diff --git a/wpilibc/wpilibC++Devices/include/CANTalon.h b/wpilibc/wpilibC++Devices/include/CANTalon.h index 838556dd6c..b1322eadcb 100644 --- a/wpilibc/wpilibC++Devices/include/CANTalon.h +++ b/wpilibc/wpilibC++Devices/include/CANTalon.h @@ -129,4 +129,5 @@ private: TalonControlMode m_sendMode; double m_setPoint; + static const unsigned int kDelayForSolicitedSignalsUs = 4000; }; diff --git a/wpilibc/wpilibC++Devices/src/CANTalon.cpp b/wpilibc/wpilibC++Devices/src/CANTalon.cpp index 01a0185a40..c49df38369 100644 --- a/wpilibc/wpilibC++Devices/src/CANTalon.cpp +++ b/wpilibc/wpilibC++Devices/src/CANTalon.cpp @@ -286,7 +286,7 @@ double CANTalon::GetP() if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } - usleep(1000); /* small yield for getting response */ + usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */ double p; status = m_impl->GetPgain(m_profile, p); if(status != CTR_OKAY) { @@ -307,7 +307,7 @@ double CANTalon::GetI() if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } - usleep(1000); /* small yield for getting response */ + usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */ double i; status = m_impl->GetIgain(m_profile, i); @@ -329,7 +329,7 @@ double CANTalon::GetD() if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } - usleep(1000); /* small yield for getting response */ + usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */ double d; status = m_impl->GetDgain(m_profile, d); @@ -351,7 +351,7 @@ double CANTalon::GetF() wpi_setErrorWithContext(status, getHALErrorMessage(status)); } - usleep(1000); /* small yield for getting response */ + usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */ double f; status = m_impl->GetFgain(m_profile, f); if(status != CTR_OKAY) { @@ -370,7 +370,7 @@ int CANTalon::GetIzone() if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } - usleep(1000); + usleep(kDelayForSolicitedSignalsUs); int iz; status = m_impl->GetIzone(m_profile, iz); @@ -865,7 +865,7 @@ uint32_t CANTalon::GetFirmwareVersion() if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } - usleep(1000); + usleep(kDelayForSolicitedSignalsUs); status = m_impl->GetParamResponseInt32(CanTalonSRX::eFirmVers,firmwareVersion); if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); @@ -888,7 +888,7 @@ int CANTalon::GetIaccum() if(status != CTR_OKAY) { wpi_setErrorWithContext(status, getHALErrorMessage(status)); } - usleep(1000); /* small yield for getting response */ + usleep(kDelayForSolicitedSignalsUs); /* small yield for getting response */ int iaccum; status = m_impl->GetParamResponseInt32(CanTalonSRX::ePidIaccum,iaccum); if(status != CTR_OKAY) { diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANTalon.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANTalon.java index a37e6e4f80..67651b94cb 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANTalon.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANTalon.java @@ -21,7 +21,6 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { PercentVbus(0), Follower(5), Voltage(4), Position(1), Speed(2), Current(3), Disabled(15); public int value; - public static ControlMode valueOf(int value) { for(ControlMode mode : values()) { if(mode.value == value) { @@ -59,6 +58,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { private CanTalonSRX m_impl; ControlMode m_controlMode; + private static double kDelayForSolicitedSignals = 0.004; int m_deviceNumber; boolean m_controlEnabled; @@ -86,6 +86,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) @@ -375,7 +385,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_P); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long pp = CanTalonJNI.new_doublep(); m_impl.GetPgain(m_profile, new SWIGTYPE_p_double(pp, true)); @@ -394,7 +404,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_I); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long ip = CanTalonJNI.new_doublep(); m_impl.GetIgain(m_profile, new SWIGTYPE_p_double(ip, true)); @@ -413,7 +423,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_D); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long dp = CanTalonJNI.new_doublep(); m_impl.GetDgain(m_profile, new SWIGTYPE_p_double(dp, true)); @@ -432,7 +442,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_F); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long fp = CanTalonJNI.new_doublep(); m_impl.GetFgain(m_profile, new SWIGTYPE_p_double(fp, true)); @@ -451,7 +461,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_IZone); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long fp = CanTalonJNI.new_intp(); m_impl.GetIzone(m_profile, new SWIGTYPE_p_int(fp, true)); @@ -478,7 +488,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.eProfileParamSlot1_CloseLoopRampRate); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long fp = CanTalonJNI.new_intp(); m_impl.GetCloseLoopRampRate(m_profile, new SWIGTYPE_p_int(fp, true)); @@ -494,7 +504,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.eFirmVers); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long fp = CanTalonJNI.new_intp(); m_impl.GetParamResponseInt32(CanTalonSRX.param_t.eFirmVers, new SWIGTYPE_p_int(fp, true)); @@ -506,7 +516,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController { m_impl.RequestParam(CanTalonSRX.param_t.ePidIaccum); // Briefly wait for new values from the Talon. - Timer.delay(0.001); + Timer.delay(kDelayForSolicitedSignals); long fp = CanTalonJNI.new_intp(); m_impl.GetParamResponseInt32(CanTalonSRX.param_t.ePidIaccum, new SWIGTYPE_p_int(fp, true));