# How to realize control allocation with BlueROV?

**URL:** <https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283>\
**Category:** Blue Robotics Software\
**Tags:** ardusub, pymavlink\
**Created:** [January 4, 2022, 3:02pm UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283 "2022-01-04T15:02:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lili\_Marleen](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Lili\_Marleen](https://discuss.bluerobotics.com/u/Lili_Marleen)\
**Post date:** [January 4, 2022, 3:02pm UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/1 "2022-01-04T15:02:15Z")

</div>

Hello everyone,  
I have been trying to automatically control the vehicle, to make it track a certain trajectory. This needs to be done with modelling and controller design and so on. I have studied this thesis [https://flex.flinders.edu.au/file/27aa0064-9de2-441c-8a17-655405d5fc2e/1/ThesisWu2018.pdf](https://flex.flinders.edu.au/file/27aa0064-9de2-441c-8a17-655405d5fc2e/1/ThesisWu2018.pdf)

The author had explained his way of control allocation, that is, to manipulate each thruster directly, but I am not sure how he did it in terms of coding, did he use Ardusub framework?  
And most of the research on motion control of AUV base on decoupled thrust control. I would assume it is almost necessary to seperate every thrust to do my project.  
All in all, is there a way of independently control each thruster of the BlueROV2?

———————————————————————  
update:  
I was somehow convinced before, that Ardusub cannot operate thrusters seperately, but is this the MAVlink command to do so? [Pymavlink · GitBook](https://www.ardusub.com/developers/pymavlink.html#set-servo-pwm)

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [January 5, 2022, 10:02pm UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/2 "2022-01-05T22:02:54Z")

</div>

Hi @Lili_Marleen,

This comment addresses most of your post, but feel free to ask follow-ups if you want some extra information on anything in particular 🙂

> [@Pymavlink outputs PWM to the motor](https://discuss.bluerobotics.com/t/pymavlink-outputs-pwm-to-the-motor/11053/3):
>
> Hi @Teshla, welcome to the forum slight_smile The [MAV\_CMD\_DO\_SET\_SERVO](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_SERVO) command only applies to non-motor outputs. If a PWM output is assigned as a motor then you won’t be able to control it as a servo. Control of individual thrusters with a single message isn’t possible with the current MAVLink specification, but there are some [workarounds for it discussed here](https://discuss.bluerobotics.com/t/how-to-control-thrusters-independently/9870/11) if you’re interested. Is there a particular reason you want/need to control individual thrusters? Generally control is simpler when …

---

<div class="post-metadata">

**Author:** ![Lili\_Marleen](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Lili\_Marleen](https://discuss.bluerobotics.com/u/Lili_Marleen)\
**Post date:** [January 6, 2022, 8:40am UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/3 "2022-01-06T08:40:25Z")

</div>

We would like to keep the auv away from an underwater column with a certain distance. The auv should rotate around the column while always facing it, with camera estimating the distance between the auv and column. We are simulating the scenario where the auv navigates around and examines underwater facilities in water tanks.

My persistence with independently controlling comes from the papers of controlling, most of them I believe bases on seperate thrusters. Especially, [https://flex.flinders.edu.au/file/27aa0064-9de2-441c-8a17-655405d5fc2e/1/ThesisWu2018.pdf](https://flex.flinders.edu.au/file/27aa0064-9de2-441c-8a17-655405d5fc2e/1/ThesisWu2018.pdf) mentioned control allocation.

However, precision would not be too strict with out project. We plan to deploy PID control, and the idea was enlightened with this series of videos: [Drone Simulation and Control, Part 2: How Do You Get a Drone to Hover? - YouTube](https://www.youtube.com/watch?v=GK1t8YIvGM8)

I find it really hard to seek some straightforward tutorial regarding ROV/AUV motion control. The algorithms in those cutting-edge research are very fancy, but we simply don’t know how to implement. They don’t mention any coding detail in most cases.

---

<div class="post-metadata">

**Author:** ![Lili\_Marleen](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Lili\_Marleen](https://discuss.bluerobotics.com/u/Lili_Marleen)\
**Post date:** [January 6, 2022, 9:45am UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/4 "2022-01-06T09:45:08Z")

</div>

I would eagarly try to find out a few things, mostly related to how to command with Mavlink

1. [Offboard Control · MAVLink Developer Guide](https://mavlink.io/en/guide/offboard_control.html)  
this link says “send low-level and high-level attitude, velocity or position commands to the vehicle.” is available, is there more details?

2. [Pymavlink · GitBook](http://www.ardusub.com/developers/pymavlink.html#change-flight-mode)  
How many filght modes are there? Can we configure each mode`s thruster speed, or vehicle velocity?

3. [Pymavlink · GitBook](http://www.ardusub.com/developers/pymavlink.html#send-rc-joystick)  
What are the channels here specifically? What does it mean by commenting “# Set some yaw”

Thank you a lot! I find these are fundamental for carrying out my project!

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [January 7, 2022, 12:47am UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/5 "2022-01-07T00:47:56Z")

</div>

> [@Lili\_Marleen](#):
>
> My persistence with independently controlling comes from the papers of controlling, most of them I believe bases on seperate thrusters. Especially, [https://flex.flinders.edu.au/file/27aa0064-9de2-441c-8a17-655405d5fc2e/1/ThesisWu2018.pdf](https://flex.flinders.edu.au/file/27aa0064-9de2-441c-8a17-655405d5fc2e/1/ThesisWu2018.pdf) mentioned control allocation.

Individual thruster control is required for vehicle control (understandably), but that isn’t necessarily the level you want to work at. ArduSub (and more generally the whole ArduPilot project) is made for doing that, with the intent that it abstracts the control for the user/operator. Instead of commanding individual thrusters users can instead control the motion of the vehicle (i.e. you can send a command for “go to this yaw angle”, and it should work for several different ArduPilot vehicles if they have their frames set up correctly - they could be different vehicle frames, and even different vehicle types, it shouldn’t matter for the user’s control). If positioning information is available to the vehicle the control can be abstracted one level further, with commands like “follow a path and go through this set of waypoints”.

> [@Lili\_Marleen](#):
>
> However, precision would not be too strict with out project. We plan to deploy PID control, and the idea was enlightened with this series of videos: [Drone Simulation and Control, Part 2: How Do You Get a Drone to Hover? - YouTube](https://www.youtube.com/watch?v=GK1t8YIvGM8)

Low level control like this is already implemented in ArduSub, but unfortunately we don’t yet have documentation on the ArduSub-specific implementation that I can point you to. The closest thing is the ArduCopter [Attitude Control docs](https://ardupilot.org/dev/docs/apmcopter-programming-attitude-control-2.html).

Note also that ArduSub vehicles aren’t the same as quadcopters. In your video link it’s discussing pitch and roll requirements for horizontal translation, but in ArduSub that’s instead accomplished with horizontally oriented thrusters that can push the vehicle sideways/forwards without affecting the vehicle rotation in the same way.

> [@Lili\_Marleen](#):
>
> 1. [Offboard Control · MAVLink Developer Guide](https://mavlink.io/en/guide/offboard_control.html)  
> this link says “send low-level and high-level attitude, velocity or position commands to the vehicle.” is available, is there more details?

I haven’t heard of that interface, so I’m not sure whether it’s well established and just poorly documented, or whether it’s in the process of being developed, or perhaps just an expression of the general idea that control instructions don’t need to come from the flight controller.

ArduSub vehicles use [directional control](https://mavlink.io/en/services/manual_control.html#directional-control), which can be specified with either [MANUAL\_CONTROL](https://mavlink.io/en/messages/common.html#MANUAL_CONTROL) or [RC\_CHANNELS\_OVERRIDE](https://mavlink.io/en/messages/common.html#RC_CHANNELS_OVERRIDE) MAVLink messages. Unfortunately the optional `s` and `t` axis fields in MANUAL\_CONTROL are very new and not yet available in ArduSub, so to specify commands for all 6 DoF at once requires using RC\_CHANNELS\_OVERRIDE.

> [@Lili\_Marleen](#):
>
> 1. [Pymavlink · GitBook](http://www.ardusub.com/developers/pymavlink.html#change-flight-mode)  
> How many filght modes are there? Can we configure each mode`s thruster speed, or vehicle velocity?

The flight modes are specified [here](https://www.ardusub.com/reference/ardusub/joystick-setup-page.html#mode-selection), and the ones that take motion control rather than position controls are described in the “Roll and Pitch Control” section. There are additional descriptions in the [ArduCopter docs](https://ardupilot.org/copter/docs/flight-modes.html), along with descriptions of several modes that don’t exist in ArduSub.

I don’t believe there are any modes that directly command vehicle velocity (so you may need to make a velocity controller if consistent velocity is important to you), but manual mode controls rotation rates and translational thrust, stabilise mode controls rotation angles and translational thrust, and depth hold mode is the same as stabilise but controls to a set depth.

Note that accurate velocity control requires an accurate position/velocity sensor, like a DVL or underwater GPS system. The vehicle can report a current velocity estimate, from integrating the IMU accelerometer values, but that value is prone to drift due to error buildup.

> [@Lili\_Marleen](#):
>
> 1. [Pymavlink · GitBook](http://www.ardusub.com/developers/pymavlink.html#send-rc-joystick)  
> What are the channels here specifically? What does it mean by commenting “# Set some yaw”

These are the [RC Input Channels](https://www.ardusub.com/developers/rc-input-and-output.html). By default channel 4 is for yaw control, so that comment is specifying that some yaw action is controlled. Values are between 1100 and 1900, where 1500 is stopped, 1900 is full positive, and 1100 is full negative. The effect of the specified value(s) will depend on the flight mode, [joystick/pilot input gain](https://www.ardusub.com/reference/ardusub/features-while-in-operation.html#pilot-input-gain), and potentially also [the `RC3_*` parameters if you’ve changed them](https://discuss.bluerobotics.com/t/raspberry-and-pixhawk-shutdown-problem/10814/2).

It may be helpful to refer to [this gist](https://gist.github.com/ES-Alexander/ee1dd479dd728b7cef1bf936f9114e71#file-rc_override_example-py) that I made last year as an example of a full pymavlink program, that hopefully makes understanding the setup and control a bit easier/more intuitive. I unfortunately haven’t yet had a chance to transfer those components to our documentation examples.

---

<div class="post-metadata">

**Author:** ![Lili\_Marleen](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Lili\_Marleen](https://discuss.bluerobotics.com/u/Lili_Marleen)\
**Post date:** [March 30, 2022, 9:05am UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/6 "2022-03-30T09:05:33Z")

</div>

> If positioning information is available to the vehicle the control can be abstracted one level further, with commands like “follow a path and go through this set of waypoints”.

could you please tell me where to find these commands, about “go through this set of waypoints”?

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [March 30, 2022, 10:39am UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/7 "2022-03-30T10:39:19Z")

</div>

The main advice is this:

> [@Go to Waypoint & Follow Terrain via pymavlink](https://discuss.bluerobotics.com/t/go-to-waypoint-follow-terrain-via-pymavlink/2599/2):
>
> The autonomous/gps enabled modes are not stable, but have been demonstrated. They are basically for developer use only right now, so there is not a lot of information and you will need to look at the source code to see exactly how it works. You should be able to use auto mode for the way points …

Beyond that, these links may be relevant

- [Set waypoints via pymavlink](https://discuss.bluerobotics.com/t/set-waypoints-via-pymavlink/8716)
- [Guided Mode — Copter documentation](https://ardupilot.org/copter/docs/ac2_guidedmode.html)
- [Auto Mode — Copter documentation](https://ardupilot.org/copter/docs/auto-mode.html)

It’s also worth noting that ArduSub \>= 4.1 has support for [visual odometry](https://ardupilot.org/copter/docs/parameters.html#viso-parameters), which is what we’ve used for [DVL integration](https://www.ardusub.com/developers/dvl-integration.html#ardusub-firmware).

---

<div class="post-metadata">

**Author:** ![rezenders](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@rezenders](https://discuss.bluerobotics.com/u/rezenders)\
**Post date:** [May 6, 2022, 1:51pm UTC](https://discuss.bluerobotics.com/t/how-to-realize-control-allocation-with-bluerov/11283/8 "2022-05-06T13:51:01Z")

</div>

Sorry to bump in the conversation, but I think it is worth mentioning that if you plan to use ROS you can also use the [MAVROS](http://wiki.ros.org/mavros) package to send those commands.

By the way, how is your project going? If it is an open/public project I would be interested in taking a look into it 🙂
