Skip to content

Commit dfe8bc4

Browse files
committed
Use spin_some for the MPC controller to avoid race condition with tf data
1 parent 98b2304 commit dfe8bc4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/mpc_controller/mpc_controller_main.lf

+12-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ reactor mpc_controller {
4545
self->node_shared_ptr = std::shared_ptr<motion::control::mpc_controller_nodes::MpcControllerNode>(self->node);
4646
//std::cout << self->node->m_controller->get_base_config().safe_deceleration_rate() << std::endl;
4747

48-
// Spawn thread to spin node for tf stuff
49-
pthread_t spinner_thread;
50-
pthread_create(
51-
&spinner_thread,
52-
NULL,
53-
&spin_node<std::shared_ptr<motion::control::mpc_controller_nodes::MpcControllerNode>>,
54-
static_cast<void*>(new std::shared_ptr<motion::control::mpc_controller_nodes::MpcControllerNode>(self->node_shared_ptr)));
48+
// Spawn thread to spin node for tf stuff (FIXME: Causes a segfault)
49+
// pthread_t spinner_thread;
50+
// pthread_create(
51+
// &spinner_thread,
52+
// NULL,
53+
// &spin_node<std::shared_ptr<motion::control::mpc_controller_nodes::MpcControllerNode>>,
54+
// static_cast<void*>(new std::shared_ptr<motion::control::mpc_controller_nodes::MpcControllerNode>(self->node_shared_ptr)));
55+
=}
56+
57+
timer ros_spin(0, 1 msec);
58+
reaction(ros_spin) {=
59+
rclcpp::spin_some(self->node_shared_ptr);
5560
=}
5661

5762
// The order of reactions is important.

tests/src/mpc_controller_test.lf

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
target CCpp {
2-
coordination: decentralized
2+
coordination: decentralized,
3+
build-type: RelWithDebInfo
34
};
45

56
import lgsvl_interface from "../../src/lgsvl_interface/lgsvl_interface_main.lf"

0 commit comments

Comments
 (0)