ROS2 Ultrasonic Range Package

798 views
Skip to first unread message

camp .

unread,
Nov 24, 2021, 12:23:35 AM11/24/21
to HomeBrew Robotics Club
Hey folks!
Big times at the ROS Discussion Group this evening! Starting with a functioning Raspberry Pi/Python ultrasonic script: https://tutorials-raspberrypi.com/raspberry-pi-ultrasonic-sensor-hc-sr04/
 
And a functioning publisher and subscriber package as described in the ROS2 tutorial: https://docs.ros.org/en/foxy/Tutorials/Writing-A-Simple-Py-Publisher-And-Subscriber.html
 
And with Big Time Help from Ralph Gnauck and Michael Wimble. We have converged the packages and made a "ROS2 Ultrasonic Range Package."
 
Below find attached the modified ultrasonic Python package and the modified simple publisher. First, create the "simple publisher" per instructions and then replace "publisher_member_function.py" with the modified version and place the modified "ultrasonic_distance.py" in the same directory. Compile and run "ros2 run py_pubsub talker" to start the publisher and "ros2 topic echo /distance" to see the distance being published as a range topic. The next step is to create a range subscriber. Again Big Thanks to Ralph and Mike. Big Thanks!
 
- Camp

publisher_member_function.py
ultrasonic_distance.py

camp .

unread,
Aug 17, 2022, 10:09:55 PM8/17/22
to HomeBrew Robotics Club
    Almost a year ago at the ROS Discussion Group, we folded a "Raspberry Pi/Python ultrasonic script" into the ROS2 Tutorial "Python Simple Publisher" and made a ROS2 ultrasonic publisher. I'm trying to duplicate this but am getting the below error message when launching "ros2 run py_pubsub talker."
 
-------------------------------------------------- snip --------------------------------------------------
Traceback (most recent call last):
  File "/home/camp/dev_ws/install/py_pubsub/lib/py_pubsub/talker", line 33, in <module>
    sys.exit(load_entry_point('py-pubsub==0.0.0', 'console_scripts', 'talker')())
  File "/home/camp/dev_ws/install/py_pubsub/lib/py_pubsub/talker", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/camp/dev_ws/install/py_pubsub/lib/python3.10/site-packages/py_pubsub/publisher_member_function.py", line 18, in <module>
    import py_pubsub.ultrasonic_distance as p
  File "/home/camp/dev_ws/install/py_pubsub/lib/python3.10/site-packages/py_pubsub/ultrasonic_distance.py", line 13, in <module>
    GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
RuntimeError: No access to /dev/mem.  Try running as root!
[ros2run]: Process exited with failure 1
-------------------------------------------------- snip --------------------------------------------------
 
    I've got two systems. One is Ubuntu 20.04 and foxy which works and the other is Ubuntu 22.04 and humble where I'm getting the above error. I am checking all the files including "publisher_member_function.py" and "ultrasonic_distance.py" which are identical plus package.xml, setup.py and setup.cfg.
    I also get an error with colcon build that I do not get with the original installation.
 
-------------------------------------------------- snip --------------------------------------------------
Starting >>> py_pubsub
--- stderr: py_pubsub                   
/usr/lib/python3/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
---
Finished <<< py_pubsub [3.87s]

Summary: 1 package finished [4.67s]
  1 package had stderr output: py_pubsub
-------------------------------------------------- snip --------------------------------------------------
 
Suggestions?
 
Thanks,
Camp

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hbrobotics/43985304.900411.1637731408342%40mail.yahoo.com.
publisher_member_function.py
ultrasonic_distance.py

camp .

unread,
Aug 18, 2022, 12:33:58 AM8/18/22
to HomeBrew Robotics Club
    I figured out what it was. I needed to install "rpi.gpio-common" and add myself to the dialout group.
 
Thanks!
Camp

publisher_member_function.py
ultrasonic_distance.py
Reply all
Reply to author
Forward
0 new messages