First flake environment

This commit is contained in:
2025-11-06 15:59:22 +01:00
parent 8648a96bce
commit d8b55f08de
33 changed files with 371 additions and 26 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.24)
project(mg_odometry)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@ -14,7 +14,6 @@ find_package(tf2_geometry_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(mg_msgs REQUIRED)
include(FindPkgConfig)
pkg_search_module(LIBSERIAL REQUIRED libserial)
# uncomment the following section in order to fill in
# further dependencies manually.
@ -36,11 +35,10 @@ ament_target_dependencies(
target_include_directories(mg_odom_publisher PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
${LIBSERIAL_INCLUDE_DIRS})
)
target_link_libraries(
mg_odom_publisher
${LIBSERIAL_LIBRARIES}
)
target_compile_features(mg_odom_publisher PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17

19
mg_odometry/package.nix Normal file
View File

@ -0,0 +1,19 @@
# Automatically generated by: ros2nix --distro jazzy
{ lib, buildRosPackage, ament-cmake, ament-lint-auto, ament-lint-common, libserial-dev, mg-msgs, rclcpp, std-srvs, tf2, tf2-geometry-msgs, tf2-ros }:
buildRosPackage rec {
pname = "ros-jazzy-mg-odometry";
version = "0.0.0";
src = ./.;
buildType = "ament_cmake";
buildInputs = [ ament-cmake ];
checkInputs = [ ament-lint-auto ament-lint-common ];
propagatedBuildInputs = [ mg-msgs rclcpp std-srvs tf2 tf2-geometry-msgs tf2-ros ];
nativeBuildInputs = [ ament-cmake ];
meta = {
description = "TODO: Package description";
license = with lib.licenses; [ "TODO-License-declaration" ];
};
}

View File

@ -5,7 +5,7 @@
#include <memory>
#include <rclcpp/service.hpp>
#include <string>
#include <libserial/SerialStream.h>
//#include <libserial/SerialStream.h>
#include <sys/types.h>
#include "mg_msgs/srv/send_double.hpp"
@ -59,11 +59,11 @@ class MgOdomPublisher : public rclcpp::Node {
rclcpp::Service<ZeroSrv>::SharedPtr zero_service_;
rclcpp::Service<ZeroSrv>::SharedPtr calib_service_;
rclcpp::TimerBase::SharedPtr timer_;
LibSerial::SerialStream enc_serial_port_;
//LibSerial::SerialStream enc_serial_port_;
void set_width(const std::shared_ptr<SendDoubleSrv::Request> request) {
RCLCPP_INFO(get_logger(), "Setting width to: %lf", request->data);
/*
if (enc_serial_port_.IsOpen()) {
union {
std::array<u_char, sizeof(double)> bytes;
@ -74,11 +74,12 @@ class MgOdomPublisher : public rclcpp::Node {
enc_serial_port_ << "w;";
for (const auto& byte : value.bytes) { enc_serial_port_ << byte; }
}
*/
}
void set_ratio(const std::shared_ptr<SendDoubleSrv::Request> request) {
RCLCPP_INFO(get_logger(), "Setting wheel ratio to: %lf", request->data);
/*
if (enc_serial_port_.IsOpen()) {
union {
std::array<u_char, sizeof(double)> bytes;
@ -89,11 +90,13 @@ class MgOdomPublisher : public rclcpp::Node {
enc_serial_port_ << "r;";
for (const auto& byte : value.bytes) { enc_serial_port_ << byte; }
}
*/
}
void calib(const std::shared_ptr<ZeroSrv::Request> /*request*/) {
RCLCPP_INFO(get_logger(), "Finishing wheel diameter calib");
/*
if (enc_serial_port_.IsOpen()) {
enc_serial_port_ << "c;";
double left_gain = 0;
@ -101,14 +104,16 @@ class MgOdomPublisher : public rclcpp::Node {
enc_serial_port_ >> left_gain >> right_gain;
RCLCPP_INFO(this->get_logger(), "The new gains are %lf %lf", left_gain, right_gain);
}
*/
}
void zero(const std::shared_ptr<ZeroSrv::Request> /*request*/) {
RCLCPP_INFO(get_logger(), "Zeroing odometry");
/*
if (enc_serial_port_.IsOpen()) {
enc_serial_port_ << "z;";
}
*/
}
void timer_callback() {
@ -118,6 +123,7 @@ class MgOdomPublisher : public rclcpp::Node {
RCLCPP_DEBUG(this->get_logger(), "Callback called");
/*
try {
if (!enc_serial_port_.IsOpen()) {
enc_serial_port_.Open(this->get_parameter("serial_path").as_string());
@ -134,6 +140,7 @@ class MgOdomPublisher : public rclcpp::Node {
make_transform(_x, _y, _theta);
} catch (const std::exception& e) { RCLCPP_ERROR(this->get_logger(), "%s\n", e.what()); }
*/
}
void make_transform(double x, double y, double theta) {