Is it possible to adapt at runtime the motors contribution to the 6DOF?

Hello,

I am working on a project to enable underwater robots to adapt at runtime, and I am using a BlueROV as testbed.

My goal now is to simulate thruster failures. For this, my plan is to deactivate thrusters at runtime, and to react to it by changing the robot frame configuration. I have two questions related to this:

  1. Is it possible to change at runtime the motors contribution to the 6DOF? For instance, can I set motor 1 to have 0 contribution to all factors?
  2. If the awnser to question 1 is no, can I change the frame that is being used at runtime? For instance, I could create extra custom frames with motors having 0 contribution to all 6DOF and switch to them when a thruster fail.
  3. If the awnser to question 1 and 2 are no, is it possible to easily switch the frame and reboot ArduSub for the changes to take effect?

PS: Initially I will be doing this with SITL + Ignition, so I am open to hacks for now. But in the future the goal is to actually apply this to the real BlueROV

Thanks in advance!

Hi @rezenders, interesting question :slight_smile:

There is currently no general way to dynamically change the frame, although it is something we’re interested in making possible.

That said, given you’re specifically trying to simulate failures, you should be able to achieve an equivalent result by just disabling the output for the motor you want to “fail”. You can do that by setting the relevant SERVOn_FUNCTION parameter from Motor{n} to Disabled (0), which you can either set in QGC, or set directly with MAVLink (e.g. using a Pymavlink script). If you have a separate MAVLink endpoint set up for it you can even use a pymavlink script while QGroundControl is connected to the standard endpoint (e.g. to simulate a sudden live failure).

Just for completeness, yes, it is possible to switch between frames in ArduSub via QGroundControl (or just setting the FRAME_CONFIG parameter) and then rebooting, but the parameter is only set up to have a single custom frame, so to have several options you can switch between you would need to either replace some of the other existing frames or go to some extra effort enabling a larger number of frame options.

1 Like

Thanks for the reply @EliotBR

You can do that by setting the relevant SERVOn_FUNCTION parameter from Motor{n} to Disabled (0),

Thanks, I will do that. One more question, does the motion controller takes this into account in order to calculate the required thrust? Probably not, right? For my use case, it would be better if it does not take into account and the movement goes “bad”. Then I can switch to a different frame and ideally the movement would be “better”.

Just for completeness, yes, it is possible to switch between frames in ArduSub via QGroundControl (or just setting the FRAME_CONFIG parameter) and then rebooting, but the parameter is only set up to have a single custom frame, so to have several options you can switch between you would need to either replace some of the other existing frames or go to some extra effort enabling a larger number of frame options.

Ok. I will go with one frame for now, considering that only one specific thruster can fail and then when I get it working I can check how to expand to more scenarios.

There is currently no general way to dynamically change the frame, although it is something we’re interested in making possible.

Is this something that would require a lot of knowledge about how Ardupilot/ArduSub works? I could pottentialy help with this, but so far I only have knowledge from the user side.

Just to let you know, I am not using QGC, I am using ROS + mavros to command the robot. The idea is that this whole process happens autonomously.

Hi @rezenders,

Check out the new lua motors backend that Peter Hall has been pushing. I suspect it would suit your needs.
I don’t really know how much work it would take to get it running, but it should suit your needs.

1 Like

Thanks for the reply @williangalvani.

I guess the lua script should be something like this, right?

I have a few questions:

  1. Does this line mean that the Motor_dynamic methods can only be used with ArduPlane, Copter or Heli?
  2. If I use a Lua script like this to set the motors contributions, do I need to somehow deactivate the original setup that is done here?
  3. I have some doubts about using lua scripts (not sure if this is the right place for this), are the lua scripts executed automatically when ardupilot starts?
  4. Is it possible to interact with the lua scripts from different codes? For instance, can I send a msg with information to the lua script from a python/c++ code?

By the way, if anyone has come across this post and is looking for more information, check this link

Yes. this is not currently supported in Sub, but I’m keen on having this feature.

That is most likely correct. There is a new Motors6dof_scripting backend that we’ll need to use.
I think this is they Key PR implementing the feature (I also highlighted the area responsible for enabling the backend):

Yes, I think there are a couple ways. The easier one is to add parameters created by the scripting interface itself.
You can, for example, create a param MY_ROLL to control roll target.

Hi @williangalvani,

Sorry for the delay to reply. I had other tasks in hand and I wanted to spend some time checking ArduPilot code to better understand what you sent.

I made some simplified Class and Activity diagrams with the relevant information for both ArduSub and ArduCopter to better communicate what I understood.

ArduSub:

ArduCopter:

So, in order to add this feature to Sub the steps are:

  1. Change AP_Motors6DOF motors to AP_MotorsMultiCopter *motors
  2. Add an allocate_motors method to Sub
  3. Call allocate_motors method before init_rc_out
  4. Add lua script to add the motors

In 3, the allocate_motors should set motors to be an AP_Motors6DOF when scripting is not enabled, and AP_MotorsMatrix_6DoF_Scripting when scripting is enabled.

Does this seem correct? Did I miss anything? I would like to implement this, should I open a draft PR in ArduPilot, and we continue the discussion there?

I have been trying to work in this feature but I got stuck.
I opened a draft PR to discuss it: [ArduSub] Add scripting support to motors by Rezenders · Pull Request #22114 · ArduPilot/ardupilot · GitHub

Do you have any idea/tips for me?

Hi @rezenders ,

I’m not that familiar with that section of the code, but I’ll give it a go, too.

@rezenders I’ll get in touch with you privately so we can work on this together

1 Like