-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
M2m2 simple dev #35
Conversation
- 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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
.
|
||
# 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}) |
There was a problem hiding this comment.
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.
explicit M2M2Lidar( | ||
const rclcpp::NodeOptions& options = rclcpp::NodeOptions()); | ||
|
||
/** | ||
* @brief Clean up | ||
*/ | ||
~M2M2Lidar(); |
There was a problem hiding this comment.
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 delete
ing them. Since you are managing resources (network socket), you definitely need to handle it.
int _requestId; | ||
static constexpr const char* REQUEST_DELIM = "\r\n\r\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect ordering
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_; | ||
}; |
There was a problem hiding this comment.
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).
# 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 ]; | ||
}; | ||
} |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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)
Removed references for target_link_libraries that are not needed
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})