Hi all,
I am implementing a seed-dropping drone. Servo commands trigger a seed to drop, and will hit a limit switch on the way down.
This switch is implemented with button setup, and a LUA script is used to detect a momentary trigger of the switch to send GCS messages and quick panel data.
I have got GCS messages to display and quick panel data to change from 0 to 1 upon detection of a seed dropping. However, as it is only momentary, I want the GCS messages and quick panel data to last longer.
The following is the LUA script i am currently using:
-- This script detects momentary button presses and sends a specific message to the GCS
-- It also sets a custom parameter to show seed drop status
local button_number = 1 -- the button number we want to read, as defined in AP_Button
local button_active_state = true -- the 'pressed' state of the button
local last_button_state
function update() -- this is the loop which periodically runs
local button_new_state = button:get_button_state(button_number) == button_active_state
-- the button has changed since the last loop
if button_new_state ~= last_button_state then
last_button_state = button_new_state
if button_new_state then
gcs:send_text(0, "Seed Drop Success")
gcs:send_named_float('DROP_CNFRM', 0)
else
gcs:send_named_float('DROP_CNFRM', 1)
end
end
return update, 0.1 -- reschedules the loop (10Hz)
end
return update() -- run immediately before starting to reschedule
I am running on the Pixhawk 6C ArduCopter 4.5.2.
Any help would be much appreciated, thank you!