Skip to content

Commit b3338e1

Browse files
lblommesteynalyashour
authored andcommitted
feat: add synthetic actuation feedback node
1 parent 6007576 commit b3338e1

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,33 @@ add_executable(control_node
2121
src/control_node.cpp
2222
src/ackermann_controller.cpp
2323
)
24+
add_executable(synthetic_actuation_feedback_node
25+
src/synthetic_actuation_feedback_node.cpp
26+
)
2427
target_include_directories(control_node PUBLIC
2528
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
2629
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
2730
)
31+
target_include_directories(synthetic_actuation_feedback_node PUBLIC
32+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
33+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
34+
)
2835
ament_target_dependencies(
2936
control_node
3037
"rclcpp"
3138
"std_msgs"
3239
"geometry_msgs"
3340
"ap1_msgs"
3441
)
42+
ament_target_dependencies(
43+
synthetic_actuation_feedback_node
44+
"rclcpp"
45+
"ap1_msgs"
46+
)
3547

3648
install(TARGETS
3749
control_node
50+
synthetic_actuation_feedback_node
3851
DESTINATION lib/${PROJECT_NAME}
3952
)
4053

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <chrono>
2+
3+
#include "rclcpp/rclcpp.hpp"
4+
5+
#include "ap1_msgs/msg/float_stamped.hpp"
6+
7+
using ap1_msgs::msg::FloatStamped;
8+
using namespace std::chrono_literals;
9+
10+
class SyntheticActuationFeedbackNode : public rclcpp::Node
11+
{
12+
public:
13+
SyntheticActuationFeedbackNode()
14+
: Node("synthetic_actuation_feedback")
15+
{
16+
speed_mps_ = this->declare_parameter<double>("speed_mps", 1.0);
17+
turn_angle_rad_ =
18+
this->declare_parameter<double>("turn_angle_rad", 0.0);
19+
publish_rate_hz_ =
20+
this->declare_parameter<double>("publish_rate_hz", 20.0);
21+
22+
if (publish_rate_hz_ <= 0.0)
23+
{
24+
RCLCPP_WARN(
25+
this->get_logger(),
26+
"publish_rate_hz must be > 0; using 20.0 Hz");
27+
publish_rate_hz_ = 20.0;
28+
}
29+
30+
speed_pub_ = this->create_publisher<FloatStamped>(
31+
"/ap1/actuation/speed",
32+
10);
33+
turn_angle_pub_ = this->create_publisher<FloatStamped>(
34+
"/ap1/actuation/turn_angle",
35+
10);
36+
37+
timer_ = this->create_wall_timer(
38+
std::chrono::duration<double>(1.0 / publish_rate_hz_),
39+
std::bind(
40+
&SyntheticActuationFeedbackNode::publish_feedback,
41+
this));
42+
43+
RCLCPP_INFO(
44+
this->get_logger(),
45+
"Synthetic actuation feedback ready. speed: %.2f m/s, "
46+
"turn_angle: %.2f rad, rate: %.2f Hz",
47+
speed_mps_,
48+
turn_angle_rad_,
49+
publish_rate_hz_);
50+
}
51+
52+
private:
53+
void publish_feedback()
54+
{
55+
const auto stamp = this->now();
56+
57+
FloatStamped speed_msg;
58+
speed_msg.header.stamp = stamp;
59+
speed_msg.value = static_cast<float>(speed_mps_);
60+
speed_pub_->publish(speed_msg);
61+
62+
FloatStamped turn_msg;
63+
turn_msg.header.stamp = stamp;
64+
turn_msg.value = static_cast<float>(turn_angle_rad_);
65+
turn_angle_pub_->publish(turn_msg);
66+
}
67+
68+
double speed_mps_;
69+
double turn_angle_rad_;
70+
double publish_rate_hz_;
71+
rclcpp::TimerBase::SharedPtr timer_;
72+
rclcpp::Publisher<FloatStamped>::SharedPtr speed_pub_;
73+
rclcpp::Publisher<FloatStamped>::SharedPtr turn_angle_pub_;
74+
};
75+
76+
int main(int argc, char** argv)
77+
{
78+
rclcpp::init(argc, argv);
79+
auto node = std::make_shared<SyntheticActuationFeedbackNode>();
80+
rclcpp::spin(node);
81+
rclcpp::shutdown();
82+
return 0;
83+
}

0 commit comments

Comments
 (0)