ArduPilot / ardupilot_gazebo

Plugins and models for vehicle simulation in Gazebo Sim with ArduPilot SITL controllers
GNU Lesser General Public License v3.0
82 stars 78 forks source link

Add feature / plugin for parachute testing #33

Closed 41Mo closed 1 year ago

41Mo commented 1 year ago

Feature request

It would be nice to be able to test parachute release with gazebo.

We could make something similar px4 gazebo plugins already have this feature, but for gazebo-classic

I have made my own implementation, but its poorly written ParachutePlugin.cc

Platform [ ] All [ ] AntennaTracker [ ✓ ] Copter [ ✓ ] Plane [ ] Rover [ ] Submarine

srmainwaring commented 1 year ago

@41Mo, if you rebase your topic branch https://github.com/41Mo/ardupilot_gazebo/tree/parachute on main I'd be happy to work on this with you. It would be great to expand the range of ArduPilot features available in Gazebo.

Not a hard requirement, but if you could name your topic branches:

<username>/topic (eg. 41Mo/parachute)

that helps keep things organised on my side when I pull your branch in for review.

Edit

Rebased version here - https://github.com/srmainwaring/ardupilot_gazebo-1/tree/41Mo/parachute

srmainwaring commented 1 year ago

Initial thoughts:

  1. ArduPilotPlugin.cc

We can reuse the existing COMMAND control type for the parachute deployment. This was added to forward PWM levels onto the thruster plugin for a ROV, but I think we can use the same approach here rather than add a new command type and additional fields to the <control> element. The parachute plugin would then decide how to interpret the forwarded PWM level (i.e. high for deploy or whatever).

The following would send the output of SERVO5 onto zephyr/parachute/deploy:

<plugin name="ArduPilotPlugin" filename="libArduPilotPlugin">
  ...   
  <control channel="4">
    ...
    <type>COMMAND</type>
    <cmd_topic>zephyr/parachute/deploy</cmd_topic>
    ...
  </control>
</plugin>
  1. ParachutePlugin.cc

It may not scale well having this plugin attached to the world. The parachute is attached to a model, so the plugin should be too. Still working through the implementation details so will update this section in due course...

41Mo commented 1 year ago

I completely agree. I originally created this as a POC, and my knowledge with gazebo plugins is not good enough. When you will be ready with your thoughts i can create a draft pr. Or if the whole implementation will be drastically changed you can create a PR and I will try to be helpful

srmainwaring commented 1 year ago

It looks like a good start - I don't think the COMMAND type was there when you developed the plugin.

I'll experiment with what you've done to see if I can get the plugin localised to a model. Would you mind jotting down some instructions how to run an example - I'm not familiar with the parachute deployment function in ArduPilot. A list of terminal and mavproxy commands would be a great help.

srmainwaring commented 1 year ago

@41Mo, I have a slightly modified version of your plugin running - it's very nice! Great work with the detachable joints.

I've made a few cosmetic changes - mainly moving implementation details into a private class in the C++ file and some formatting details to keep cpplint happy.

Next steps:

Figure: Initial version of parachute plugin. Parachute pose is not correct, but model is being created on manual trigger and parachute drag is apparent.

https://user-images.githubusercontent.com/24916364/208252069-ec8898f8-65d9-4cbc-9ff3-a4a28fd7d907.mov

41Mo commented 1 year ago

Glad to hear it. Good job!

srmainwaring commented 1 year ago

@41Mo - posted a PR building on your initial version. Would appreciate your feedback and testing if you get a chance. It's stripped down to minimal functionality. Can add the detach commands back in if required (but I don't think ArduPilot supports that - so I left it out of this version).

41Mo commented 1 year ago

@srmainwaring Perfect. I will try to give feedback this week.

Detach is not required. I have implemented this function to test decouple feature of my aircraft.

srmainwaring commented 1 year ago

Thanks. The main issue I found was that for certain choices of the release pose the collision engine would crash (hard assert and exit signal). I think this was because the original inertial for the parachute resulted in an instability arising from the impulse generated if the chute and vehicle collided before the joint was created - setting a pose directly rather than indirectly through applied forces can sometimes cause these instabilities. I reworked the collision (it is now a sphere with diameter of the canopy) and recalculated the inertial and set the CoM at the collision origin. This seems to have fixed the issue, but would be interested to know if it breaks for some inputs choices.