chore(les1): Clean up work, add node template

This commit is contained in:
2025-09-11 09:38:42 +02:00
parent 976f684c04
commit a8f0eb737e
4 changed files with 79 additions and 104 deletions

View File

@@ -1,22 +1,4 @@
// Wessel T <contact@wessel.gg> (https://wessel.gg/)
//
// "Build your own tower.
// A kingdom freed from malice.
// Create a world of bounty, peace and beauty."
// ⠀⣠⣶⣶⣤⣁
// ⢰⣷⡟⠻⣏⠻⣧⣀⠐⠈⠀⡈⠠⠀⠂⠀⢁⠈⠀⠄⠀⠁⣠⣴⣤⡈
// ⠀⣿⢿⡀⠘⢦⡈⢻⣦⠐⠀⠀⠄⠀⠁⠈⠀⡀⠠⠀⣠⡿⣿⣯⣽⡇
// ⠀⢻⣿⠛⢦⣄⣹⠦⣌⣳⡀⠀⣠⠈⠀⢾⠀⠀⢀⣼⢯⠞⢡⣿⣿⠁
// ⠄⠘⣿⣷⣤⡀⠙⣆⠈⠻⣿⡄⠘⣇⠀⣾⠀⣴⠿⢲⣋⣤⣿⡿⠃⠀
// ⠀⡀⠹⣿⣦⡉⠛⠚⣆⠀⠈⠻⣆⢻⢠⣇⡾⠃⢠⣟⣠⣾⡞⠃⠀
// ⠂⡀⠄⠹⣿⣏⠛⠒⠾⠷⣄⠀⠙⣞⣿⠋⣀⣴⣋⣽⡿⠋
// ⠂⠠⠀⠀⣨⣿⢿⣶⣒⠲⢮⣿⣶⣼⣧⣾⣭⣿⠟⠉
// ⠐⠀⠁⣰⣿⠓⠒⣛⣻⠟⠛⣩⣿⣯⠙⡯⣿⡆
// ⠐⠀⠄⠸⣿⡟⢉⡽⢛⣿⡿⠉⠀⢸⣧⡷⣾⡇
// ⠀⢂⠀⠄⠹⢿⣿⣴⣯⠏⠀⠀⠀⣼⢸⣽⣷⠇
// ⠠⠀⠂⢀⠀⢀⠈⠉⠀⠀⠀⠂⡀⠹⠿⠛⠁⠀⠀
/* les1.cpp
/* les1/clock.cpp
* Assignment done in the first lesson explaining
* the basics of ROS2
*
@@ -26,15 +8,13 @@
* [07-09-2025] Wessel T:
* - Rename {les1.cpp -> les1/clock.cpp}
* - Update node names to be in line with other files
* [11-09-2025] Wessel T: Remove unused imports
*/
#include <cstdlib>
#include "rclcpp/rclcpp.hpp"
#include <rclcpp/clock.hpp>
#include <rclcpp/time.hpp>
class NodeLes1Clock : public rclcpp::Node
{
class NodeLes1Clock : public rclcpp::Node {
public:
NodeLes1Clock()
: Node("node_les1_clock")

View File

@@ -1,22 +1,4 @@
// Wessel T <contact@wessel.gg> (https://wessel.gg/)
//
// "Build your own tower.
// A kingdom freed from malice.
// Create a world of bounty, peace and beauty."
// ⠀⣠⣶⣶⣤⣁
// ⢰⣷⡟⠻⣏⠻⣧⣀⠐⠈⠀⡈⠠⠀⠂⠀⢁⠈⠀⠄⠀⠁⣠⣴⣤⡈
// ⠀⣿⢿⡀⠘⢦⡈⢻⣦⠐⠀⠀⠄⠀⠁⠈⠀⡀⠠⠀⣠⡿⣿⣯⣽⡇
// ⠀⢻⣿⠛⢦⣄⣹⠦⣌⣳⡀⠀⣠⠈⠀⢾⠀⠀⢀⣼⢯⠞⢡⣿⣿⠁
// ⠄⠘⣿⣷⣤⡀⠙⣆⠈⠻⣿⡄⠘⣇⠀⣾⠀⣴⠿⢲⣋⣤⣿⡿⠃⠀
// ⠀⡀⠹⣿⣦⡉⠛⠚⣆⠀⠈⠻⣆⢻⢠⣇⡾⠃⢠⣟⣠⣾⡞⠃⠀
// ⠂⡀⠄⠹⣿⣏⠛⠒⠾⠷⣄⠀⠙⣞⣿⠋⣀⣴⣋⣽⡿⠋
// ⠂⠠⠀⠀⣨⣿⢿⣶⣒⠲⢮⣿⣶⣼⣧⣾⣭⣿⠟⠉
// ⠐⠀⠁⣰⣿⠓⠒⣛⣻⠟⠛⣩⣿⣯⠙⡯⣿⡆
// ⠐⠀⠄⠸⣿⡟⢉⡽⢛⣿⡿⠉⠀⢸⣧⡷⣾⡇
// ⠀⢂⠀⠄⠹⢿⣿⣴⣯⠏⠀⠀⠀⣼⢸⣽⣷⠇
// ⠠⠀⠂⢀⠀⢀⠈⠉⠀⠀⠀⠂⡀⠹⠿⠛⠁⠀⠀
/* les1.cpp
/* les1/publisher.cpp
* Assignment done in the first lesson explaining
* the basics of ROS2
*
@@ -24,23 +6,21 @@
* Changelog:
* [04-09-2025] Wessel T:
* - Implement template
* [11-09-2025] Wessel T: Remove unused imports
*/
#include <cstdlib>
#include "rclcpp/rclcpp.hpp"
#include <rclcpp/clock.hpp>
#include <rclcpp/time.hpp>
#include "geometry_msgs/msg/point.hpp" // Point for x, y, z coordinates
#include "les_interface/msg/hardware_status.hpp" // Custom HW status message
class NodeLes1Publisher : public rclcpp::Node {
public:
NodeLes1Publisher()
NodeLes1Publisher()
: Node("node_les1_publisher")
{
{
publisher_location_ =
this->create_publisher<geometry_msgs::msg::Point>("location", 10);
@@ -56,10 +36,10 @@ NodeLes1Publisher()
std::chrono::seconds(2),
std::bind(&NodeLes1Publisher::timer_hw_status_function, this)
);
}
}
void timer_location_function() {
void timer_location_function() {
geometry_msgs::msg::Point coordinate;
coordinate.x = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
coordinate.y = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
@@ -67,10 +47,11 @@ void timer_location_function() {
publisher_location_->publish(coordinate);
RCLCPP_INFO(this->get_logger(),
"Published x=%.2f, y=%.2f, z=%.2f", coordinate.x, coordinate.y, coordinate.z);
}
"Published x=%.2f, y=%.2f, z=%.2f", coordinate.x, coordinate.y, coordinate.z
);
}
void timer_hw_status_function() {
void timer_hw_status_function() {
les_interface::msg::HardwareStatus hw_msg;
hw_msg.version = 1;
hw_msg.temperature = static_cast<double>(std::rand()) / RAND_MAX * 80.0;
@@ -82,8 +63,9 @@ void timer_hw_status_function() {
"Published HW status: version=%ld, temp=%.2f, motors_ready=%s, msg=%s",
hw_msg.version, hw_msg.temperature,
hw_msg.are_motors_ready ? "true" : "false",
hw_msg.debug_message.c_str());
}
hw_msg.debug_message.c_str()
);
}
private:
rclcpp::Publisher<geometry_msgs::msg::Point>::SharedPtr publisher_location_;

View File

@@ -1,22 +1,4 @@
// Wessel T <contact@wessel.gg> (https://wessel.gg/)
//
// "Build your own tower.
// A kingdom freed from malice.
// Create a world of bounty, peace and beauty."
// ⠀⣠⣶⣶⣤⣁
// ⢰⣷⡟⠻⣏⠻⣧⣀⠐⠈⠀⡈⠠⠀⠂⠀⢁⠈⠀⠄⠀⠁⣠⣴⣤⡈
// ⠀⣿⢿⡀⠘⢦⡈⢻⣦⠐⠀⠀⠄⠀⠁⠈⠀⡀⠠⠀⣠⡿⣿⣯⣽⡇
// ⠀⢻⣿⠛⢦⣄⣹⠦⣌⣳⡀⠀⣠⠈⠀⢾⠀⠀⢀⣼⢯⠞⢡⣿⣿⠁
// ⠄⠘⣿⣷⣤⡀⠙⣆⠈⠻⣿⡄⠘⣇⠀⣾⠀⣴⠿⢲⣋⣤⣿⡿⠃⠀
// ⠀⡀⠹⣿⣦⡉⠛⠚⣆⠀⠈⠻⣆⢻⢠⣇⡾⠃⢠⣟⣠⣾⡞⠃⠀
// ⠂⡀⠄⠹⣿⣏⠛⠒⠾⠷⣄⠀⠙⣞⣿⠋⣀⣴⣋⣽⡿⠋
// ⠂⠠⠀⠀⣨⣿⢿⣶⣒⠲⢮⣿⣶⣼⣧⣾⣭⣿⠟⠉
// ⠐⠀⠁⣰⣿⠓⠒⣛⣻⠟⠛⣩⣿⣯⠙⡯⣿⡆
// ⠐⠀⠄⠸⣿⡟⢉⡽⢛⣿⡿⠉⠀⢸⣧⡷⣾⡇
// ⠀⢂⠀⠄⠹⢿⣿⣴⣯⠏⠀⠀⠀⣼⢸⣽⣷⠇
// ⠠⠀⠂⢀⠀⢀⠈⠉⠀⠀⠀⠂⡀⠹⠿⠛⠁⠀⠀
/* les1.cpp
/* les1/subscriber.cpp
* Assignment done in the first lesson explaining
* the basics of ROS2
*
@@ -38,7 +20,7 @@ using namespace std::placeholders;
class NodeLes1Subscriber : public rclcpp::Node {
public:
NodeLes1Subscriber()
NodeLes1Subscriber()
: Node("node_les1_subscriber")
{
subscriber_location_ =
@@ -52,21 +34,21 @@ NodeLes1Subscriber()
"hardware_status", 10,
std::bind(&NodeLes1Subscriber::sub_callback_hw_status, this, _1)
);
}
}
void sub_callback_location(const geometry_msgs::msg::Point::SharedPtr msg) {
void sub_callback_location(const geometry_msgs::msg::Point::SharedPtr msg) {
RCLCPP_INFO(this->get_logger(),
"Received: x=%.2f, y=%.2f, z=%.2f", msg->x, msg->y, msg->z
);
}
}
void sub_callback_hw_status(const les_interface::msg::HardwareStatus::SharedPtr msg) {
void sub_callback_hw_status(const les_interface::msg::HardwareStatus::SharedPtr msg) {
RCLCPP_INFO(this->get_logger(),
"Received HW status: version=%ld, temp=%.2f, motors_ready=%s, msg=%s",
msg->version, msg->temperature,
msg->are_motors_ready ? "true" : "false",
msg->debug_message.c_str());
}
}
private:
rclcpp::Subscription<geometry_msgs::msg::Point>::SharedPtr subscriber_location_;

View File

@@ -0,0 +1,31 @@
/* node_template.cpp
* Basic node template for ROS2
*
* Reviewed by: <x>
* Changelog:
* [04-09-2025] Wessel T: Implement template
*/
#include <cstdlib>
#include "rclcpp/rclcpp.hpp"
class NodeTemplate : public rclcpp::Node {
public:
NodeTemplate()
: Node("node_template")
{
}
private:
};
int main(int argc,char *argv[]) {
rclcpp::init(argc,argv);
auto node = std::make_shared<NodeTemplate>();
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}