Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2m2 simple dev #35

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

M2m2 simple dev #35

wants to merge 14 commits into from

Conversation

DingoOz
Copy link
Contributor

@DingoOz DingoOz commented Dec 22, 2024

This PR brings over the Humble baseline code for the m2m2_lidar node.

I added the nlohmann and openSSL libraries to the pacakge's nix overlay.

When adding these libraries to the CMakeLists.txt I had to add a target_link_libraries explicitly as there are two libraries in OpenSSL that are needed OpenSSL::SSL and Open::Crypto and build fails unless being explicit here.

This is the relevant section:

OpenSSL has two libraries that need to linked against explicitly

target_link_libraries(
m2m2_lidar
PRIVATE OpenSSL::SSL OpenSSL::Crypto nlohmann_json::nlohmann_json
${rclcpp_LIBRARIES} ${sensor_msgs_LIBRARIES} ${std_msgs_LIBRARIES})

RandomSpaceship and others added 8 commits December 22, 2024 19:14
- Despite symlinking the "real" executable, ros2 run can't see the node, so versioning has to be removed.
Readme file is useful for communicating how this node is generally
used; how it might be used independently of persues bringup and
that there are features which are still be worked on.
Added the code that was baselined against ROS2 Humble and demonstated working.
Add two required libraries the package nix overlay and adjusted the CMakeLists file.
Due to needing both openssl::crypto and openssl::ssl had to add an explicit target_link_libraries to CMakeLists.txt
@DingoOz DingoOz temporarily deployed to binary-deployment December 22, 2024 12:05 — with GitHub Actions Inactive
Copy link
Contributor

@RandomSpaceship RandomSpaceship left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone through and commented on most of the issues I see. Probably missed a few things, but I think I've noted the worst of it.

* Groups all sensor-specific configuration parameters in one place,
* making it easier to modify settings and extend functionality
*/
struct SensorConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming doesn't match software standards - should be sensor_config_t


<depend>rclcpp</depend>
<depend>backward_ros</depend>
<depend>sensor_msgs</depend>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you depend on openSSL and nlohman::json, add the dependencies here. Just standard <depend> tags in this case, openssl and nlohmann-json-dev.

Comment on lines 69 to 74

# OpenSSL has two libraries that need to linked against explicitly
target_link_libraries(
m2m2_lidar
PRIVATE OpenSSL::SSL OpenSSL::Crypto nlohmann_json::nlohmann_json
${rclcpp_LIBRARIES} ${sensor_msgs_LIBRARIES} ${std_msgs_LIBRARIES})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace all of this with:

target_link_libraries(m2m2_lidar PRIVATE OpenSSL::Crypto)

That's all you need.

target_link_libraries is not exclusive, it's additive! ament_target_dependencies already sets up linking against all of the dependencies in THIS_PACKAGE_INCLUDE_DEPENDS, getting rid of all the _LIBRARIES specifiers you have there. Its documentation shows in the example that it also links against default namespaced targets too, so that gets rid of OpenSSL::SSL and nlohmann_json::nlohmann_json (I think they're the default targets), which leaves only OpenSSL::Crypto needing manual linking.

Comment on lines +42 to +48
explicit M2M2Lidar(
const rclcpp::NodeOptions& options = rclcpp::NodeOptions());

/**
* @brief Clean up
*/
~M2M2Lidar();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heed the Rule of Three - given that you have a destructor (and are therefore probably managing resources), you almost certainly need to handle copy/move semantics as well, even if it's just deleteing them. Since you are managing resources (network socket), you definitely need to handle it.

Comment on lines 51 to 52
int _requestId;
static constexpr const char* REQUEST_DELIM = "\r\n\r\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect ordering

Comment on lines +514 to +534
class M2M2LidarNode : public rclcpp::Node
{
public:
M2M2LidarNode() : Node("m2m2_lidar_node")
{
publisher_ = this->create_publisher<sensor_msgs::msg::LaserScan>("m2m2_lidar/scan", 10);
timer_ = this->create_wall_timer(
100ms, std::bind(&M2M2LidarNode::publish_scan, this));
}

private:
void publish_scan()
{
auto message = sensor_msgs::msg::LaserScan();
// Fill in the LaserScan message
publisher_->publish(message);
}

rclcpp::Publisher<sensor_msgs::msg::LaserScan>::SharedPtr publisher_;
rclcpp::TimerBase::SharedPtr timer_;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use a different syntax. Declare everything which should be part of the class in the header file. Also, naming check fails again (method names + underscore placement).

Comment on lines +1 to +35
# Automatically generated by: ros2nix --output-dir=ros_ws/nix-packages --output-as-nix-pkg-name --no-default --distro jazzy
{
lib,
buildRosPackage,
ament-cmake,
backward-ros,
rclcpp,
sensor-msgs,
nlohmann_json,
openssl,
}:
buildRosPackage rec {
pname = "ros-jazzy-perseus-sensors";
version = "0.0.0";

src = ./../src/perseus_sensors;

buildType = "ament_cmake";
buildInputs = [
ament-cmake
nlohmann_json
openssl
];
propagatedBuildInputs = [
backward-ros
rclcpp
sensor-msgs
];
nativeBuildInputs = [ ament-cmake ];

meta = {
description = "TODO: Package description";
license = with lib.licenses; [ mit ];
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after fixing the package.xml, run software/scripts/nix-package.sh --no-commit to regenerate the nix packaging info

/**
* @brief Clean up
*/
~M2M2Lidar();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructors should either be protected and nonvirtual or public and virtual

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(yes I'm guilty of this too, I need to fix my code as well)

#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/laser_scan.hpp"

using namespace std::chrono_literals;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to add using std::string, std::vector; and the like to remove some of the namespacing in this file

Comment on lines +499 to +502
scan->time_increment = 1.0 / (15.0 * points.size()); // Assuming 15Hz scan rate
scan->scan_time = 1.0 / 15.0; // 15Hz
scan->range_min = 0.1; // 10cm minimum range
scan->range_max = 30.0; // 30m maximum range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give your magic constants names, then you can also get rid of the comments (or convert them to notes on the units of the constant)

@DingoOz DingoOz temporarily deployed to binary-deployment December 22, 2024 20:34 — with GitHub Actions Inactive
@DingoOz DingoOz deployed to binary-deployment December 22, 2024 20:36 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants