Skip to content

building PX4 with colcon on ubuntu22 - ros2 humble: ROS2 interface proto can't find px4 module  #21128

Open
@beniaminopozzan

Description

@beniaminopozzan

Describe the bug

To Reproduce

Steps to reproduce the behavior, assuming: ros2 humble installed from binaries, PX4 toolchain configured.

  1. Create a new colcon workspace
    mkdir -p ~/px4_colcon_ws/src
    cd ~/px4_colcon_ws/src
  2. Clone PX4-Autopilot
    git clone https://github.com/PX4/PX4-Autopilot.git --recursive
  3. Modify at least one entry of https://github.com/PX4/PX4-Autopilot/blob/main/src/modules/microdds_client/dds_topics.yaml such that the required message type belongs to px4 package instead of px4_msgs, for example VehicleOdometry
    diff --git a/src/modules/microdds_client/dds_topics.yaml b/src/modules/microdds_client/dds_topics.yaml
    index 3a871848bb..90506a5821 100644
    --- a/src/modules/microdds_client/dds_topics.yaml
    +++ b/src/modules/microdds_client/dds_topics.yaml
    @@ -36,7 +36,7 @@ publications:
         type: px4_msgs::msg::VehicleLocalPosition
    
       - topic: /fmu/out/vehicle_odometry
    -    type: px4_msgs::msg::VehicleOdometry
    +    type: px4::msg::VehicleOdometry
    
       - topic: /fmu/out/vehicle_status
         type: px4_msgs::msg::VehicleStatus
    the diff file adapt-dds_topic.patch.txt can be applied with git apply << adapt-dds_topic.patch.txt
  4. source the ros2 environment
    source /opt/ros/humble/setup.bash
  5. compile the workspace
    colcon build --symlink-install
  6. source the workspace
    source install/local_setup.bash
  7. It is now possible to list all message associated to the newly compiled px4 package
    ros2 interface package px4
    which will return something like
    px4/msg/InputRc
    px4/msg/HeaterStatus
    px4/msg/QshellRetval
    px4/msg/VehicleAngularVelocity
    px4/msg/Airspeed
    px4/msg/SensorGps
    .
    .
    .
  8. And it is possible to inspect the message definitions
    ros2 interface show px4/msg/Ping
    which will return
    uint64 timestamp			# time since system start (microseconds)
    uint64 ping_time			# Timestamp of the ping packet
    uint32 ping_sequence		# Sequence number of the ping packet
    uint32 dropped_packets		# Number of dropped ping packets
    float32 rtt_ms				# Round trip time (in ms)
    uint8 system_id				# System ID of the remote system
    uint8 component_id			# Component ID of the remote system
  9. However, when trying to create a prototype of any message
    ros2 interface proto px4/msg/Ping
    you will get the error
    Traceback (most recent call last):
      File "/opt/ros/humble/bin/ros2", line 33, in <module>
        sys.exit(load_entry_point('ros2cli==0.18.5', 'console_scripts', 'ros2')())
      File "/opt/ros/humble/lib/python3.10/site-packages/ros2cli/cli.py", line 89, in main
        rc = extension.main(parser=parser, args=args)
      File "/opt/ros/humble/lib/python3.10/site-packages/ros2interface/command/interface.py", line 35, in main
        return extension.main(args=args)
      File "/opt/ros/humble/lib/python3.10/site-packages/ros2interface/verb/proto.py", line 33, in main
        yaml = interface_to_yaml(args.type)
      File "/opt/ros/humble/lib/python3.10/site-packages/ros2interface/api/__init__.py", line 46, in interface_to_yaml
        interface = utilities.get_interface(identifier)
      File "/opt/ros/humble/lib/python3.10/site-packages/rosidl_runtime_py/utilities.py", line 23, in get_interface
        return import_message_from_namespaced_type(get_namespaced_type(identifier))
      File "/opt/ros/humble/lib/python3.10/site-packages/rosidl_runtime_py/import_message.py", line 30, in import_message_from_namespaced_type
        module = importlib.import_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 992, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
    ModuleNotFoundError: No module named 'px4'
  10. At the same time, if a simulation is started make px4_sitl gazebo, the microDDS agent enabled MicroXRCEAgent udp4 -p 8888, then all topics are available but they cannot be echoed.
    ros2 topic echo /fmu/out/vehicle_odometry
    will return the error
    The message type 'px4/msg/VehicleOdometry' is invalid

Expected behavior

The expected behavior can be easily seen using px4_msgs packages are message container and repeating all the above test with it. In particular,

ros2 interface proto px4_msgs/msg/TaskStackInfo

gives

"timestamp: 0
ping_time: 0
ping_sequence: 0
dropped_packets: 0
rtt_ms: 0.0
system_id: 0
component_id: 0
"

while echoing a topic gives the expected echo.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions