# ROS2 to MPA

Source: https://forum.modalai.com/topic/3559/ros2-to-mpa
Category: VOXL SDK and Software (https://forum.modalai.com/category/47/voxl-sdk-and-software)
Tags: ros
Posted: 2024-06-17 22:28:31 UTC by jmltt
Replies: 4 · Views: 1430

## jmltt · 2024-06-17 22:28:31 UTC

Has anybody implemented something similar to voxl_mpa_to_ros2 that provides data flow in the opposite direction, like subscribing to the uorb topics published by px4 and exposed via ros2 topics and re-publishing them for onboard use over of the MPA? If so would you be able to point me to example code?

I'm brand new to ROS/ROS2 so I'm still trying to run through tutorials and figure out how it all works

Thanks!

## Reply by Alex Kushleyev (ModalAI staff) · 2024-06-21 15:21:48 UTC

@jmltt , we have not done this yet. Can you please provide an example of a use case for this functionality? What kind of data would you want to send to VOXL2 via ROS and publish locally on VOXL2 via MPA?

Alex

## Reply by jmltt · 2024-06-26 14:57:38 UTC (in reply to Alex Kushleyev)

@Alex-Kushleyev the only immediate need I have for this is to subscribe to the vehicle_local_position topic and republish it for use in an offboard controller i'm testing that requires a state estimate for feedback that includes filtered acceleration (PX4 only streams the truncated local position ned data over mavlink).  I want to transition from mavlink to ROS-based offboard communications in general though in case there are some random uorb topics I end up needing data from that aren't supported over mavlink.

I don't think there's a wide general need for this, but I need to learn how to do it and since I've never used ROS before I was hoping there was some example code I could look at.  I'm sure I can figure it out though looking at the existing voxl-mpa-to-ros2 code

## Reply by Alex Kushleyev (ModalAI staff) · 2024-06-26 17:01:17 UTC (in reply to jmltt)

@jmltt ,

The mpa publisher functionality is pretty easy:
- create a new pipe using `pipe_server_create` - you need to provide the information about the data you are sending. 
  - https://gitlab.com/voxl-public/voxl-sdk/core-libs/libmodal-pipe/-/blob/master/library/include/modal_pipe_server.h?ref_type=heads#L110
- publish the data using `pipe_server_write` : https://gitlab.com/voxl-public/voxl-sdk/core-libs/libmodal-pipe/-/blob/master/library/include/modal_pipe_server.h?ref_type=heads#L188
- note that for some data types like images, there are functions like `pipe_server_write_camera_frame` which allow you to publish the image and the metadata in a single call.
- also note that you can only publish the supported data types, listed here : https://gitlab.com/voxl-public/voxl-sdk/core-libs/libmodal-pipe/-/blob/master/library/include/modal_pipe_interfaces.h

A simple example of the publisher is embedded into this tool, which creates an ascii version of the image and publishes some stats via mpa: https://gitlab.com/voxl-public/voxl-sdk/utilities/voxl-mpa-tools/-/blob/master/tools/voxl-inspect-cam-ascii.cpp?ref_type=heads#L258 . Please note, in this example the code uses pipe channel 0 when creating the pipe - it is better to use `pipe_server_get_next_available_channel()` to get the ID of the channel and then use it when publishing.

Alex

## Reply by tahawaru · 2024-10-22 13:33:43 UTC (in reply to Alex Kushleyev)

@Alex-Kushleyev 

Please could you provide a simple example like arm() and disarm() or something similar to the offboard_control.cpp?

Best wishes,
