Skip to content

Instantly share code, notes, and snippets.

@davidbitton
Created September 29, 2021 20:33
Show Gist options
  • Save davidbitton/b1351cee82f22b3e9883dba987fb928f to your computer and use it in GitHub Desktop.
Save davidbitton/b1351cee82f22b3e9883dba987fb928f to your computer and use it in GitHub Desktop.
Custom MotorsMatrix Arducopter Lua Script
-- duplicate the #defines from AP_Motors
local AP_MOTORS_MOT_1 = 0
local AP_MOTORS_MOT_2 = 1
local AP_MOTORS_MOT_3 = 2
local AP_MOTORS_MOT_4 = 3
local function add_motor(motor_num, angle_degrees, yaw_factor, testing_order)
gcs:send_text(6, string.format("Adding motor:%i to MotorsMatrix", motor_num + 1))
MotorsMatrix:add_motor_raw(
motor_num,
math.cos(math.rad(angle_degrees + 90)),
math.cos(math.rad(angle_degrees)),
yaw_factor,
testing_order
)
gcs:send_text(6, string.format("Added motor:%i to MotorsMatrix", motor_num + 1))
end
-- This script fails unless the correct FRAME_CLASS is set
local message = 'Empty message'
if not(param:set('FRAME_CLASS', 15)) then
message = 'Unable to set FRAME_CLASS to 15'
else
message = 'FRAME_CLASS Succesfully set to 15'
end
gcs:send_text(6, message)
assert((param:get('FRAME_CLASS') == 15), 'Incorrect FRAME_CLASS')
--[[
default V (Discovery) definition:
add_motor(AP_MOTORS_MOT_1, 45, 0.7981f, 1);
add_motor(AP_MOTORS_MOT_2, -135, 1.0000f, 3);
add_motor(AP_MOTORS_MOT_3, -45, -0.7981f, 4);
add_motor(AP_MOTORS_MOT_4, 135, -1.0000f, 2);
--]]
gcs:send_text(6, "MotorsMatrix initializing")
add_motor(AP_MOTORS_MOT_1, 45, -0.7981, 1)
add_motor(AP_MOTORS_MOT_2, -135, -1.0000, 3)
add_motor(AP_MOTORS_MOT_3, -45, 0.7981, 4)
add_motor(AP_MOTORS_MOT_4, 135, 1.0000, 2)
assert(MotorsMatrix:init(4), "Failed to init MotorsMatrix")
gcs:send_text(6, "MotorsMatrix initialized")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment