chore(les1): Clean up work, add node template
This commit is contained in:
@@ -1,22 +1,4 @@
|
|||||||
// Wessel T <contact@wessel.gg> (https://wessel.gg/)
|
/* les1/clock.cpp
|
||||||
//
|
|
||||||
// "Build your own tower.
|
|
||||||
// A kingdom freed from malice.
|
|
||||||
// Create a world of bounty, peace and beauty."
|
|
||||||
// ⠀⣠⣶⣶⣤⣁
|
|
||||||
// ⢰⣷⡟⠻⣏⠻⣧⣀⠐⠈⠀⡈⠠⠀⠂⠀⢁⠈⠀⠄⠀⠁⣠⣴⣤⡈
|
|
||||||
// ⠀⣿⢿⡀⠘⢦⡈⢻⣦⠐⠀⠀⠄⠀⠁⠈⠀⡀⠠⠀⣠⡿⣿⣯⣽⡇
|
|
||||||
// ⠀⢻⣿⠛⢦⣄⣹⠦⣌⣳⡀⠀⣠⠈⠀⢾⠀⠀⢀⣼⢯⠞⢡⣿⣿⠁
|
|
||||||
// ⠄⠘⣿⣷⣤⡀⠙⣆⠈⠻⣿⡄⠘⣇⠀⣾⠀⣴⠿⢲⣋⣤⣿⡿⠃⠀
|
|
||||||
// ⠀⡀⠹⣿⣦⡉⠛⠚⣆⠀⠈⠻⣆⢻⢠⣇⡾⠃⢠⣟⣠⣾⡞⠃⠀
|
|
||||||
// ⠂⡀⠄⠹⣿⣏⠛⠒⠾⠷⣄⠀⠙⣞⣿⠋⣀⣴⣋⣽⡿⠋
|
|
||||||
// ⠂⠠⠀⠀⣨⣿⢿⣶⣒⠲⢮⣿⣶⣼⣧⣾⣭⣿⠟⠉
|
|
||||||
// ⠐⠀⠁⣰⣿⠓⠒⣛⣻⠟⠛⣩⣿⣯⠙⡯⣿⡆
|
|
||||||
// ⠐⠀⠄⠸⣿⡟⢉⡽⢛⣿⡿⠉⠀⢸⣧⡷⣾⡇
|
|
||||||
// ⠀⢂⠀⠄⠹⢿⣿⣴⣯⠏⠀⠀⠀⣼⢸⣽⣷⠇
|
|
||||||
// ⠠⠀⠂⢀⠀⢀⠈⠉⠀⠀⠀⠂⡀⠹⠿⠛⠁⠀⠀
|
|
||||||
|
|
||||||
/* les1.cpp
|
|
||||||
* Assignment done in the first lesson explaining
|
* Assignment done in the first lesson explaining
|
||||||
* the basics of ROS2
|
* the basics of ROS2
|
||||||
*
|
*
|
||||||
@@ -26,18 +8,16 @@
|
|||||||
* [07-09-2025] Wessel T:
|
* [07-09-2025] Wessel T:
|
||||||
* - Rename {les1.cpp -> les1/clock.cpp}
|
* - Rename {les1.cpp -> les1/clock.cpp}
|
||||||
* - Update node names to be in line with other files
|
* - Update node names to be in line with other files
|
||||||
|
* [11-09-2025] Wessel T: Remove unused imports
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "rclcpp/rclcpp.hpp"
|
#include "rclcpp/rclcpp.hpp"
|
||||||
#include <rclcpp/clock.hpp>
|
|
||||||
#include <rclcpp/time.hpp>
|
|
||||||
|
|
||||||
class NodeLes1Clock : public rclcpp::Node
|
class NodeLes1Clock : public rclcpp::Node {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
NodeLes1Clock()
|
NodeLes1Clock()
|
||||||
: Node("node_les1_clock")
|
: Node("node_les1_clock")
|
||||||
{
|
{
|
||||||
timer_ = this->create_wall_timer(
|
timer_ = this->create_wall_timer(
|
||||||
std::chrono::seconds(1),
|
std::chrono::seconds(1),
|
||||||
|
|||||||
@@ -1,22 +1,4 @@
|
|||||||
// Wessel T <contact@wessel.gg> (https://wessel.gg/)
|
/* les1/publisher.cpp
|
||||||
//
|
|
||||||
// "Build your own tower.
|
|
||||||
// A kingdom freed from malice.
|
|
||||||
// Create a world of bounty, peace and beauty."
|
|
||||||
// ⠀⣠⣶⣶⣤⣁
|
|
||||||
// ⢰⣷⡟⠻⣏⠻⣧⣀⠐⠈⠀⡈⠠⠀⠂⠀⢁⠈⠀⠄⠀⠁⣠⣴⣤⡈
|
|
||||||
// ⠀⣿⢿⡀⠘⢦⡈⢻⣦⠐⠀⠀⠄⠀⠁⠈⠀⡀⠠⠀⣠⡿⣿⣯⣽⡇
|
|
||||||
// ⠀⢻⣿⠛⢦⣄⣹⠦⣌⣳⡀⠀⣠⠈⠀⢾⠀⠀⢀⣼⢯⠞⢡⣿⣿⠁
|
|
||||||
// ⠄⠘⣿⣷⣤⡀⠙⣆⠈⠻⣿⡄⠘⣇⠀⣾⠀⣴⠿⢲⣋⣤⣿⡿⠃⠀
|
|
||||||
// ⠀⡀⠹⣿⣦⡉⠛⠚⣆⠀⠈⠻⣆⢻⢠⣇⡾⠃⢠⣟⣠⣾⡞⠃⠀
|
|
||||||
// ⠂⡀⠄⠹⣿⣏⠛⠒⠾⠷⣄⠀⠙⣞⣿⠋⣀⣴⣋⣽⡿⠋
|
|
||||||
// ⠂⠠⠀⠀⣨⣿⢿⣶⣒⠲⢮⣿⣶⣼⣧⣾⣭⣿⠟⠉
|
|
||||||
// ⠐⠀⠁⣰⣿⠓⠒⣛⣻⠟⠛⣩⣿⣯⠙⡯⣿⡆
|
|
||||||
// ⠐⠀⠄⠸⣿⡟⢉⡽⢛⣿⡿⠉⠀⢸⣧⡷⣾⡇
|
|
||||||
// ⠀⢂⠀⠄⠹⢿⣿⣴⣯⠏⠀⠀⠀⣼⢸⣽⣷⠇
|
|
||||||
// ⠠⠀⠂⢀⠀⢀⠈⠉⠀⠀⠀⠂⡀⠹⠿⠛⠁⠀⠀
|
|
||||||
|
|
||||||
/* les1.cpp
|
|
||||||
* Assignment done in the first lesson explaining
|
* Assignment done in the first lesson explaining
|
||||||
* the basics of ROS2
|
* the basics of ROS2
|
||||||
*
|
*
|
||||||
@@ -24,66 +6,66 @@
|
|||||||
* Changelog:
|
* Changelog:
|
||||||
* [04-09-2025] Wessel T:
|
* [04-09-2025] Wessel T:
|
||||||
* - Implement template
|
* - Implement template
|
||||||
|
* [11-09-2025] Wessel T: Remove unused imports
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "rclcpp/rclcpp.hpp"
|
#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 "geometry_msgs/msg/point.hpp" // Point for x, y, z coordinates
|
||||||
#include "les_interface/msg/hardware_status.hpp" // Custom HW status message
|
#include "les_interface/msg/hardware_status.hpp" // Custom HW status message
|
||||||
|
|
||||||
class NodeLes1Publisher : public rclcpp::Node {
|
class NodeLes1Publisher : public rclcpp::Node {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NodeLes1Publisher()
|
NodeLes1Publisher()
|
||||||
: Node("node_les1_publisher")
|
: Node("node_les1_publisher")
|
||||||
{
|
{
|
||||||
publisher_location_ =
|
publisher_location_ =
|
||||||
this->create_publisher<geometry_msgs::msg::Point>("location", 10);
|
this->create_publisher<geometry_msgs::msg::Point>("location", 10);
|
||||||
|
|
||||||
publisher_hw_status_ =
|
publisher_hw_status_ =
|
||||||
this->create_publisher<les_interface::msg::HardwareStatus>("hardware_status", 10);
|
this->create_publisher<les_interface::msg::HardwareStatus>("hardware_status", 10);
|
||||||
|
|
||||||
timer_location_ = this->create_wall_timer(
|
timer_location_ = this->create_wall_timer(
|
||||||
std::chrono::seconds(2),
|
std::chrono::seconds(2),
|
||||||
std::bind(&NodeLes1Publisher::timer_location_function, this)
|
std::bind(&NodeLes1Publisher::timer_location_function, this)
|
||||||
);
|
);
|
||||||
|
|
||||||
timer_hw_status_ = this->create_wall_timer(
|
timer_hw_status_ = this->create_wall_timer(
|
||||||
std::chrono::seconds(2),
|
std::chrono::seconds(2),
|
||||||
std::bind(&NodeLes1Publisher::timer_hw_status_function, this)
|
std::bind(&NodeLes1Publisher::timer_hw_status_function, this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void timer_location_function() {
|
void timer_location_function() {
|
||||||
geometry_msgs::msg::Point coordinate;
|
geometry_msgs::msg::Point coordinate;
|
||||||
coordinate.x = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
|
coordinate.x = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
|
||||||
coordinate.y = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
|
coordinate.y = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
|
||||||
coordinate.z = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
|
coordinate.z = static_cast<double>(std::rand()) / RAND_MAX * 100.0;
|
||||||
|
|
||||||
publisher_location_->publish(coordinate);
|
publisher_location_->publish(coordinate);
|
||||||
RCLCPP_INFO(this->get_logger(),
|
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;
|
les_interface::msg::HardwareStatus hw_msg;
|
||||||
hw_msg.version = 1;
|
hw_msg.version = 1;
|
||||||
hw_msg.temperature = static_cast<double>(std::rand()) / RAND_MAX * 80.0;
|
hw_msg.temperature = static_cast<double>(std::rand()) / RAND_MAX * 80.0;
|
||||||
hw_msg.are_motors_ready = (std::rand() % 2 == 0);
|
hw_msg.are_motors_ready = (std::rand() % 2 == 0);
|
||||||
hw_msg.debug_message = "Status OK";
|
hw_msg.debug_message = "Status OK";
|
||||||
|
|
||||||
publisher_hw_status_->publish(hw_msg);
|
publisher_hw_status_->publish(hw_msg);
|
||||||
RCLCPP_INFO(this->get_logger(),
|
RCLCPP_INFO(this->get_logger(),
|
||||||
"Published HW status: version=%ld, temp=%.2f, motors_ready=%s, msg=%s",
|
"Published HW status: version=%ld, temp=%.2f, motors_ready=%s, msg=%s",
|
||||||
hw_msg.version, hw_msg.temperature,
|
hw_msg.version, hw_msg.temperature,
|
||||||
hw_msg.are_motors_ready ? "true" : "false",
|
hw_msg.are_motors_ready ? "true" : "false",
|
||||||
hw_msg.debug_message.c_str());
|
hw_msg.debug_message.c_str()
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rclcpp::Publisher<geometry_msgs::msg::Point>::SharedPtr publisher_location_;
|
rclcpp::Publisher<geometry_msgs::msg::Point>::SharedPtr publisher_location_;
|
||||||
|
|||||||
@@ -1,22 +1,4 @@
|
|||||||
// Wessel T <contact@wessel.gg> (https://wessel.gg/)
|
/* les1/subscriber.cpp
|
||||||
//
|
|
||||||
// "Build your own tower.
|
|
||||||
// A kingdom freed from malice.
|
|
||||||
// Create a world of bounty, peace and beauty."
|
|
||||||
// ⠀⣠⣶⣶⣤⣁
|
|
||||||
// ⢰⣷⡟⠻⣏⠻⣧⣀⠐⠈⠀⡈⠠⠀⠂⠀⢁⠈⠀⠄⠀⠁⣠⣴⣤⡈
|
|
||||||
// ⠀⣿⢿⡀⠘⢦⡈⢻⣦⠐⠀⠀⠄⠀⠁⠈⠀⡀⠠⠀⣠⡿⣿⣯⣽⡇
|
|
||||||
// ⠀⢻⣿⠛⢦⣄⣹⠦⣌⣳⡀⠀⣠⠈⠀⢾⠀⠀⢀⣼⢯⠞⢡⣿⣿⠁
|
|
||||||
// ⠄⠘⣿⣷⣤⡀⠙⣆⠈⠻⣿⡄⠘⣇⠀⣾⠀⣴⠿⢲⣋⣤⣿⡿⠃⠀
|
|
||||||
// ⠀⡀⠹⣿⣦⡉⠛⠚⣆⠀⠈⠻⣆⢻⢠⣇⡾⠃⢠⣟⣠⣾⡞⠃⠀
|
|
||||||
// ⠂⡀⠄⠹⣿⣏⠛⠒⠾⠷⣄⠀⠙⣞⣿⠋⣀⣴⣋⣽⡿⠋
|
|
||||||
// ⠂⠠⠀⠀⣨⣿⢿⣶⣒⠲⢮⣿⣶⣼⣧⣾⣭⣿⠟⠉
|
|
||||||
// ⠐⠀⠁⣰⣿⠓⠒⣛⣻⠟⠛⣩⣿⣯⠙⡯⣿⡆
|
|
||||||
// ⠐⠀⠄⠸⣿⡟⢉⡽⢛⣿⡿⠉⠀⢸⣧⡷⣾⡇
|
|
||||||
// ⠀⢂⠀⠄⠹⢿⣿⣴⣯⠏⠀⠀⠀⣼⢸⣽⣷⠇
|
|
||||||
// ⠠⠀⠂⢀⠀⢀⠈⠉⠀⠀⠀⠂⡀⠹⠿⠛⠁⠀⠀
|
|
||||||
|
|
||||||
/* les1.cpp
|
|
||||||
* Assignment done in the first lesson explaining
|
* Assignment done in the first lesson explaining
|
||||||
* the basics of ROS2
|
* the basics of ROS2
|
||||||
*
|
*
|
||||||
@@ -38,8 +20,8 @@ using namespace std::placeholders;
|
|||||||
class NodeLes1Subscriber : public rclcpp::Node {
|
class NodeLes1Subscriber : public rclcpp::Node {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NodeLes1Subscriber()
|
NodeLes1Subscriber()
|
||||||
: Node("node_les1_subscriber")
|
: Node("node_les1_subscriber")
|
||||||
{
|
{
|
||||||
subscriber_location_ =
|
subscriber_location_ =
|
||||||
this->create_subscription<geometry_msgs::msg::Point>(
|
this->create_subscription<geometry_msgs::msg::Point>(
|
||||||
@@ -52,21 +34,21 @@ NodeLes1Subscriber()
|
|||||||
"hardware_status", 10,
|
"hardware_status", 10,
|
||||||
std::bind(&NodeLes1Subscriber::sub_callback_hw_status, this, _1)
|
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(),
|
RCLCPP_INFO(this->get_logger(),
|
||||||
"Received: x=%.2f, y=%.2f, z=%.2f", msg->x, msg->y, msg->z
|
"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(),
|
RCLCPP_INFO(this->get_logger(),
|
||||||
"Received HW status: version=%ld, temp=%.2f, motors_ready=%s, msg=%s",
|
"Received HW status: version=%ld, temp=%.2f, motors_ready=%s, msg=%s",
|
||||||
msg->version, msg->temperature,
|
msg->version, msg->temperature,
|
||||||
msg->are_motors_ready ? "true" : "false",
|
msg->are_motors_ready ? "true" : "false",
|
||||||
msg->debug_message.c_str());
|
msg->debug_message.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rclcpp::Subscription<geometry_msgs::msg::Point>::SharedPtr subscriber_location_;
|
rclcpp::Subscription<geometry_msgs::msg::Point>::SharedPtr subscriber_location_;
|
||||||
|
|||||||
31
src/les_pkg/src/node_template.cpp
Normal file
31
src/les_pkg/src/node_template.cpp
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user