Home        Store        Docs        Blog

Altitude hold and depth hold in pymavlink

Hello, I’m trying to implement altitude hold on BlueROV using altitude measurement from a DVL. I followed some code snippets in ping1d_mavlink_driver and pymavlink, but neither worked. I taped the pressure sensor and the vehicle sank once I enabled alt_hold mode. Is the altitude hold not supported anymore in this commit?

So I have a few questions with regard to altitude and depth hold modes.

  1. What’s the easiest way to implement altitude hold assuming altitude is available? I could write a PID controller for that but it will be great if I can leverage existing functions in ArduSub.
  2. Is there a way to change the desired depth value in pymavlink during depth hold mode without using a joystick?
  3. When I changed the depth during depth hold mode, I noticed that the vehicle jerked a little bit as you can see from the figure. As a result, the vehicle didn’t hold the exact depth when I released the depth knob.

Regards,
Jinkun

Hello Jinkun,

Yes, that commit disabled it as we didn’t think it was good enough.

You can revert that commit and try to improve the behavior.

I’m afraid that not right now. SET_POSITION_TARGET_GLOBAL_INT and SET_POSITION_TARGET_LOCAL_NED Should be able to set a depth target, but they are only supported in Guided or Auto modes right now. It should be possible to add support for this message to Depth Hold too.

We recently worked on the depth hold controller to mitigate a behavior just like that. Are you running ArduSub 3.5.4?

Hi Willian,

Thanks for the reply. We are using ArduSub 3.5.3. It seems the code to disable altitude hold hasn’t been committed yet in 3.5.3. So the altitude should have worked. Can you verify the following code is the correct?

    bridge.conn.mav.distance_sensor_send(
        int(time * 1000),
        min_altitude * 100,
        max_altitude * 100,
        altitude * 100,
        mavutils.mavlink.MAV_DISTANCE_SENSOR_UNKNOWN,
        1,
        mavutil.mavlink.MAV_SENSOR_ROTATION_PITCH_270,
        0
    )

Should I update to 3.5.4 to use the improved depth hold controller?

Hi,
If you move to 3.5.4 you will be unable to use these messages at all.
you could build 3.5.4 yourself reverting the commit and try to to get it working.

Hello again,

I’ve been looking into this issue. You should be able to set depth target with this gist in the sub 3.6 branch after cherry-picking this commit.

I’m not sure this is the best approach, so I can’t guarantee we’ll get this merged.

Thanks! If it works, I don’t need altitude hold any more.

I tried to build ArduSub 3.6, but I got this error,

The board target px4-v2 has been removed from ArduPilot with the removal of NuttX support and HAL_PX4.

Please use a replacement build as follows:

 px4-v2     Use Pixhawk1 build

Then I changed px4-v2 to Pixhawk1 but I couldn’t find .px4 file in the build folder.

So how can I build sub 3.6 with your commit? Can I use stable branch?

Try:
./waf configure --board Pixhawk1
./waf sub
use the file ardusub.apj from the folder ardupilot/build/Pixhawk1/bin
The files were recently renamed from .px4 to .apj. you may need to rename it to flash using the companion interface.