# Question on Custom Controller Implementation

Source: https://forum.modalai.com/topic/3092/question-on-custom-controller-implementation
Category: Development Drones (https://forum.modalai.com/category/44/development-drones)
Tags: sentinel
Posted: 2024-02-06 16:35:05 UTC by jmltt
Replies: 3 · Views: 662

## jmltt · 2024-02-06 16:35:05 UTC

I'm working with the Sentinel platform and I'm planning on testing a custom controller that runs in tandem with a deep learning model and I have some general questions about implementation.  I've modified the existing voxl-vision-hub to contain an additional offboard mode with a custom trajectory.  I want to also implement a custom controller that basically replaces the Position/Attitude controllers on PX4 and just feeds rate/thrust commands to PX4's rate controller.

1. Is implementing a controller as a separate thread within a new offboard mode in voxl-vision-hub a viable option or would I have to modify PX4 source code to edit the existing position/attitude controllers?  I saw there is a message struct in the mavlink API for sending rate/thrust commands directly to PX4 so I was planning on having the controller pull down the current state from the autopilot monitor in voxl-vision-hub for input the same way existing offboard modes do and output the rate thrust commands via mavlink the same way trajectory setpoints are sent.

2.  If I do have to modify PX4 source code, how would I go about doing that?  Can I just uninstall the px4 service from the sentinel, pull down the repo here https://gitlab.com/voxl-public/voxl-sdk/services/voxl-px4, swap the px4 submodule with an edited one, rebuild locally and push it back to sentinel?

3. Any general advice/warnings for custom controller implementation?

Any feedback is appreciated. Thanks!

## Reply by Moderator (ModalAI staff) · 2024-02-07 03:17:28 UTC

@josephmlullo Here is how to build PX4 for VOXL 2 https://docs.modalai.com/voxl-px4-dev-build-guide/

## Reply by Moderator (ModalAI staff) · 2024-02-07 03:19:45 UTC (in reply to Moderator)

On this branch you can see how to control the attitude for PX4 in offboard_mode just from the CPU https://gitlab.com/voxl-public/voxl-sdk/services/voxl-vision-hub/-/blob/dev_attitude_target/src/offboard_manual.c?ref_type=heads

Please note, this is development code and we do not support it in any way. you are on your own when implementing your own controller

## Reply by Eric Katzfey (ModalAI staff) · 2024-02-07 15:55:09 UTC

@josephmlullo The build environment for px4 is within a Docker container. You can find the instructions on how to create this Docker image here: https://gitlab.com/voxl-public/rb5-flight/rb5-flight-px4-build-docker
