123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #include <AP_BattMonitor/AP_BattMonitor.h>
- #include <AP_HAL/AP_HAL.h>
- #include "AP_MotorsMatrixTS.h"
- extern const AP_HAL::HAL& hal;
- #define SERVO_OUTPUT_RANGE 4500
- void AP_MotorsMatrixTS::output_motor_mask(float thrust, uint8_t mask, float rudder_dt)
- {
- const int16_t pwm_min = get_pwm_output_min();
- const int16_t pwm_range = get_pwm_output_max() - pwm_min;
- for (uint8_t i=0; i<AP_MOTORS_MAX_NUM_MOTORS; i++) {
- if (motor_enabled[i]) {
- int16_t motor_out;
- if (mask & (1U<<i)) {
-
- float diff_thrust = get_roll_factor(i) * rudder_dt * 0.5f;
- motor_out = pwm_min + pwm_range * constrain_float(thrust + diff_thrust, 0.0f, 1.0f);
- } else {
- motor_out = pwm_min;
- }
- rc_write(i, motor_out);
- }
- }
- }
- void AP_MotorsMatrixTS::output_to_motors()
- {
-
- AP_MotorsMatrix::output_to_motors();
-
- SRV_Channels::set_output_scaled(SRV_Channel::k_aileron, -_yaw_in * SERVO_OUTPUT_RANGE);
- SRV_Channels::set_output_scaled(SRV_Channel::k_elevator, _pitch_in * SERVO_OUTPUT_RANGE);
- SRV_Channels::set_output_scaled(SRV_Channel::k_rudder, _roll_in * SERVO_OUTPUT_RANGE);
- }
- void AP_MotorsMatrixTS::output_armed_stabilizing()
- {
- float roll_thrust;
- float pitch_thrust;
- float throttle_thrust;
- float thrust_max = 0.0f;
- float thr_adj = 0.0f;
-
- const float compensation_gain = get_compensation_gain();
- roll_thrust = (_roll_in + _roll_in_ff) * compensation_gain;
- pitch_thrust = (_pitch_in + _pitch_in_ff) * compensation_gain;
- throttle_thrust = get_throttle() * compensation_gain;
-
- if (throttle_thrust <= 0.0f) {
- throttle_thrust = 0.0f;
- limit.throttle_lower = true;
- }
- if (throttle_thrust >= _throttle_thrust_max) {
- throttle_thrust = _throttle_thrust_max;
- limit.throttle_upper = true;
- }
- thrust_max = 0.0f;
- for (int i=0; i<AP_MOTORS_MAX_NUM_MOTORS; i++) {
- if (motor_enabled[i]) {
-
- _thrust_rpyt_out[i] = throttle_thrust + roll_thrust * _roll_factor[i] + pitch_thrust * _pitch_factor[i];
- if (thrust_max < _thrust_rpyt_out[i]) {
- thrust_max = _thrust_rpyt_out[i];
- }
- }
- }
-
- if (thrust_max > 1.0f) {
- thr_adj = 1.0f - thrust_max;
- limit.throttle_upper = true;
- limit.roll = true;
- limit.pitch = true;
- for (int i=0; i<AP_MOTORS_MAX_NUM_MOTORS; i++) {
- if (motor_enabled[i]) {
-
- _thrust_rpyt_out[i] += thr_adj;
- }
- }
- }
- }
- void AP_MotorsMatrixTS::setup_motors(motor_frame_class frame_class, motor_frame_type frame_type)
- {
-
- for (int8_t i=0; i<AP_MOTORS_MAX_NUM_MOTORS; i++) {
- remove_motor(i);
- }
- bool success = false;
- switch (frame_class) {
- case MOTOR_FRAME_TRI:
-
- add_motor(AP_MOTORS_MOT_1, 90, 0, 2);
- add_motor(AP_MOTORS_MOT_2, -90, 0, 4);
- add_motor(AP_MOTORS_MOT_4, 180, 0, 3);
- success = true;
- break;
- case MOTOR_FRAME_QUAD:
- switch (frame_type) {
- case MOTOR_FRAME_TYPE_PLUS:
-
-
-
-
- add_motor(AP_MOTORS_MOT_1, 90, 0, 2);
- add_motor(AP_MOTORS_MOT_2, -90, 0, 4);
- add_motor(AP_MOTORS_MOT_3, 0, 0, 1);
- add_motor(AP_MOTORS_MOT_4, 180, 0, 3);
- success = true;
- break;
- case MOTOR_FRAME_TYPE_X:
-
- add_motor(AP_MOTORS_MOT_1, 45, 0, 1);
- add_motor(AP_MOTORS_MOT_2, -135, 0, 3);
- add_motor(AP_MOTORS_MOT_3, -45, 0, 4);
- add_motor(AP_MOTORS_MOT_4, 135, 0, 2);
- success = true;
- break;
- default:
-
- break;
- }
- break;
- default:
-
- break;
- }
-
- normalise_rpy_factors();
- _flags.initialised_ok = success;
- }
|