Hi, I’ve enabled buttons (BTN_ENABLE 1) to use as a bumper, and a lua script to do stuff if the button is pressed. eg b2=button:get_button_state(2)
Testing has shown it working well, but short sharp impacts (eg hit with a stick) on the bumper are not recoginised, even though electrically the pins are shorted, but for a short duration.
Im guessing AP_Button.cpp and debouncing are solving a debounce, at the expense of my bumper sensitivity…
// very crude debounce method #define DEBOUNCE_MS 50
I was running the script at 5Hz, but tested at 20Hz with no change.
Thoughts/Options
modify the DEBOUNCE_MS to 10 on a custom build of ardurover & test ?
electronics, - put in a latch or extend the pulse long enough for the script to pick it up
only crash into heavy slow moving things…
Thanks in advance.
Ardurover 4.5.2 on Qiotek Zealot H743
I don’t think this is debounce so much as script design. The Lua script doesn’t directly see interrupts, so if you’re polling for raw button state, you will very likely miss brief events. If you wanted to fix it in firmware, you’d probably lengthen the debounce time, not shorten it. But I think that’s beside the point.
I think you should assign an aux function (like an unused relay function) to the button and then poll for that aux function having been triggered. I don’t think you need to even fully configure the relay function (by assigning an output pin) to use it for state management like this.
If you want to do this electronically, a latching relay would work. I think I would approach that by scripting a latch reset on arming and then have the script disarm if ever the relay latches (which would present to the autopilot as a constant button press).
More crudely, you can run the script even faster, say at 100Hz (which is entirely possible on an H7 autopilot, though depending on script complexity, sometimes gets throttled a bit). 50ms (20Hz) is an eternity in computing time. This method is likely the least reliable, as scripting is not scheduled in perfect intervals, and it takes a back seat to higher priority CPU tasks.
I’ll give 100hz a try - the code is just checking the button press, so pretty tight loop/light load.
Setting the button to toggle a relay makes sense - but the lua code to read the state of the relay doesnt appear to work, so hard to test for. relay:enable(0) just returns true as far as i can tell.
Ah - but i can set BTN_FUNC2 to HOLD - then use the script to check for HOLD Mode, if its there power down the ICE_MOTOR. I dont use hold normally, so im ok with cutting the noise !
This will be the test of not polling the btn, and seeing how quick the btn mode change notices.