Let the boat drift until [SCRIPT_TIME continues]

nice, I will try it now. thank you very much

Ok it seems to work well, I added the sailmast with the same setup.

But I noticed a weird behavior on the distance :
I tried little value, 2 meters, several times, on the quick tab the value stay under 1 meter but the script stop with this final values :

Strange. I’ll look into it a bit later. It might have something to do with allowing drift on the last waypoint of the mission.

Hello, big problem.
The script is not working well after rebooting.
The steering is ok but the throttle seems to be rescaling a lot and is limited to 1508 … I need to boot with the throttle function on chan3, then select script2 again.
If I reboot with this setup it’s not working anymore

That doesn’t make much sense.

First, maybe match the servo min/trim/max values between the actual output and its virtual surrogate.

Next, it might be worth either returning early during a disarmed condition, and/or delaying entry into the first function by using a schedule call of a few seconds instead of a few milliseconds (last line of the script).

I’m not sure to understand, do you mean increase RUN_INTERVAL_MS ? Or add another delay ?

Do not change the overall run interval. That’s critical and must be 10-20ms for proper performance.

You might try changing the very last line of the entire script to delay the entry point a little:
return await_script_time, 3000

Oh yeah obviously, I will try it tomorrow. Thank you

No, it didn’t work, I tried to match the trims too…

I think maybe we are forcing an ESC calibration to be skipped by swapping the throttle to an unused channel.

The attached update sets throttle out to non-scripted mode when disarmed.

Recommend setting and saving SERVOx_FUNCTION,70 for whichever output is the actual throttle (so you’ll have two outputs that show “70” on the servo setup page). If it’s not SERVO3, update the script’s THROTTLE_OUT_CH to match. The script will handle the rest.

drift.lua (3.5 KB)

Hi @Yuri_Rage! Great script!! I’ll try it in the pond in a week.
Is it possible to use a script to make a “controlled” drift?
For example, you are moving downstream in the river and you basically do not need a motor, you only need a servo machine (for rudder).
And the script was activated, for example, at a certain speed, if, for example, the speed of a boat is
2 m/s, then you can turn off the motor.

A boat is very uncontrollable juste with a rudder in the current, you need at least a sail or add some motor at the same time you turn the rudder.

@Yuri_Rage while waiting for your reply I tried several things and it worked replacing scaled methods by pwm, in the await_script function.

I will look into your script later, thank you.

It all depends on the shape of the hull and the area of the rudder of the vessel, in manual mode I do it easily. It’s just the idea itself, not a specific case. If there is such a script that can control the rudder , then you can simply use the bow or stern trasters instead of the servomachine. I have several model models that have trasters, but Ardupilot does not use them.

Strange result indeed. If you use raw PWM values with this method, be absolutely sure that min/max/trim are identical between each virtual output and its scripted surrogate.

Yep, and reverse checkbox too

Hello,

I’m currently working on a similar problem where I also need to lock the outputs. Is there a reason why you used the “virtual” outputs instead of

SRV_Channels:set_output_pwm_chan_timeout(channel, pwm, timeout)

? Because according to the documentation this should also be able to override the outputs: Lua Scripts — Copter documentation

Edit: Although I can’t get it to work in the Simulator, but I’m struggling a bit with it anyways, so could also be another mistake

Edit2: Figured it out, it works that way

1 Like

because we can’t override critical functions like steering or throttle.
Good if it’s working for you

Instead of overriding the servo outputs directly for Rovers and Boats you can use the the vehicle object’s set_steering_and_throttle binding.

1 Like

I thought intercepting the servo commands was creative, and it’s certainly effective (I’ve done this on a few scripts for things that are less straightforward - my own mower does this to linearize output).

But the guided mode bindings are clearly more suited this use case!

1 Like