Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Inlining node loop again.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed Nov 16, 2023
1 parent 863c9d3 commit 04dd2a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 2 additions & 4 deletions include/t07_robot/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ class Node : public rclcpp::Node
std::mutex _node_mtx;
std::chrono::steady_clock::time_point const _node_start;
std::unique_ptr<CanManager> _can_mgr;

static std::chrono::milliseconds constexpr IO_LOOP_RATE{1};
rclcpp::TimerBase::SharedPtr _io_loop_timer;
void io_loop();
static std::chrono::milliseconds constexpr NODE_LOOP_RATE{1};
rclcpp::TimerBase::SharedPtr _node_loop_timer;

cyphal::Publisher<uavcan::node::Heartbeat_1_0> _cyphal_heartbeat_pub;
static std::chrono::milliseconds constexpr CYPHAL_HEARTBEAT_PERIOD{1000};
Expand Down
15 changes: 7 additions & 8 deletions src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ Node::Node()
_node_hdl.onCanFrameReceived(frame);
});

_node_loop_timer = create_wall_timer(NODE_LOOP_RATE,
[this]()
{
std::lock_guard <std::mutex> lock(_node_mtx);
_node_hdl.spinSome();
});

init_cyphal_heartbeat();
init_cyphal_node_info();

_io_loop_timer = create_wall_timer(IO_LOOP_RATE, [this]() { this->io_loop(); });

init_motor_left();
init_motor_right();

Expand All @@ -86,12 +91,6 @@ Node::~Node()
* PRIVATE MEMBER FUNCTIONS
**************************************************************************************/

void Node::io_loop()
{
std::lock_guard <std::mutex> lock(_node_mtx);
_node_hdl.spinSome();
}

void Node::init_cyphal_heartbeat()
{
_cyphal_heartbeat_pub = _node_hdl.create_publisher<uavcan::node::Heartbeat_1_0>(1*1000*1000UL /* = 1 sec in usecs. */);
Expand Down

0 comments on commit 04dd2a0

Please sign in to comment.