YDLIDAR / ydlidar_ros2_driver

ydlidar driver package under ros2
Other
54 stars 99 forks source link

Build Error in ROS2 Humble: no matching function - rclcpp::Node::declare_parameter(const char [5]) #21

Closed slowrunner closed 1 year ago

slowrunner commented 1 year ago

Compile errors in ROS2 Humble (on Ubuntu 22.04 Server Jammy)

$ colcon build --symlink-install
Starting >>> ydlidar_ros2_driver
[Processing: ydlidar_ros2_driver]                             
--- stderr: ydlidar_ros2_driver                               
/home/ubuntu/ydlidar_ros2_ws/src/ydlidar_ros2_driver/src/ydlidar_ros2_driver_node.cpp: In function ‘int main(int, char**)’:
/home/ubuntu/ydlidar_ros2_ws/src/ydlidar_ros2_driver/src/ydlidar_ros2_driver_node.cpp:44:26: error: no matching function for call to ‘rclcpp::Node::declare_parameter(const char [5])’
   44 |   node->declare_parameter("port");
      |   ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/opt/ros/humble/include/rclcpp/rclcpp/node.hpp:421:3: note:   template argument deduction/substitution failed:
/home/ubuntu/ydlidar_ros2_driver/src/ydlidar_ros2_driver_node.cpp:44:26: note:   candidate expects 4 arguments, 1 provided
   44 |   node->declare_parameter("port");
      |   ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~

...

ubuntu@ROS2HH:~/ydlidar_ros2_ws$ printenv | grep ROS
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_DOMAIN_ID=0
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=humble

ubuntu@ROS2HH:~/ydlidar_ros2_ws$ uname -a
Linux ROS2HH 5.15.0-1017-raspi #19-Ubuntu SMP PREEMPT Fri Oct 14 08:22:47 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
slowrunner commented 1 year ago

Workaround: Added ", optvalue", ", f_optvalue", ", b_optvalue" as appropriate for each declare_parameter() to get it to properly compile.

Also had to change ydlidarlaunch.py removing node from executable, name, namespace to get it to build:

 driver_node = LifecycleNode(package='ydlidar_ros2_driver',
                                executable='ydlidar_ros2_driver_node',
                                name='ydlidar_ros2_driver_node',
                                output='screen',
                                emulate_tty=True,
                                parameters=[parameter_file],
                                namespace='/',
                                )
MrBearing commented 1 year ago

maybe, @lghrainbow is solve this issue in below PR ?

https://github.com/YDLIDAR/ydlidar_ros2_driver/pull/20

MrBearing commented 1 year ago

In my enviroment, this repository is work.

slowrunner commented 1 year ago

In my environment, this repository gives the following errors: [ydlidar_ros2_driver_node-1] terminate called after throwing an instance of 'rclcpp::exceptions::UninitializedStaticallyTypedParameterException' [ydlidar_ros2_driver_node-1] what(): Statically typed parameter 'fixed_resolution' must be initialized. [static_transform_publisher-2] [INFO] [1666711686.062313321] [static_tf_pub_laser]: Spinning until stopped - publishing transform

I had to change "resolution_fixed: true" to "fixed_resolution: true" in params/ydlidar.yaml and then the @lghrainbow humble updates worked for me

MrBearing commented 1 year ago

Oh, sorry for my misunderstanding. You use raspberry pi ? It is different from my environment.(amd64 , Ubuntu 22.04)

rekabuk commented 1 year ago

Sorry, I'm not geat with git. Can I get a copy of the code that works for Humble on Ubuntu 20.04 Jammy. Is it in the Pull Request somewhere?

rekabuk commented 1 year ago

Mr Bearing #20 worked for me 😀

JHPHELAN commented 1 year ago

@slowrunner "Workaround: Added ", optvalue", ", f_optvalue", ", b_optvalue" as appropriate for each declare_parameter() to get it to properly compile." I'm a ROS2 newbie and don't know what 'optvalue' is nor which is appropriate where. Could you please give example code changes? Thanks!!

slowrunner commented 1 year ago

This is the version I used by @lghrainbow that compiles under ROS2 Humble / Ubuntu 22.04 Jammy / Python 3.10.6 (Updated 3/19/23 to point to file I used successfully):

https://raw.githubusercontent.com/slowrunner/ROS2-GoPiGo3/main/ros2ws/src/ydlidar_ros2_driver/src/ydlidar_ros2_driver_node.cpp

ly-bo commented 4 months ago

I'm using the same environment and getting the same error. I later made a change to the code, and the compilation passed without a hitch. std::string str_optvalue = "/dev/ydlidar"; std::string str_port = "port"; node->declare_parameter(str_port,str_optvalue); node->get_parameter("port", str_optvalue);