ardupilot icon indicating copy to clipboard operation
ardupilot copied to clipboard

AP_Volz_Protocol: use own thread for output

Open IamPete1 opened this issue 10 months ago • 2 comments

Note that I have been testing with half duplex servos (with 3 in the part number). The current driver is probably better for full duplex (with 5 in the part number) because it remains in lock step with the servo outputs. However, there are a few issues with the existing driver, and I don't have any full duplex servos to test it with. This method will still work with full duplex actuators just there will be slightly more delay in some cases.

This tidies up the library a little and moves the output to its own thread, this means each command is sent and then we wait enough time for the reply (which we don't read) to be sent before sending the next command.

The current driver just sends all the commands in a big block which steps on the reply. For four servos set in the bitmask it looks like this:

image

You will notice slightly random timing and we only occasionally get the reply, highlighted in blue on the RS485 line (my transceiver is in transmit mode all the time so we don't get the reply on the UART).

This results in the servos having quite a bad time, quite steppy sounding (unmute recommended):

media_20240403_211229_2494658397588330632.webm

This PR send the commands one at a time which looks like this: Volz Thread I only have one servo connected, but it's sending commands for four servos, so we only see the reply on every fourth command.

Nice even spacing and we don't step on the reply. Scrolling through the trace this is the closest it came: Volz Thread close

We could leave a longer gap with a bit more head room, but this does seem to work, it depends on how quick the servo is to reply.

That results in a much happier servo:

media_20240404_161546_1469986467495218372.webm

This also adds a new range parameter. This defaults to the current max range of 200 deg (+- 100). Using the full range of 200 deg means you get a 0.2 deg per PWM US. In most cases you need a much smaller range, so end up having to set servo min/max very close to trim. 1400 to 1600 would be +- 20 deg for example. The range param allow you to set 40 deg range and then use 1000 to 2000 PWM for that range. 40 deg means you can get 0.04 deg per PWM US which is slightly lower than the limit of the protocol.

This also changes the behavior of 0 PWM in safe. Currently it would go to -100 deg. This PR changes it to move to the servo trim position. Unfortunately there is no way to power down the servo with the protocol.

IamPete1 avatar Apr 04 '24 16:04 IamPete1

If possible it would also be nice to update the wiki page: https://ardupilot.org/copter/docs/common-servo-volz.html

so if anyone has comments they think should be added, type them here and I'll create a PR.

rmackay9 avatar Apr 08 '24 23:04 rmackay9

@IamPete1 I will test on full duplex servos

tridge avatar Apr 08 '24 23:04 tridge

Rebased.

IamPete1 avatar Jul 08 '24 23:07 IamPete1

I have been unable to find anyone else to test this, I think we just have to merge it or close it at this point.

IamPete1 avatar Jul 09 '24 16:07 IamPete1

STAK results from hardware testing: image image

MattKear avatar Jul 10 '24 07:07 MattKear