How can I prevent arming from Mission Planner if throttle is not at 0

A Lua script to immediately disarm if an arm command happened with the throttle in an unsafe position could work. But that’s probably a bad answer.

That would be better than nothing but prevention would be better. I’m hoping it is an option I have not found.

I think that just checks to see if the RC has been calibrated by checking if several channels have been changed from default.

Thanks, Dave. I really think there should be a way to prevent arming from any source if the throttle is not in the neutral position. I think I will make an entry in the issues list.

1 Like

I was hoping to see an answer we hadn’t found here. If I get a little time, I’ll work up a script to at least mimic the desired behavior. It’s not a great solution since the motors would be momentarily armed.

1 Like

Here’s the script. As written, the assumption is that the desired throttle arming position is the trim/center position. If you want it to be the min PWM value (or max, if reversed), set USE_TRIM to false.

Again, this is a less than ideal solution because the vehicle will actually be armed momentarily. However, it will be disarmed within 50ms upon detection of an off-idle throttle position, which you could further reduce by decreasing the FREQUENCY variable.

--[[----------------------------------------------------------------------------

ThrottleCheck ArduPilot Lua script

Immediately disarms the vehicle if the throttle is not idle/neutral upon arming.

CAUTION: This script is capable of engaging and disengaging autonomous control
of a vehicle.  Use this script AT YOUR OWN RISK.

-- Yuri -- Sep 2021

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

------------------------------------------------------------------------------]]

--------    USER EDITABLE GLOBALS  --------
local USE_TRIM      = true  -- if true, trim value is idle/neutral, otherwise use RCx_MIN/RCx_MAX
local USE_DEAD_ZONE = true  -- allow RCx_DZ amount of "slop" around throttle neutral/idle value for arming
local FREQUENCY     = 50    -- (ms) how often to run this script (faster is probably better)
local VERBOSE_MODE  = 2     -- 0 to suppress all GCS messages, 1 for status only, 2 for add'l debug messages
-------- END USER EDITABLE GLOBALS --------

local throttle_channel  = math.floor(param:get("RCMAP_THROTTLE"))
local throttle_reversed = math.floor(param:get("RC" .. throttle_channel .. "_REVERSED"))
local throttle_suffix   = "_MIN"
local deadzone          = 0

if (USE_DEAD_ZONE) then
    deadzone = param:get("RC" .. throttle_channel .. "_DZ")
end

if (throttle_reversed == 1) then
    throttle_suffix = "_MAX"
end

if (USE_TRIM) then
    throttle_suffix   = "_TRIM"
end

local throttle_neutral = param:get("RC" .. throttle_channel .. throttle_suffix)

function is_neutral()
    pwm = rc:get_pwm(throttle_channel)
    if (math.abs(pwm - throttle_neutral) <= deadzone) then
        return true
    end
    return false
end

function while_disarmed()
    if (arming:is_armed()) then
        if (not is_neutral()) then
            arming:disarm()
            if (VERBOSE_MODE > 0) then gcs:send_text(4, "Disarmed: Check throttle!") end
            return while_disarmed, FREQUENCY
        end
        return while_armed, FREQUENCY
    end
    return while_disarmed, FREQUENCY
end

function while_armed()
    if (not arming:is_armed()) then
        return while_disarmed, FREQUENCY
    end
    return while_armed, FREQUENCY
end

if (VERBOSE_MODE > 1) then gcs:send_text(5, "Loaded Lua Script: ThrottleCheck") end

return while_disarmed()

Download here: ThrottleCheck.lua (3.2 KB)

Hey, thanks, Yuri. I’m never going to learn Lua since you whip out everything I need so fast! LOL. Please don’t think I mind! I really, really appreciate it. This old dog has a lot of other tricks to learn and can wait on the Lua. Plus, the best way I can learn, if I ever need to, is to look at your code!

No worries - it was a fun little problem solving exercise, and I hope my code is up to the task of being a teaching aid!

1 Like

I have created a feature request: Add Protection from Arming via MAVLink (e.g. Mission Planner) when throttle not at minimum · Issue #18688 · ArduPilot/ardupilot (github.com)

@ktrussell Any update to the questions asked on the issue?

Peter, I apologize for not seeing the activity over there. Responding now. Thanks.

you have arming checks disabled: ARMING_CHECK,0

Set ARMING_CHECK to 1 to re-enable all checks.

EDIT: Kenny solved it!

I built a mower very similar to Kenny’s and find that I have to disable most if not all arming checks because I store it in a garage where it cannot get GPS lock and therefore cannot get a valid yaw source upon first booting up. To move it out of the garage under manual RC control, I cannot have many of the arming checks enabled at all.

I’ll do that but I don’t necessarily want all checks enabled. That is why i asked in my initial post above what the RC Channels option does in the ARMING_CHECK parameter. I would like to know how to enable just the throttle check. I am probably fine with some of the other checks, too, but I don’t think I want them all enabled. Which specific check is the one for throttle in neutral?

EDIT: I verified that with ARMING_CHECK set to 1 (ALL), ArduRover does indeed NOT let me arm if throttle is away from neutral. Then I tried setting it to 64, which is RC Channels, and that also does not let arming happen, so that is the setting I want. I should have just tried it instead of asking. So, @dkemxr, take note. We both learned something. :slight_smile:

I will post in the github issues that this was never an issue and I apologize for taking up folks’ time!

2 Likes

I would like to get to the bottom of why the all arming check is not working with your use case. I would have expected you to still be allowed to arm in manual mode even with no GPS lock since manual does not use GPS. What pre-arms are you hitting with the all option?

EDIT:

@iampete, I had a few minutes to to fire up the electronics, and I remember now why I have all arming checks disabled. I get PreArm: Fence requires position if ANY arming check is enabled, even when trying to arm in manual mode. That’s why I mentioned lack of GPS lock.

Ah, Fence, that would do it, the thinking being that if you have setup a fence you should not be allowed to arm unless AP is sure that the vehicle is inside it.

I take it that you do use a fence? So you can’t just turn it off completely.

We do have a RCx_OPTION to enable and disable fence, 11. So you could disable the fence from the transmitter.

Or you could use your lua script to disable the fence when in manual mode.

I only use exclusion fences to avoid known obstacles, and I keep them uploaded almost all the time. There is no inclusion fence.

I would sooner disable arming checks than go to the trouble of enabling and disabling fences. I actually have a pretty foolproof method for arming the mower in the garage - I don’t even start the engine until the flight controller is booted, the messages show normal operation, and I can visually check the controls, so there’s no way it will move in any mode at that point.

It seems that arming should be possible (especially in manual mode) even with fences enabled if GPS checks are ignored. Would that make sense as a possible logic change? Alternatively, if no inclusion fence is specified, should manual movement be prevented when just exclusion fences are present? Or do we want to be somewhat “draconian” about fence enforcement?

Part of the reason we do not allow arming is because you would just instantly trip into the failsafe action. I guess with exclusion fences probability is on your side, your much more likely to be outside of a given area then inside one.

What is your fence action? (FENCE_ACTION) I can see the argument that if its 0 for “Report Only” then we should allow arming because your not going to straight away switch mode due to the fence failsafe.

@rmackay9 any thoughts?

All of that makes sense.

Indeed, I am using “Report Only” for the simple avoidance action. I use BendyRuler obstacle avoidance.