Skip to content

Commit 8a5dcf9

Browse files
Merge pull request #78 from nasa-jpl/davkim-arg-check-before-reset
Changed orders for cmds to not reset when rejecting cmd
2 parents 76165d8 + a15d01e commit 8a5dcf9

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/jsd/actuator_fsm_helpers.cc

+32-32
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ bool fastcat::Actuator::CheckStateMachineGainSchedulingCmds()
9090

9191
bool fastcat::Actuator::HandleNewCSPCmd(DeviceCmd& cmd)
9292
{
93-
// Check that the command can be honored within FSM state
94-
if (!CheckStateMachineMotionCmds()) {
93+
// Validate the command arguments
94+
if (PosExceedsCmdLimits(cmd.actuator_csp_cmd.target_position +
95+
cmd.actuator_csp_cmd.position_offset) ||
96+
VelExceedsCmdLimits(cmd.actuator_csp_cmd.velocity_offset)) {
9597
TransitionToState(ACTUATOR_SMS_FAULTED);
9698
ERROR("Act %s: %s", name_.c_str(), "Failing CSP Command");
9799
return false;
98100
}
99101

100-
// Validate the command arguments
101-
if (PosExceedsCmdLimits(cmd.actuator_csp_cmd.target_position +
102-
cmd.actuator_csp_cmd.position_offset) ||
103-
VelExceedsCmdLimits(cmd.actuator_csp_cmd.velocity_offset)) {
102+
// Check that the command can be honored within FSM state
103+
if (!CheckStateMachineMotionCmds()) {
104104
TransitionToState(ACTUATOR_SMS_FAULTED);
105105
ERROR("Act %s: %s", name_.c_str(), "Failing CSP Command");
106106
return false;
@@ -121,16 +121,16 @@ bool fastcat::Actuator::HandleNewCSPCmd(DeviceCmd& cmd)
121121

122122
bool fastcat::Actuator::HandleNewCSVCmd(DeviceCmd& cmd)
123123
{
124-
// Check that the command can be honored within FSM state
125-
if (!CheckStateMachineMotionCmds()) {
124+
// Validate command arguments
125+
if (VelExceedsCmdLimits(cmd.actuator_csv_cmd.target_velocity +
126+
cmd.actuator_csv_cmd.velocity_offset)) {
126127
TransitionToState(ACTUATOR_SMS_FAULTED);
127128
ERROR("Act %s: %s", name_.c_str(), "Failing CSV Command");
128129
return false;
129130
}
130131

131-
// Validate command arguments
132-
if (VelExceedsCmdLimits(cmd.actuator_csv_cmd.target_velocity +
133-
cmd.actuator_csv_cmd.velocity_offset)) {
132+
// Check that the command can be honored within FSM state
133+
if (!CheckStateMachineMotionCmds()) {
134134
TransitionToState(ACTUATOR_SMS_FAULTED);
135135
ERROR("Act %s: %s", name_.c_str(), "Failing CSV Command");
136136
return false;
@@ -150,16 +150,16 @@ bool fastcat::Actuator::HandleNewCSVCmd(DeviceCmd& cmd)
150150

151151
bool fastcat::Actuator::HandleNewCSTCmd(DeviceCmd& cmd)
152152
{
153-
// Check that the command can be honored within FSM state
154-
if (!CheckStateMachineMotionCmds()) {
153+
// Validate command arguments
154+
if (CurrentExceedsCmdLimits(cmd.actuator_cst_cmd.target_torque_amps +
155+
cmd.actuator_cst_cmd.torque_offset_amps)) {
155156
TransitionToState(ACTUATOR_SMS_FAULTED);
156157
ERROR("Act %s: %s", name_.c_str(), "Failing CST Command");
157158
return false;
158159
}
159160

160-
// Validate command arguments
161-
if (CurrentExceedsCmdLimits(cmd.actuator_cst_cmd.target_torque_amps +
162-
cmd.actuator_cst_cmd.torque_offset_amps)) {
161+
// Check that the command can be honored within FSM state
162+
if (!CheckStateMachineMotionCmds()) {
163163
TransitionToState(ACTUATOR_SMS_FAULTED);
164164
ERROR("Act %s: %s", name_.c_str(), "Failing CST Command");
165165
return false;
@@ -178,13 +178,6 @@ bool fastcat::Actuator::HandleNewCSTCmd(DeviceCmd& cmd)
178178

179179
bool fastcat::Actuator::HandleNewProfPosCmd(DeviceCmd& cmd)
180180
{
181-
// Check that the command can be honored within FSM state
182-
if (!CheckStateMachineMotionCmds()) {
183-
TransitionToState(ACTUATOR_SMS_FAULTED);
184-
ERROR("Act %s: %s", name_.c_str(), "Failing Prof Pos Command");
185-
return false;
186-
}
187-
188181
double target_position = 0;
189182
if (cmd.actuator_prof_pos_cmd.relative) {
190183
target_position = cmd.actuator_prof_pos_cmd.target_position +
@@ -203,6 +196,13 @@ bool fastcat::Actuator::HandleNewProfPosCmd(DeviceCmd& cmd)
203196
return false;
204197
}
205198

199+
// Check that the command can be honored within FSM state
200+
if (!CheckStateMachineMotionCmds()) {
201+
TransitionToState(ACTUATOR_SMS_FAULTED);
202+
ERROR("Act %s: %s", name_.c_str(), "Failing Prof Pos Command");
203+
return false;
204+
}
205+
206206
// Only transition to disengaging if its needed
207207
if(state_->actuator_state.servo_enabled){
208208
// Bypassing wait since brakes are disengaged
@@ -227,15 +227,15 @@ bool fastcat::Actuator::HandleNewProfPosCmd(DeviceCmd& cmd)
227227

228228
bool fastcat::Actuator::HandleNewProfVelCmd(DeviceCmd& cmd)
229229
{
230-
// Check that the command can be honored within FSM state
231-
if (!CheckStateMachineMotionCmds()) {
230+
if (VelExceedsCmdLimits(cmd.actuator_prof_vel_cmd.target_velocity) ||
231+
AccExceedsCmdLimits(cmd.actuator_prof_vel_cmd.profile_accel)) {
232232
TransitionToState(ACTUATOR_SMS_FAULTED);
233233
ERROR("Act %s: %s", name_.c_str(), "Failing Prof Vel Command");
234234
return false;
235235
}
236236

237-
if (VelExceedsCmdLimits(cmd.actuator_prof_vel_cmd.target_velocity) ||
238-
AccExceedsCmdLimits(cmd.actuator_prof_vel_cmd.profile_accel)) {
237+
// Check that the command can be honored within FSM state
238+
if (!CheckStateMachineMotionCmds()) {
239239
TransitionToState(ACTUATOR_SMS_FAULTED);
240240
ERROR("Act %s: %s", name_.c_str(), "Failing Prof Vel Command");
241241
return false;
@@ -265,15 +265,15 @@ bool fastcat::Actuator::HandleNewProfVelCmd(DeviceCmd& cmd)
265265

266266
bool fastcat::Actuator::HandleNewProfTorqueCmd(DeviceCmd& cmd)
267267
{
268-
// Check that the command can be honored within FSM state
269-
if (!CheckStateMachineMotionCmds()) {
268+
if (CurrentExceedsCmdLimits(
269+
cmd.actuator_prof_torque_cmd.target_torque_amps)) {
270270
TransitionToState(ACTUATOR_SMS_FAULTED);
271271
ERROR("Act %s: %s", name_.c_str(), "Failing Prof Torque Command");
272272
return false;
273273
}
274-
275-
if (CurrentExceedsCmdLimits(
276-
cmd.actuator_prof_torque_cmd.target_torque_amps)) {
274+
275+
// Check that the command can be honored within FSM state
276+
if (!CheckStateMachineMotionCmds()) {
277277
TransitionToState(ACTUATOR_SMS_FAULTED);
278278
ERROR("Act %s: %s", name_.c_str(), "Failing Prof Torque Command");
279279
return false;

0 commit comments

Comments
 (0)