Skip to content

Commit ffc27c3

Browse files
committed
Update velocity guards in FSM.
Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
1 parent 10e4824 commit ffc27c3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

app/b3rb/src/fsm.c

+17
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct status_input {
9595
bool input_source_ethernet;
9696
bool input_source_radio_control;
9797
bool topic_timeout;
98+
bool cmd_vel_timeout;
9899
bool topic_status_loss;
99100

100101
// derived booleans
@@ -126,6 +127,8 @@ struct context {
126127
struct k_thread thread_data;
127128
int64_t now_ticks;
128129
int64_t input_last_ticks;
130+
int64_t cmd_vel_last_ticks;
131+
const int64_t cmd_vel_loss_ticks;
129132
const int64_t input_loss_ticks;
130133
int64_t topic_last_ticks;
131134
const int64_t topic_loss_ticks;
@@ -167,6 +170,8 @@ static struct context g_ctx = {
167170
.now_ticks = 0,
168171
.input_last_ticks = 0,
169172
.topic_last_ticks = 0,
173+
.cmd_vel_last_ticks = 0,
174+
.cmd_vel_loss_ticks = 1.0 * CONFIG_SYS_CLOCK_TICKS_PER_SEC,
170175
.input_loss_ticks = 1.0 * CONFIG_SYS_CLOCK_TICKS_PER_SEC,
171176
.topic_loss_ticks = 1.0 * CONFIG_SYS_CLOCK_TICKS_PER_SEC,
172177
};
@@ -244,6 +249,8 @@ static void fsm_compute_input(struct status_input *input, struct context *ctx)
244249
input->topic_source_input =
245250
ctx->status.topic_source == synapse_pb_Status_TopicSource_TOPIC_SOURCE_INPUT;
246251
input->input_timeout = (ctx->now_ticks - ctx->input_last_ticks) > ctx->input_loss_ticks;
252+
input->cmd_vel_timeout =
253+
(ctx->now_ticks - ctx->cmd_vel_last_ticks) > ctx->cmd_vel_loss_ticks;
247254
input->input_status_loss =
248255
ctx->status.input_status == synapse_pb_Status_LinkStatus_STATUS_LOSS;
249256
input->input_source_ethernet =
@@ -330,6 +337,15 @@ static void fsm_update(synapse_pb_Status *status, const struct status_input *inp
330337
synapse_pb_Status_Mode_MODE_VELOCITY, // post
331338
status->status_message, sizeof(status->status_message), // status
332339
&status->request_seq, &status->request_rejected, // request
340+
1, input->cmd_vel_timeout, "cmd_vel not received"); // guards
341+
342+
transition(&status->mode, // state
343+
input->cmd_vel_timeout, // request
344+
"actuator fallback, cmd_vel not received", // label
345+
synapse_pb_Status_Mode_MODE_VELOCITY, // pre
346+
synapse_pb_Status_Mode_MODE_ACTUATORS, // post
347+
status->status_message, sizeof(status->status_message), // status
348+
&status->request_seq, &status->request_rejected, // request
333349
0); // guards
334350

335351
transition(&status->mode, // state
@@ -480,6 +496,7 @@ static void b3rb_fsm_run(void *p0, void *p1, void *p2)
480496

481497
if (in->update_cmd_vel_ethernet) {
482498
zros_sub_update(&ctx->sub_cmd_vel_ethernet);
499+
ctx->cmd_vel_last_ticks = ctx->now_ticks;
483500
}
484501

485502
// update input from correct source

0 commit comments

Comments
 (0)