forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_Scripting: added FlexDebug example
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--[[ | ||
ArduPilot lua script to log debug messages from AM32 DroneCAN | ||
ESCs on the flight controller | ||
To install set SCR_ENABLE=1 and put this script in APM/SCRIPTS/ on | ||
the microSD of the flight controller then restart the flight | ||
controller | ||
--]] | ||
|
||
-- assume ESCs are nodes 30, 31, 32 and 33 | ||
local ESC_BASE = 30 | ||
|
||
local AM32_DEBUG = 100 | ||
|
||
local last_tstamp = {} | ||
local ts_zero = uint32_t(0) | ||
local reported_version_error = false | ||
|
||
function log_AM32() | ||
for i = 0, 3 do | ||
local last_ts = last_tstamp[i] or ts_zero | ||
tstamp_us, msg = DroneCAN_get_FlexDebug(0, ESC_BASE+i, AM32_DEBUG, last_ts) | ||
if tstamp_us and msg then | ||
version, commutation_interval, num_commands, num_input, rx_errors, rxframe_error, rx_ecode, auto_advance_level = string.unpack("<BiHHHHiB", msg) | ||
if not version or version ~= 1 then | ||
if not reported_version_error then | ||
reported_version_error = true | ||
gcs:send_text(0, string.format("AM32 debug version error %u", version)) | ||
end | ||
return | ||
end | ||
logger:write('AMD1','Node,CI,NC,NI,RXerr,FrE,RXec,AAL','BiHHHHiB','#-------','--------',i,commutation_interval, num_commands, num_input, rx_errors, rxframe_error, rx_ecode, auto_advance_level) | ||
if rx_ecode then | ||
gcs:send_named_float(string.format('AM32_EC_%u',i), rx_ecode) | ||
end | ||
last_tstamp[i] = tstamp_us | ||
end | ||
end | ||
end | ||
|
||
function update() | ||
log_AM32() | ||
return update, 5 | ||
end | ||
|
||
gcs:send_text(0, "Loaded AM32_debug_log") | ||
|
||
return update, 5 | ||
|
||
|