ArduPilot / ardupilot

ArduPlane, ArduCopter, ArduRover, ArduSub source
http://ardupilot.org/
GNU General Public License v3.0
11.09k stars 17.66k forks source link

AP_DDS: Investigate running microROS client library #23424

Open Ryanf55 opened 1 year ago

Ryanf55 commented 1 year ago

Feature request

Is your feature request related to a problem? Please describe. Ardupilot parameters would like to be exposed through the ROS 2 parameter server, but it's not clear how to do it.

Describe the solution you'd like Conduct a prototype on SITL with the microROS agent to determine if ArduPilot can use it. If so, see if we can add chibiOS support for it, as well as specific hardware. It may be best to start on the ESP32 hardware since that's an already supported configuration.

[ ] Add microROS agent as a new module dependency [ ] Add a configure option to enable microROS client library instead of xrce client library [ ] Add the necessary waf hooks to build the client library into Ardupilot FW [ ] Implement the corresponding functions in AP_DDS to expose a few parameters in Ardupilot [ ] Check the flash cost of the library [ ] Check the CPU cost of the library

Describe alternatives you've considered

@arshPratap is considering using an integration service through eProsima and exposing params as a ROS service

Platform [x ] All [ ] AntennaTracker [ ] Copter [ ] Plane [ ] Rover [ ] Submarine

Additional context

https://design.ros2.org/articles/ros_parameters.html

This ticket is research for #23309

Recommendations from Tridge

