|
|
|
@ -26,6 +26,11 @@ void AP_MotorsMatrix::init(motor_frame_class frame_class, motor_frame_type frame
@@ -26,6 +26,11 @@ void AP_MotorsMatrix::init(motor_frame_class frame_class, motor_frame_type frame
|
|
|
|
|
_last_frame_class = frame_class; |
|
|
|
|
_last_frame_type = frame_type; |
|
|
|
|
|
|
|
|
|
if (frame_class == MOTOR_FRAME_SCRIPTING_MATRIX) { |
|
|
|
|
// if Scripting frame class, do nothing scripting must call its own dedicated init function
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// setup the motors
|
|
|
|
|
setup_motors(frame_class, frame_type); |
|
|
|
|
|
|
|
|
@ -33,6 +38,63 @@ void AP_MotorsMatrix::init(motor_frame_class frame_class, motor_frame_type frame
@@ -33,6 +38,63 @@ void AP_MotorsMatrix::init(motor_frame_class frame_class, motor_frame_type frame
|
|
|
|
|
set_update_rate(_speed_hz); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_SCRIPTING |
|
|
|
|
// dedicated init for lua scripting
|
|
|
|
|
bool AP_MotorsMatrix::init(uint8_t expected_num_motors) |
|
|
|
|
{ |
|
|
|
|
if (_last_frame_class != MOTOR_FRAME_SCRIPTING_MATRIX) { |
|
|
|
|
// not the correct class
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Make sure the correct number of motors have been added
|
|
|
|
|
uint8_t num_motors = 0; |
|
|
|
|
for (uint8_t i = 0; i < AP_MOTORS_MAX_NUM_MOTORS; i++) { |
|
|
|
|
if (motor_enabled[i]) { |
|
|
|
|
num_motors++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
set_initialised_ok(expected_num_motors == num_motors); |
|
|
|
|
|
|
|
|
|
if (!initialised_ok()) { |
|
|
|
|
_mav_type = MAV_TYPE_GENERIC; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (num_motors) { |
|
|
|
|
case 3: |
|
|
|
|
_mav_type = MAV_TYPE_TRICOPTER; |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
_mav_type = MAV_TYPE_QUADROTOR; |
|
|
|
|
break; |
|
|
|
|
case 6: |
|
|
|
|
_mav_type = MAV_TYPE_HEXAROTOR; |
|
|
|
|
break; |
|
|
|
|
case 8: |
|
|
|
|
_mav_type = MAV_TYPE_OCTOROTOR; |
|
|
|
|
break; |
|
|
|
|
case 10: |
|
|
|
|
_mav_type = MAV_TYPE_DECAROTOR; |
|
|
|
|
break; |
|
|
|
|
case 12: |
|
|
|
|
_mav_type = MAV_TYPE_DODECAROTOR; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
_mav_type = MAV_TYPE_GENERIC; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
normalise_rpy_factors(); |
|
|
|
|
|
|
|
|
|
set_update_rate(_speed_hz); |
|
|
|
|
|
|
|
|
|
set_initialised_ok(true); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
#endif // ENABLE_SCRIPTING
|
|
|
|
|
|
|
|
|
|
// set update rate to motors - a value in hertz
|
|
|
|
|
void AP_MotorsMatrix::set_update_rate(uint16_t speed_hz) |
|
|
|
|
{ |
|
|
|
@ -55,14 +117,9 @@ void AP_MotorsMatrix::set_frame_class_and_type(motor_frame_class frame_class, mo
@@ -55,14 +117,9 @@ void AP_MotorsMatrix::set_frame_class_and_type(motor_frame_class frame_class, mo
|
|
|
|
|
if (armed() || (frame_class == _last_frame_class && _last_frame_type == frame_type)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
_last_frame_class = frame_class; |
|
|
|
|
_last_frame_type = frame_type; |
|
|
|
|
|
|
|
|
|
// setup the motors
|
|
|
|
|
setup_motors(frame_class, frame_type); |
|
|
|
|
init(frame_class, frame_type); |
|
|
|
|
|
|
|
|
|
// enable fast channels or instant pwm
|
|
|
|
|
set_update_rate(_speed_hz); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AP_MotorsMatrix::output_to_motors() |
|
|
|
@ -429,6 +486,11 @@ bool AP_MotorsMatrix::output_test_num(uint8_t output_channel, int16_t pwm)
@@ -429,6 +486,11 @@ bool AP_MotorsMatrix::output_test_num(uint8_t output_channel, int16_t pwm)
|
|
|
|
|
// add_motor
|
|
|
|
|
void AP_MotorsMatrix::add_motor_raw(int8_t motor_num, float roll_fac, float pitch_fac, float yaw_fac, uint8_t testing_order) |
|
|
|
|
{ |
|
|
|
|
if (initialised_ok()) { |
|
|
|
|
// do not allow motors to be set if the current frame type has init correctly
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ensure valid motor number is provided
|
|
|
|
|
if (motor_num >= 0 && motor_num < AP_MOTORS_MAX_NUM_MOTORS) { |
|
|
|
|
|
|
|
|
@ -486,7 +548,7 @@ void AP_MotorsMatrix::setup_motors(motor_frame_class frame_class, motor_frame_ty
@@ -486,7 +548,7 @@ void AP_MotorsMatrix::setup_motors(motor_frame_class frame_class, motor_frame_ty
|
|
|
|
|
for (int8_t i = 0; i < AP_MOTORS_MAX_NUM_MOTORS; i++) { |
|
|
|
|
remove_motor(i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
set_initialised_ok(false); |
|
|
|
|
bool success = true; |
|
|
|
|
|
|
|
|
|
switch (frame_class) { |
|
|
|
@ -988,3 +1050,6 @@ void AP_MotorsMatrix::disable_yaw_torque(void)
@@ -988,3 +1050,6 @@ void AP_MotorsMatrix::disable_yaw_torque(void)
|
|
|
|
|
_yaw_factor[i] = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// singleton instance
|
|
|
|
|
AP_MotorsMatrix *AP_MotorsMatrix::_singleton; |
|
|
|
|