Fixed services for parameter adjusting not working

This commit is contained in:
2025-02-28 19:43:00 +01:00
parent e46b336357
commit 0839b19c09

View File

@ -6,6 +6,7 @@
#include <rclcpp/service.hpp> #include <rclcpp/service.hpp>
#include <string> #include <string>
#include <libserial/SerialStream.h> #include <libserial/SerialStream.h>
#include <sys/types.h>
#include "mg_msgs/srv/set_width.hpp" #include "mg_msgs/srv/set_width.hpp"
#include "std_srvs/srv/empty.hpp" #include "std_srvs/srv/empty.hpp"
@ -56,9 +57,9 @@ class MgOdomPublisher : public rclcpp::Node {
void set_width(const std::shared_ptr<SetWidthSrv::Request> request) { void set_width(const std::shared_ptr<SetWidthSrv::Request> request) {
RCLCPP_INFO(get_logger(), "Setting width to: %lf", request->width); RCLCPP_INFO(get_logger(), "Setting width to: %lf", request->width);
if (!enc_serial_port_.IsOpen()) { if (enc_serial_port_.IsOpen()) {
union { union {
std::array<double, sizeof(double)> bytes; std::array<u_char, sizeof(double)> bytes;
double data; double data;
} value{}; } value{};
value.data = request->width; value.data = request->width;
@ -71,7 +72,7 @@ class MgOdomPublisher : public rclcpp::Node {
void zero(const std::shared_ptr<ZeroSrv::Request> /*request*/) { void zero(const std::shared_ptr<ZeroSrv::Request> /*request*/) {
RCLCPP_INFO(get_logger(), "Zeroing odometry"); RCLCPP_INFO(get_logger(), "Zeroing odometry");
if (!enc_serial_port_.IsOpen()) { if (enc_serial_port_.IsOpen()) {
enc_serial_port_ << "z;"; enc_serial_port_ << "z;";
} }
} }