# Setting up micrortps bridge on VOXL2/Sentinel

Source: https://forum.modalai.com/topic/1580/setting-up-micrortps-bridge-on-voxl2-sentinel
Category: VOXL 2 and VOXL 2 Mini (https://forum.modalai.com/category/26/voxl-2-and-voxl-2-mini)
Tags: voxl-2
Posted: 2022-11-29 01:30:13 UTC by jaredjohansen
Replies: 14 · Views: 2972

## jaredjohansen · 2022-11-29 01:30:13 UTC

I'm trying to setup a `micrortps_bridge` (https://docs.px4.io/main/en/ros/ros2_comm.html) on a VOXL2/Sentinel.

On one side of the `micrortps_bridge`, I have a Docker container. 
This Docker container has Ubuntu 20.04, ROS2 foxy, a number of supporting libraries (e.g., gradle, Fast-DDS) and some custom ROS2 SW.  From within the Docker container, I am able to run the `micrortps_agent` and ROS2 SW.  It appears that everything on this side of the `micrortps_bridge` is working.

On the other side of the `micrortps_bridge` is the `micrortps_client`.  I am uncertain how to properly set this up on the VOXL2.  I found [this post](https://forum.modalai.com/topic/264/micrortps-setup-via-voxl_io) (which attempts to setup the bridge on the VOXL1 but had some issues) and [this post](https://docs.modalai.com/setup-ros-on-voxl-2/) (which sets up ROS1 on VOXL2).  Neither are quite what I am looking for.

I am wondering if there is any guidance on how to do setup a `micrortps_bridge` on the VOXL2.  @Eric-Katzfey, you were involved in the post from a year ago with @ryan_meagher and @benjamin-linne that attempted to get the `micrortps_bridge` working on VOXL1.  Is there any help/instructions/pointers you can give me?

## Reply by Eric Katzfey (ModalAI staff) · 2022-11-29 19:44:45 UTC

@jaredjohansen Actually, I don't see anything from me in that thread and, unfortunately, I have not worked with micrortps at all.

## Reply by jaredjohansen · 2022-11-29 19:49:50 UTC

Oops.  Sorry, @Eric-Katzfey!  I meant to say @Alex-Kushleyev.  

@Alex-Kushleyev, any help/instructions/pointers you can give?

## Reply by Alex Kushleyev (ModalAI staff) · 2022-11-29 20:37:26 UTC

@jacksparkman , sorry, but I have not used micrortps either. In the post you mentioned, i tried to provide help that is not specific to micrortps.

## Reply by jaredjohansen · 2022-11-30 03:37:43 UTC

Got it.  Thanks.  One more follow-up question.  

The VOXL1 had a tool called `voxl-px4-shell` that gave you [access to the PX4 console](https://docs.modalai.com/voxl-vision-px4-nuttx-shell/).  I don't see something like that for VOXL2.  Will that be a future capability?  If so, do you have an estimate on when it'd be available?  Thanks!

## Reply by modaltb (ModalAI staff) · 2022-11-30 17:07:26 UTC

Hi @jaredjohansen ,

You can, from the Ubuntu shell on VOXL2, run `px4-xxx` commands to invoke from command line (similar to voxl-px4-shell).

If you disable the voxl-px4 service from running on bootup, and run it manually, you can get an interactive shell, see this section:

https://docs.modalai.com/voxl-px4-developer-guide/#how-to-access-the-px4-shell-pxh

## Reply by jaredjohansen · 2022-11-30 17:25:32 UTC

Awesome.  That is super helpful!  I was able to follow those instructions and access the `pxh>` shell.

According to [these instructions](https://dev.px4.io/v1.11_noredirect/en/middleware/micrortps.html#client_firmware), if I have access to the NuttShell/System Console (`nsh>` shell, I believe), I should be able to start the `micrortps_client` running.

Is there a way to access the `nsh>` shell on the VOXL2?  

(For others, I'll note that the `nsh>` shell is available on the VOXL1, which is nice to simulate things like the GPS signal being lost [as described here.](https://docs.modalai.com/flying-without-gps/))

## Reply by jaredjohansen · 2022-12-02 18:10:23 UTC

@James-Strawson , I saw that you worked on the original [voxl-px4-shell](https://gitlab.com/voxl-public/voxl-sdk/services/voxl-vision-px4/-/blob/master/utils/voxl-px4-shell.c).

Do you know if there is a way to access the PX4's nuttx `nsh>` shell on the VOXL2?  

(For ROS2 to communicate with the PX4 on the VOXL2 through the `micrortps_bridge`, it is my understanding that I need to start the `micrortps_client` via the PX4 nuttx shell.)

## Reply by modaltb (ModalAI staff) · 2022-12-02 23:43:57 UTC

Hi @jaredjohansen ,

There's no nuttx on VOXL2, instead of the Nuttx RTOS, there's a QuRT RTOS instead.  So the shell you get above is it...  

For example `micrortps_client` would need to be enabled in and more than likely ported to work on VOXL2: https://github.com/modalai/px4-firmware/tree/voxl-dev/src/modules/micrortps_bridge

See this graphic for some help on orienting yourself:
  https://docs.modalai.com/voxl-px4-developer-guide/#block-diagram---details

This is where we are excluding that driver at this time:
  https://github.com/modalai/px4-firmware/blob/voxl-dev/boards/modalai/rb5-flight/default.cmake#L90

I've not used micrortps in anyway, so info above is just about how one could try to enable the driver and begin looking at porting it (assuming you want it on the ubuntu core (apps_proc))

## Reply by jaredjohansen · 2022-12-02 23:59:59 UTC

Thanks, @modaltb!  What you've pointed me to is very helpful!  I'll look into it!

## Reply by Kyungtaek Oh 0 · 2022-12-07 20:55:42 UTC

Hi @modaltb ,

I tried to build the voxl-px4 with the voxl-dev branch (which includes the micrortps_bridge).

1. On an Ubuntu 20.04 machine, we followed the steps in [VOXL 2 PX4 Build Guide](https://docs.modalai.com/voxl2-px4-build-guide/) to build the rb5-flight-px4-build-docker.  This was successful.
2. On the same machine, we `git cloned` the [voxl-px4](https://gitlab.com/voxl-public/voxl-sdk/services/voxl-px4) repository and `git updated` the submodules (of which `px4-firmware` is one of them).
3. Inside of the `voxl-px4` directory, we ran `./run_docker.sh`, which started the docker container and gave us a shell inside the docker container (at `/usr/local/workspace`).
4. Inside of the docker, at `/usr/local/workspace`, we installed fastrtpsgen (i.e., Fast-DDS, Fast-DDS-python, Fast-DDS-Gen).
5. We then ran the following commands:
```{r}
git clone px4-firmware
cd px4-firmware
git checkout voxl-dev
git submodule update --init --recursive
vi px4-firmware/board/modalai/rb5-flight/default.cmake
# Uncomment the micrortps_bridge at line 90
# save and exit
cd /usr/local/workspace
source /home/build-env.sh
./clean.sh 
./build.sh
```
This last step failed with two errors:

ERROR #1
```{r}
-- fastrtpsgen version 1.0.4
Traceback (most recent call last):
  File "/usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_classifier.py", line 233, in <module>
    else Classifier(os.path.join(msg_dir, args.yaml_file), msg_dir))
  File "/usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_classifier.py", line 55, in __init__
    self.check_if_listed(yaml_file)
  File "/usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_classifier.py", line 139, in check_if_listed
    raise AssertionError(
AssertionError: 
The following messages are not listen under  /usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_message_ids.yaml: imu_server, parameter_server_set_used_request, parameter_server_set_used_response, parameter_client_reset_response, mavlink, parameter_client_set_value_response, parameter_server_set_value_request, parameter_server_set_value_response, parameter_client_reset_request, parameter_client_set_value_request

Please add them to the yaml file with the respective ID and, if applicable, mark them to be sent or received by the micro-RTPS bridge.
NOTE: If the message has multi-topics (#TOPICS), these should be added as well.

CMake Error at src/modules/micrortps_bridge/CMakeLists.txt:58 (string):
  string sub-command FIND requires 3 or 4 parameters.

Traceback (most recent call last):
  File "/usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_classifier.py", line 233, in <module>
    else Classifier(os.path.join(msg_dir, args.yaml_file), msg_dir))
  File "/usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_classifier.py", line 55, in __init__
    self.check_if_listed(yaml_file)
  File "/usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_classifier.py", line 139, in check_if_listed
    raise AssertionError(
AssertionError: 
The following messages are not listen under  /usr/local/workspace/px4-firmware/msg/tools/uorb_rtps_message_ids.yaml: imu_server, parameter_server_set_used_request, parameter_server_set_used_response, parameter_client_reset_response, mavlink, parameter_client_set_value_response, parameter_server_set_value_request, parameter_server_set_value_response, parameter_client_reset_request, parameter_client_set_value_request

Please add them to the yaml file with the respective ID and, if applicable, mark them to be sent or received by the micro-RTPS bridge.
NOTE: If the message has multi-topics (#TOPICS), these should be added as well.

CMake Error at src/modules/micrortps_bridge/CMakeLists.txt:74 (string):
  string sub-command FIND requires 3 or 4 parameters.
```
We checked the uorb_rtps_message_ids.yaml which specifies the message’s id. It doesn't have the messages described in the error line.  Can you help us whether we should add these message_ids to the file (or remove them from elsewhere)?

ERROR #2
```
[ 45%] Built target rc
make[3]: Entering directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
Scanning dependencies of target lib__rc__rc_tests
make[3]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make[3]: Entering directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
[ 45%] Building CXX object src/lib/rc/rc_tests/CMakeFiles/lib__rc__rc_tests.dir/RCTest.cpp.o
/usr/local/workspace/px4-firmware/src/lib/rc/rc_tests/RCTest.cpp: In member function ‘bool RCTest::crsfTest()’:
/usr/local/workspace/px4-firmware/src/lib/rc/rc_tests/RCTest.cpp:96:88: error: too few arguments to function ‘uint32_t crsf_parse(uint64_t, const uint8_t*, unsigned int, uint16_t*, uint16_t*, uint16_t, uint8_t*, uint8_t*)’
   96 |    bool result = crsf_parse(now, frame, frame_len, rc_values, &num_values, max_channels);
      |                                                                                        ^
compilation terminated due to -Wfatal-errors.
make[3]: *** [src/lib/rc/rc_tests/CMakeFiles/lib__rc__rc_tests.dir/build.make:63: src/lib/rc/rc_tests/CMakeFiles/lib__rc__rc_tests.dir/RCTest.cpp.o] Error 1
make[3]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make[2]: *** [CMakeFiles/Makefile2:8186: src/lib/rc/rc_tests/CMakeFiles/lib__rc__rc_tests.dir/all] Error 2
make[2]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make[1]: *** [Makefile:152: all] Error 2
make[1]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make: *** [Makefile:222: modalai_rb5-flight_default] Error 2
```
We checked the crsf_parse and it requires two additional arguments, leading us to believe that we have mismatched code versions.  Can you help us know whether this is true (and if so, how we can bring all the SW versions into sync)?

For reference, the complete log from running `build.sh` can be found [here](https://www.notion.so/Build-sh-Log-71314c4927ed4f6796151838a24f758a)

## Reply by Eric Katzfey (ModalAI staff) · 2022-12-08 17:48:18 UTC (in reply to Kyungtaek Oh 0)

@Kyungtaek-Oh-0 First of all, https://docs.modalai.com/voxl2-px4-build-guide/ is not completely correct so sorry about that. We will update that today. But basically you need to prepare the Docker image which it looks like you did successfully. Then you need to build the PX4 code with these instructions: https://gitlab.com/voxl-public/voxl-sdk/services/voxl-px4/-/blob/dev/README.md. If you don't make any changes to default.cmake does that work for you?

## Reply by Kyungtaek Oh 0 · 2022-12-08 18:12:32 UTC

Thank you @Eric-Katzfey! That sound's great!

When I changed nothing including "default.cmake", it worked for me and it could run on voxl2.
The error only occurred when changing [default.cmake line 90](https://github.com/modalai/px4-firmware/blob/voxl-dev/boards/modalai/rb5-flight/default.cmake#L90).

## Reply by Eric Katzfey (ModalAI staff) · 2022-12-08 18:17:56 UTC (in reply to Kyungtaek Oh 0)

@Kyungtaek-Oh-0 Okay, that's not something any of us has tried yet.

## Reply by Kyungtaek Oh 0 · 2022-12-13 19:20:35 UTC

Hi @Eric-Katzfey, 
We had some finds.
Here's what we've understood so far:

1. Two things are needed to make a voxl-px4 package using px4-firmware(voxl-dev)
   * `modalai_rb5-flight_default`
   * `modalai_rb5-flight_qurt`
2. And each one needs the following different crsf_parse function 
   * `modalai_rb5-flight_default` needs `crsf_parse`(6 arguments)
   * `modalai_rb5-flight_qrut` needs `crsf_parse`(8 arguments)
3. Each px4-firmware has a different version of `crsf_parse`
   * Branch: main has `crsf_parse`(6 arguments)
   * Branch: voxl-dev has `crsf_parse`(8 arguments)

Our goal was to build the voxl-px4 included MicroRTPS_bridge in px4-firmware(branch: voxl-dev), so we added the following two functions to crsf.cpp in px4-firmware.
* `bool crsf_parse_buffer(uint16_t *values, uint16_t *num_values, uint16_t max_channels)`
   * as `crsf_parse_buffer_6`
* `bool crsf_parse(const uint64_t now, const uint8_t *frame, unsigned len, uint16_t *values, uint16_t *num_values, uint16_t max_channels)`
   * as `crsf_parse_6`

Then the build progressed to 89% and stopped with an error below.
**ERROR #1**
```
[ 89%] Building CXX object src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/pwm.cpp.o
/usr/local/workspace/px4-firmware/src/systemcmds/pwm/pwm.cpp: In function 'int pwm_main(int, char**)':
/usr/local/workspace/px4-firmware/src/systemcmds/pwm/pwm.cpp:810:3: error: 'qurt_loop' was not declared in this scope
  810 |   qurt_loop = 320;
      |   ^~~~~~~~~
compilation terminated due to -Wfatal-errors.
make[3]: *** [src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/build.make:63: src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/pwm.cpp.o] Error 1
make[3]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make[2]: *** [CMakeFiles/Makefile2:12085: src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/all] Error 2
make[2]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make[1]: *** [Makefile:152: all] Error 2
make[1]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make: *** [Makefile:222: modalai_rb5-flight_default] Error 2
```
We changed the `int qurt_loop` variable's scope to like this.
* Before
![32b86fac-1631-4048-b2ce-a29792ee533b-Untitled.png](https://forum.modalai.com/assets/uploads/files/1670957157167-32b86fac-1631-4048-b2ce-a29792ee533b-untitled.png) 
* After
![f6a25f03-3c63-4f66-92e4-b3181adacef6-Untitled (1).png](https://forum.modalai.com/assets/uploads/files/1670957171221-f6a25f03-3c63-4f66-92e4-b3181adacef6-untitled-1.png) 

After that, an error occurred for the label for jump, and it was resolved by changing it as follows.
**ERROR #2**
```
[ 89%] Building CXX object src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/pwm.cpp.o
/usr/local/workspace/px4-firmware/src/systemcmds/pwm/pwm.cpp: In function 'int pwm_main(int, char**)':
/usr/local/workspace/px4-firmware/src/systemcmds/pwm/pwm.cpp:864:1: error: jump to label 'err_out_no_test_2'
  864 | err_out_no_test_2:
      | ^~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
make[3]: *** [src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/build.make:63: src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/pwm.cpp.o] Error 1
make[3]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make[2]: *** [CMakeFiles/Makefile2:12085: src/systemcmds/pwm/CMakeFiles/systemcmds__pwm.dir/all] Error 2
make[2]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
make[1]: *** [Makefile:152: all] Error 2
make[1]: Leaving directory '/usr/local/workspace/px4-firmware/build/modalai_rb5-flight_default'
```
So we changed the `goto` command to "return 0" instead of using `err_out_no_test_2` label.

After that, the `build.sh` worked and the `make_packages.sh` also worked.(in the `voxl-px4`)
However, it did not run with the following error on voxl2.
**ERROR #3**
```
voxl2:~$ voxl-px4
Found DSP signature file
/usr/bin/voxl-px4: line 42: /usr/bin/px4: cannot execute binary file: Exec format error
```
Based on the above results, we think the voxl-px4 with microRTPS_bridge can be built by changing `modalai_rb5-flight_default` and `modalai_rb5-flight_qurt` to use the same `crsf_parse`.

So if you think our thinking is correct, can you give us some guidance?
If it is not possible in px4-firmware(branch: voxl-dev), can we build voxl-px4(included micrortps_bridge) using another branch?
Any advice would be appreciated.
