Added Get/clear routine for IntegralAccumulator
Added missing status check in GetFirmwareVersion().  I don't expect this to affect anything.

JAVA
Renamed getRampRate to getCloseLoopRampRate in java to match the set routines in java, and match all routines in cpp.
Added GetFirmwareVersion to java to match cpp.
Added Get/clear routine for IntegralAccumulator
Retested all three routines in java.

Change-Id: I4ce9d9c87a379b9d4a76aae226e2072876218688
This commit is contained in:
Omar Zrien
2014-12-06 21:59:44 -05:00
committed by James Kuszmaul
parent e3ac0b628c
commit 19a7243bfc
9 changed files with 102 additions and 4 deletions

View File

@@ -211,6 +211,8 @@ public:
eResetFlags=88,
eFirmVers=89,
eSettingsChanged=90,
eQuadFilterEn=91,
ePidIaccum=93,
}param_t;
/*---------------------setters and getters that use the solicated param request/response-------------*//**
* Send a one shot frame to set an arbitrary signal.

View File

@@ -100,6 +100,8 @@ public:
void SetCloseLoopRampRate(double rampRate);
void SelectProfileSlot(int slotIdx);
double GetIzone();
int GetIaccum();
void ClearIaccum();
private:
// Values for various modes as is sent in the CAN packets for the Talon.
enum TalonControlMode {

View File

@@ -212,6 +212,8 @@ public:
eResetFlags=88,
eFirmVers=89,
eSettingsChanged=90,
eQuadFilterEn=91,
ePidIaccum=93,
}param_t;
/*---------------------setters and getters that use the solicated param request/response-------------*//**
* Send a one shot frame to set an arbitrary signal.

View File

@@ -815,9 +815,12 @@ void CANTalon::SetCloseLoopRampRate(double rampRate)
uint32_t CANTalon::GetFirmwareVersion()
{
int firmwareVersion;
m_impl->RequestParam(CanTalonSRX::eFirmVers);
CTR_Code status = m_impl->RequestParam(CanTalonSRX::eFirmVers);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000);
CTR_Code status = m_impl->GetParamResponseInt32(CanTalonSRX::eFirmVers,firmwareVersion);
status = m_impl->GetParamResponseInt32(CanTalonSRX::eFirmVers,firmwareVersion);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
@@ -830,6 +833,33 @@ uint32_t CANTalon::GetFirmwareVersion()
return firmwareVersion;
}
/**
* @return The accumulator for I gain.
*/
int CANTalon::GetIaccum()
{
CTR_Code status = m_impl->RequestParam(CanTalonSRX::ePidIaccum);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
usleep(1000); /* small yield for getting response */
int iaccum;
status = m_impl->GetParamResponseInt32(CanTalonSRX::ePidIaccum,iaccum);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
return iaccum;
}
/**
* Clear the accumulator for I gain.
*/
void CANTalon::ClearIaccum()
{
CTR_Code status = m_impl->SetParam(CanTalonSRX::ePidIaccum, 0);
if(status != CTR_OKAY) {
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
/**
* TODO documentation (see CANJaguar.cpp)

View File

@@ -438,7 +438,7 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
return CanTalonJNI.intp_value(fp);
}
public double getRampRate() {
public double getCloseLoopRampRate() {
// if(!(m_controlMode.equals(ControlMode.Position) || m_controlMode.equals(ControlMode.Speed))) {
// throw new IllegalStateException("PID mode only applies in Position and Speed modes.");
// }
@@ -456,8 +456,41 @@ public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
m_impl.GetCloseLoopRampRate(m_profile, new SWIGTYPE_p_int(fp, true));
return CanTalonJNI.intp_value(fp);
}
/**
* @return The version of the firmware running on the Talon
*/
public long GetFirmwareVersion() {
// Update the information that we have.
m_impl.RequestParam(CanTalonSRX.param_t.eFirmVers);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
long fp = CanTalonJNI.new_intp();
m_impl.GetParamResponseInt32(CanTalonSRX.param_t.eFirmVers, new SWIGTYPE_p_int(fp, true));
return CanTalonJNI.intp_value(fp);
}
public long GetIaccum() {
// Update the information that we have.
m_impl.RequestParam(CanTalonSRX.param_t.ePidIaccum);
// Briefly wait for new values from the Talon.
Timer.delay(0.001);
long fp = CanTalonJNI.new_intp();
m_impl.GetParamResponseInt32(CanTalonSRX.param_t.ePidIaccum, new SWIGTYPE_p_int(fp, true));
return CanTalonJNI.intp_value(fp);
}
/**
* Clear the accumulator for I gain.
*/
public void ClearIaccum()
{
SWIGTYPE_p_CTR_Code status = m_impl.SetParam(CanTalonSRX.param_t.ePidIaccum, 0);
}
/**
* Set the proportional value of the currently selected profile.
*

View File

@@ -435,6 +435,8 @@ public class CanTalonSRX extends CtreCanNode {
public final static CanTalonSRX.param_t eResetFlags = new CanTalonSRX.param_t("eResetFlags", CanTalonJNI.CanTalonSRX_eResetFlags_get());
public final static CanTalonSRX.param_t eFirmVers = new CanTalonSRX.param_t("eFirmVers", CanTalonJNI.CanTalonSRX_eFirmVers_get());
public final static CanTalonSRX.param_t eSettingsChanged = new CanTalonSRX.param_t("eSettingsChanged", CanTalonJNI.CanTalonSRX_eSettingsChanged_get());
public final static CanTalonSRX.param_t eQuadFilterEn = new CanTalonSRX.param_t("eQuadFilterEn", CanTalonJNI.CanTalonSRX_eQuadFilterEn_get());
public final static CanTalonSRX.param_t ePidIaccum = new CanTalonSRX.param_t("ePidIaccum", CanTalonJNI.CanTalonSRX_ePidIaccum_get());
public final int swigValue() {
return swigValue;
@@ -470,7 +472,7 @@ public class CanTalonSRX extends CtreCanNode {
swigNext = this.swigValue+1;
}
private static param_t[] swigValues = { eProfileParamSlot0_P, eProfileParamSlot0_I, eProfileParamSlot0_D, eProfileParamSlot0_F, eProfileParamSlot0_IZone, eProfileParamSlot0_CloseLoopRampRate, eProfileParamSlot1_P, eProfileParamSlot1_I, eProfileParamSlot1_D, eProfileParamSlot1_F, eProfileParamSlot1_IZone, eProfileParamSlot1_CloseLoopRampRate, eProfileParamSoftLimitForThreshold, eProfileParamSoftLimitRevThreshold, eProfileParamSoftLimitForEnable, eProfileParamSoftLimitRevEnable, eOnBoot_BrakeMode, eOnBoot_LimitSwitch_Forward_NormallyClosed, eOnBoot_LimitSwitch_Reverse_NormallyClosed, eOnBoot_LimitSwitch_Forward_Disable, eOnBoot_LimitSwitch_Reverse_Disable, eFault_OverTemp, eFault_UnderVoltage, eFault_ForLim, eFault_RevLim, eFault_HardwareFailure, eFault_ForSoftLim, eFault_RevSoftLim, eStckyFault_OverTemp, eStckyFault_UnderVoltage, eStckyFault_ForLim, eStckyFault_RevLim, eStckyFault_ForSoftLim, eStckyFault_RevSoftLim, eAppliedThrottle, eCloseLoopErr, eFeedbackDeviceSelect, eRevMotDuringCloseLoopEn, eModeSelect, eProfileSlotSelect, eRampThrottle, eRevFeedbackSensor, eLimitSwitchEn, eLimitSwitchClosedFor, eLimitSwitchClosedRev, eSensorPosition, eSensorVelocity, eCurrent, eBrakeIsEnabled, eEncPosition, eEncVel, eEncIndexRiseEvents, eQuadApin, eQuadBpin, eQuadIdxpin, eAnalogInWithOv, eAnalogInVel, eTemp, eBatteryV, eResetCount, eResetFlags, eFirmVers, eSettingsChanged };
private static param_t[] swigValues = { eProfileParamSlot0_P, eProfileParamSlot0_I, eProfileParamSlot0_D, eProfileParamSlot0_F, eProfileParamSlot0_IZone, eProfileParamSlot0_CloseLoopRampRate, eProfileParamSlot1_P, eProfileParamSlot1_I, eProfileParamSlot1_D, eProfileParamSlot1_F, eProfileParamSlot1_IZone, eProfileParamSlot1_CloseLoopRampRate, eProfileParamSoftLimitForThreshold, eProfileParamSoftLimitRevThreshold, eProfileParamSoftLimitForEnable, eProfileParamSoftLimitRevEnable, eOnBoot_BrakeMode, eOnBoot_LimitSwitch_Forward_NormallyClosed, eOnBoot_LimitSwitch_Reverse_NormallyClosed, eOnBoot_LimitSwitch_Forward_Disable, eOnBoot_LimitSwitch_Reverse_Disable, eFault_OverTemp, eFault_UnderVoltage, eFault_ForLim, eFault_RevLim, eFault_HardwareFailure, eFault_ForSoftLim, eFault_RevSoftLim, eStckyFault_OverTemp, eStckyFault_UnderVoltage, eStckyFault_ForLim, eStckyFault_RevLim, eStckyFault_ForSoftLim, eStckyFault_RevSoftLim, eAppliedThrottle, eCloseLoopErr, eFeedbackDeviceSelect, eRevMotDuringCloseLoopEn, eModeSelect, eProfileSlotSelect, eRampThrottle, eRevFeedbackSensor, eLimitSwitchEn, eLimitSwitchClosedFor, eLimitSwitchClosedRev, eSensorPosition, eSensorVelocity, eCurrent, eBrakeIsEnabled, eEncPosition, eEncVel, eEncIndexRiseEvents, eQuadApin, eQuadBpin, eQuadIdxpin, eAnalogInWithOv, eAnalogInVel, eTemp, eBatteryV, eResetCount, eResetFlags, eFirmVers, eSettingsChanged, eQuadFilterEn, ePidIaccum };
private static int swigNext = 0;
private final int swigValue;
private final String swigName;

View File

@@ -143,6 +143,8 @@ public class CanTalonJNI {
public final static native int CanTalonSRX_eResetFlags_get();
public final static native int CanTalonSRX_eFirmVers_get();
public final static native int CanTalonSRX_eSettingsChanged_get();
public final static native int CanTalonSRX_eQuadFilterEn_get();
public final static native int CanTalonSRX_ePidIaccum_get();
public final static native long CanTalonSRX_SetParam(long jarg1, CanTalonSRX jarg1_, int jarg2, double jarg3);
public final static native long CanTalonSRX_RequestParam(long jarg1, CanTalonSRX jarg1_, int jarg2);
public final static native long CanTalonSRX_GetParamResponse(long jarg1, CanTalonSRX jarg1_, int jarg2, long jarg3);

View File

@@ -2049,6 +2049,30 @@ SWIGEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CanTalonJNI_CanTalonSRX_1
}
SWIGEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CanTalonJNI_CanTalonSRX_1eQuadFilterEn_1get(JNIEnv *jenv, jclass jcls) {
jint jresult = 0 ;
CanTalonSRX::_param_t result;
(void)jenv;
(void)jcls;
result = (CanTalonSRX::_param_t)CanTalonSRX::eQuadFilterEn;
jresult = (jint)result;
return jresult;
}
SWIGEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CanTalonJNI_CanTalonSRX_1ePidIaccum_1get(JNIEnv *jenv, jclass jcls) {
jint jresult = 0 ;
CanTalonSRX::_param_t result;
(void)jenv;
(void)jcls;
result = (CanTalonSRX::_param_t)CanTalonSRX::ePidIaccum;
jresult = (jint)result;
return jresult;
}
SWIGEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_CanTalonJNI_CanTalonSRX_1SetParam(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2, jdouble jarg3) {
jlong jresult = 0 ;
CanTalonSRX *arg1 = (CanTalonSRX *) 0 ;

View File

@@ -7,3 +7,4 @@ bindings are checked into git, so that it should work until someone goes and upd
In order for this to work, I had to change the CanTalonSRX constructor to take a int deviceNumber instead of a uint8_t.
Also, in all the SWIGTYPE* files, you must change protected methods to public functions.
Because the SWIGTYPE* files don't generally change, you can jsut do a git checkout -- SWIGTYPE* in wpilibJavaDevices/....../wpilibj/