See ardupilot ftp mavproxy sys/memory.txt , `see @SYS virtual filesystem to evaluate.

Really, should just try microROS parameter service as-is.

srmainwaring commented 1 year ago

micro-ROS PoC

Initial investigations into using micro-ROS directly in ArduPilot:

The branch provides an example of ArduPilot hosting a micro-ROS client.

Features

Notes:

Dependencies

A customised version of the micro_ros_setup project is used to create a custom static micro-ROS library

The main changes are:

After following the initial steps to configure the workspace and build micro_ros_setup, the create_firmware_ws and build_firmware steps are:

ros2 run micro_ros_setup create_firmware_ws.sh generate_lib generic
ros2 run micro_ros_setup build_firmware.sh -f -- $(pwd)/src/micro_ros_setup/config/generate_lib/generic/demo_toolchain.cmake $(pwd)/src/micro_ros_setup/config/generate_lib/generic/client-colcon.meta

The contents of the folder ~ws/firmware/build are copied to ~/ardupilot/libraries/AP_UROS/uros.

Build

Build directly using waf:

./waf configure --boards sitl --enable-uros
./waf build --enable-uros

Build using colcon:

colcon build --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo --packages-select ardupilot_sitl

Run

If you have a ros-ardupilot environment set up the various components may be launched separately:

micro-ROS agent:

ros2 launch ardupilot_sitl micro_ros_agent.launch.py transport:=udp4 port:=2019 verbose:=6

SITL:

ros2 launch ardupilot_sitl sitl.launch.py synthetic_clock:=True wipe:=False model:=quad speedup:=1 slave:=0 instance:=0 defaults:=$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/default_params/copter.parm,$(ros2 pkg prefix ardupilot_sitl)/share/ardupilot_sitl/config/default_params/dds_udp.parm

Non-interactive MAVProxy:

ros2 launch ardupilot_sitl mavproxy.launch.py master:=tcp:127.0.0.1:5760 sitl:=127.0.0.1:5501

MAVProxy console:

mavproxy.py --console

Figure: micro-ROS client initialisation

ap-uros-init
ros2 node list
/ardupilot_uros
ros2 node info /ardupilot_uros
/ardupilot_uros
  Subscribers:
    /geometry_msgs_msg_Vector3: geometry_msgs/msg/Vector3
  Publishers:

  Service Servers:

  Service Clients:

  Action Servers:

  Action Clients:
os2 topic pub /geometry_msgs_msg_Vector3 geometry_msgs/msg/Vector3 "{x: 1.1, y: 2.2, z : 3.3}" --rate 1
publisher: beginning loop
publishing #1: geometry_msgs.msg.Vector3(x=1.1, y=2.2, z=3.3)

publishing #2: geometry_msgs.msg.Vector3(x=1.1, y=2.2, z=3.3)

publishing #3: geometry_msgs.msg.Vector3(x=1.1, y=2.2, z=3.3)

Figure: micro-ROS client subscriber

ap-uros-sub

Flash

A comparison of flash for master and builds with DDS and UROS enabled.

Base:

BUILD SUMMARY
Build directory: /Users/rhys/Code/ros2/humble/ros2-ardupilot/src/ardupilot/build/sitl
Target               Text (B)  Data (B)  BSS (B)  Total Flash Used (B)  Free Flash (B)  External Flash Used (B)
---------------------------------------------------------------------------------------------------------------
bin/antennatracker    1769472    196608        0               1966080  Not Applicable  Not Applicable         
bin/arducopter        2392064    229376        0               2621440  Not Applicable  Not Applicable         
bin/arducopter-heli   2392064    229376        0               2621440  Not Applicable  Not Applicable         
bin/arduplane         2342912    212992        0               2555904  Not Applicable  Not Applicable         
bin/ardusub           2097152    212992        0               2310144  Not Applicable  Not Applicable         
bin/blimp             1802240    196608        0               1998848  Not Applicable  Not Applicable         
bin/ardurover         2179072    212992        0               2392064  Not Applicable  Not Applicable

DDS:

BUILD SUMMARY
Build directory: /Users/rhys/Code/ros2/humble/ros2-ardupilot/src/ardupilot/build/sitl
Target               Text (B)  Data (B)  BSS (B)  Total Flash Used (B)  Free Flash (B)  External Flash Used (B)
---------------------------------------------------------------------------------------------------------------
bin/antennatracker    1851392    196608        0               2048000  Not Applicable  Not Applicable         
bin/arducopter        2473984    229376        0               2703360  Not Applicable  Not Applicable         
bin/arducopter-heli   2473984    229376        0               2703360  Not Applicable  Not Applicable         
bin/arduplane         2441216    212992        0               2654208  Not Applicable  Not Applicable         
bin/ardusub           2195456    212992        0               2408448  Not Applicable  Not Applicable         
bin/blimp             1884160    196608        0               2080768  Not Applicable  Not Applicable         
bin/ardurover         2277376    212992        0               2490368  Not Applicable  Not Applicable

UROS:

BUILD SUMMARY
Build directory: /Users/rhys/Code/ros2/humble/ros2-ardupilot/src/ardupilot/build/sitl
Target               Text (B)  Data (B)  BSS (B)  Total Flash Used (B)  Free Flash (B)  External Flash Used (B)
---------------------------------------------------------------------------------------------------------------
bin/antennatracker    1867776    278528        0               2146304  Not Applicable  Not Applicable         
bin/arducopter        2490368    294912        0               2785280  Not Applicable  Not Applicable         
bin/arducopter-heli   2490368    294912        0               2785280  Not Applicable  Not Applicable         
bin/arduplane         2457600    294912        0               2752512  Not Applicable  Not Applicable         
bin/ardusub           2211840    278528        0               2490368  Not Applicable  Not Applicable         
bin/blimp             1900544    278528        0               2179072  Not Applicable  Not Applicable         
bin/ardurover         2293760    294912        0               2588672  Not Applicable  Not Applicable         

The UROS build has rmw_microxrcedds configured as follows:

        "rmw_microxrcedds": {
            "cmake-args": [
                "-DCMAKE_BUILD_TYPE=RelWithDebInfo",
                "-DRMW_UXRCE_TRANSPORT=custom",
                "-DRMW_UXRCE_DEFAULT_UDP_IP=127.0.0.1",
                "-DRMW_UXRCE_DEFAULT_UDP_PORT=2019",
                "-DRMW_UXRCE_MAX_NODES=15",
                "-DRMW_UXRCE_MAX_PUBLISHERS=15",
                "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=15",
                "-DRMW_UXRCE_MAX_SERVICES=15",
                "-DRMW_UXRCE_MAX_CLIENTS=15",
                "-DRMW_UXRCE_STREAM_HISTORY=32",
                "-DRMW_UXRCE_MAX_HISTORY=10"
            ]
        }

Next steps

Update

Custom transport

The rmw_microxrcedds library exports a structure rmw_uxrce_transport_default_params when RMW_UXRCE_TRANSPORT=custom. This symbol was appearing in the common block:

nm -g -P libmicroros.a | grep rmw_uxrce_transport_default
_rmw_uxrce_transport_default_params C 38 0

and was failing to link in the waf build. Initialising this with:

rmw_uxrce_transport_params_t rmw_uxrce_transport_default_params = {};

results in the symbol being moved to S

nm -g -P libmicroros.a | grep rmw_uxrce_transport_default
_rmw_uxrce_transport_default_params S 1d78 0

and the waf build links.

Change in: https://github.com/srmainwaring/rmw_microxrcedds/tree/prs/prs-humble-fix-custom-transport-linking

micro-ROS client library binaries

Prebuilt binaries and generated includes for macOS, Ubuntu and esp32:

To use: unzip to <ardupilot>/libraries/AP_UROS.