botamochi6277 / ros2_pigpio

ROS2 package to control raspberry pi GPIO with pigpio
MIT License
19 stars 5 forks source link

Can't select GPIO pin between 0-9 #3

Closed me-henk closed 2 months ago

me-henk commented 2 months ago

I have the issue that when selecting a GPIO pin number between 0 to 9 an error will be given, selecting a GPIO from 10 and up goes without error and works. I only tested this on the write and read, not on PWM and wheels.

I tried to enter the number in two ways, for example I'll use GPIO7: ros2 run ros2_pigpio gpio_writer --ros-args --param pin:=7 ros2 run ros2_pigpio gpio_writer --ros-args --param pin:=07 ros2 run ros2_pigpio gpio_reader --ros-args --param pin:=7 --param is_pull_up:=false ros2 run ros2_pigpio gpio_reader --ros-args --param pin:=07 --param is_pull_up:=false

Both give the same error for the write (the text is not fully correct, please check the image): [INFO] [1723736005.741199014] [gpiosubscriber]: Write GPIO-07 terminate called after throwing an instance of 'rclcpp::exceptions::InvalidTopicNameError' what(): Invalid topic name: topic name must not contain characters other than alphanumerics, '', '~', '{', or '}': 'gpiooutput 7' ^

Also both give the same error for the read (the text is not fully correct, please check the image): [INFO] [1723736147.921912773] [gpio_publisher]: Read GPIO-07 (PULLDOWN) terminate called after throwing an instance of 'rclcpp::exceptions::InvalidTopicNameError' what(): Invalid topic name: topic name must not contain characters other than alphanumerics, '', '~', '{', or '}': 'gpioinput 7' ^

I am using Ubuntu 22.04 server and ros2 Humble, because github removes some of the underscores in my text and puts the ^ in the wrong place I added an image from the error messages were the underscore can be seen. github pigpio errors

botamochi6277 commented 2 months ago

Hello me-henk, thank you for using this repository and sharing the issue. 👍 This problem is due to wrong topic name making. I fixed it at 15bad4e96e417900cf2b3a697902e78abe0328dd. Please pull this commit and retry to use.


wrong points: before:

ss << "gpio_input_" << std::setw(2) << pin_;

after:

ss << "gpio_input_" << std::setfill('0') << std::right << std::setw(2) << pin_;
me-henk commented 2 months ago

Thank you for the fast response and fix. I just did a test with the new fix and all is working now.