2016-02-17 21:25:38 -04:00
|
|
|
#pragma once
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2022-02-28 21:19:11 -04:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2015-08-11 03:28:44 -03:00
|
|
|
#include <Filter/Filter.h> // filter library
|
2022-05-11 06:14:51 -03:00
|
|
|
#include <Filter/DerivativeFilter.h>
|
2022-02-28 21:19:11 -04:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2023-07-13 21:58:07 -03:00
|
|
|
#include <AP_Logger/AP_Logger_config.h>
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2015-09-28 23:58:52 -03:00
|
|
|
// offsets for motors in motor_out and _motor_filtered arrays
|
|
|
|
#define AP_MOTORS_MOT_1 0U
|
|
|
|
#define AP_MOTORS_MOT_2 1U
|
|
|
|
#define AP_MOTORS_MOT_3 2U
|
|
|
|
#define AP_MOTORS_MOT_4 3U
|
|
|
|
#define AP_MOTORS_MOT_5 4U
|
|
|
|
#define AP_MOTORS_MOT_6 5U
|
|
|
|
#define AP_MOTORS_MOT_7 6U
|
|
|
|
#define AP_MOTORS_MOT_8 7U
|
2017-05-13 22:15:49 -03:00
|
|
|
#define AP_MOTORS_MOT_9 8U
|
|
|
|
#define AP_MOTORS_MOT_10 9U
|
|
|
|
#define AP_MOTORS_MOT_11 10U
|
|
|
|
#define AP_MOTORS_MOT_12 11U
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2017-05-13 22:15:49 -03:00
|
|
|
#define AP_MOTORS_MAX_NUM_MOTORS 12
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2022-01-30 08:22:01 -04:00
|
|
|
#ifndef AP_MOTORS_FRAME_DEFAULT_ENABLED
|
|
|
|
#define AP_MOTORS_FRAME_DEFAULT_ENABLED 1
|
|
|
|
#endif
|
|
|
|
|
2021-10-30 23:56:36 -03:00
|
|
|
#ifndef AP_MOTORS_FRAME_QUAD_ENABLED
|
2022-01-30 08:22:01 -04:00
|
|
|
#define AP_MOTORS_FRAME_QUAD_ENABLED AP_MOTORS_FRAME_DEFAULT_ENABLED
|
2021-10-24 15:24:33 -03:00
|
|
|
#endif
|
2021-10-30 23:56:36 -03:00
|
|
|
#ifndef AP_MOTORS_FRAME_HEXA_ENABLED
|
2022-01-30 08:22:01 -04:00
|
|
|
#define AP_MOTORS_FRAME_HEXA_ENABLED AP_MOTORS_FRAME_DEFAULT_ENABLED
|
2021-10-24 15:24:33 -03:00
|
|
|
#endif
|
2021-10-30 23:56:36 -03:00
|
|
|
#ifndef AP_MOTORS_FRAME_OCTA_ENABLED
|
2022-01-30 08:22:01 -04:00
|
|
|
#define AP_MOTORS_FRAME_OCTA_ENABLED AP_MOTORS_FRAME_DEFAULT_ENABLED
|
2021-10-24 15:24:33 -03:00
|
|
|
#endif
|
2021-10-30 23:56:36 -03:00
|
|
|
#ifndef AP_MOTORS_FRAME_DECA_ENABLED
|
2022-01-30 08:22:01 -04:00
|
|
|
#define AP_MOTORS_FRAME_DECA_ENABLED AP_MOTORS_FRAME_DEFAULT_ENABLED
|
2021-10-24 15:24:33 -03:00
|
|
|
#endif
|
2021-10-30 23:56:36 -03:00
|
|
|
#ifndef AP_MOTORS_FRAME_DODECAHEXA_ENABLED
|
2022-01-30 08:22:01 -04:00
|
|
|
#define AP_MOTORS_FRAME_DODECAHEXA_ENABLED AP_MOTORS_FRAME_DEFAULT_ENABLED
|
2021-10-24 15:24:33 -03:00
|
|
|
#endif
|
2021-10-30 23:56:36 -03:00
|
|
|
#ifndef AP_MOTORS_FRAME_Y6_ENABLED
|
2022-01-30 08:22:01 -04:00
|
|
|
#define AP_MOTORS_FRAME_Y6_ENABLED AP_MOTORS_FRAME_DEFAULT_ENABLED
|
2021-10-24 15:24:33 -03:00
|
|
|
#endif
|
2021-10-30 23:56:36 -03:00
|
|
|
#ifndef AP_MOTORS_FRAME_OCTAQUAD_ENABLED
|
2022-01-30 08:22:01 -04:00
|
|
|
#define AP_MOTORS_FRAME_OCTAQUAD_ENABLED AP_MOTORS_FRAME_DEFAULT_ENABLED
|
2021-10-24 15:24:33 -03:00
|
|
|
#endif
|
|
|
|
|
2012-10-26 20:59:07 -03:00
|
|
|
// motor update rate
|
2013-05-14 04:56:55 -03:00
|
|
|
#define AP_MOTORS_SPEED_DEFAULT 490 // default output rate to the motors
|
2012-10-26 20:59:07 -03:00
|
|
|
|
|
|
|
/// @class AP_Motors
|
|
|
|
class AP_Motors {
|
|
|
|
public:
|
|
|
|
|
2016-12-14 01:46:42 -04:00
|
|
|
enum motor_frame_class {
|
|
|
|
MOTOR_FRAME_UNDEFINED = 0,
|
|
|
|
MOTOR_FRAME_QUAD = 1,
|
|
|
|
MOTOR_FRAME_HEXA = 2,
|
|
|
|
MOTOR_FRAME_OCTA = 3,
|
|
|
|
MOTOR_FRAME_OCTAQUAD = 4,
|
|
|
|
MOTOR_FRAME_Y6 = 5,
|
|
|
|
MOTOR_FRAME_HELI = 6,
|
|
|
|
MOTOR_FRAME_TRI = 7,
|
|
|
|
MOTOR_FRAME_SINGLE = 8,
|
2017-02-10 01:26:12 -04:00
|
|
|
MOTOR_FRAME_COAX = 9,
|
|
|
|
MOTOR_FRAME_TAILSITTER = 10,
|
2017-03-14 06:46:48 -03:00
|
|
|
MOTOR_FRAME_HELI_DUAL = 11,
|
2017-05-13 22:15:49 -03:00
|
|
|
MOTOR_FRAME_DODECAHEXA = 12,
|
2017-08-26 08:53:53 -03:00
|
|
|
MOTOR_FRAME_HELI_QUAD = 13,
|
2020-09-16 12:00:00 -03:00
|
|
|
MOTOR_FRAME_DECA = 14,
|
2021-01-19 12:44:02 -04:00
|
|
|
MOTOR_FRAME_SCRIPTING_MATRIX = 15,
|
2021-01-26 09:01:02 -04:00
|
|
|
MOTOR_FRAME_6DOF_SCRIPTING = 16,
|
2021-06-19 15:13:36 -03:00
|
|
|
MOTOR_FRAME_DYNAMIC_SCRIPTING_MATRIX = 17,
|
2016-12-14 01:46:42 -04:00
|
|
|
};
|
2020-11-05 15:59:35 -04:00
|
|
|
|
|
|
|
// return string corresponding to frame_class
|
2022-01-01 11:55:34 -04:00
|
|
|
const char* get_frame_string() const;
|
2020-11-05 15:59:35 -04:00
|
|
|
|
2016-12-14 01:46:42 -04:00
|
|
|
enum motor_frame_type {
|
|
|
|
MOTOR_FRAME_TYPE_PLUS = 0,
|
|
|
|
MOTOR_FRAME_TYPE_X = 1,
|
|
|
|
MOTOR_FRAME_TYPE_V = 2,
|
|
|
|
MOTOR_FRAME_TYPE_H = 3,
|
|
|
|
MOTOR_FRAME_TYPE_VTAIL = 4,
|
|
|
|
MOTOR_FRAME_TYPE_ATAIL = 5,
|
2018-12-03 03:55:44 -04:00
|
|
|
MOTOR_FRAME_TYPE_PLUSREV = 6, // plus with reversed motor direction
|
2017-02-06 00:01:51 -04:00
|
|
|
MOTOR_FRAME_TYPE_Y6B = 10,
|
2019-01-31 23:30:47 -04:00
|
|
|
MOTOR_FRAME_TYPE_Y6F = 11, // for FireFlyY6
|
|
|
|
MOTOR_FRAME_TYPE_BF_X = 12, // X frame, betaflight ordering
|
|
|
|
MOTOR_FRAME_TYPE_DJI_X = 13, // X frame, DJI ordering
|
|
|
|
MOTOR_FRAME_TYPE_CW_X = 14, // X frame, clockwise ordering
|
2019-03-15 18:47:50 -03:00
|
|
|
MOTOR_FRAME_TYPE_I = 15, // (sideways H) octo only
|
2019-11-23 18:02:46 -04:00
|
|
|
MOTOR_FRAME_TYPE_NYT_PLUS = 16, // plus frame, no differential torque for yaw
|
|
|
|
MOTOR_FRAME_TYPE_NYT_X = 17, // X frame, no differential torque for yaw
|
2020-01-14 02:24:55 -04:00
|
|
|
MOTOR_FRAME_TYPE_BF_X_REV = 18, // X frame, betaflight ordering, reversed motors
|
2021-11-02 21:15:44 -03:00
|
|
|
MOTOR_FRAME_TYPE_Y4 = 19, //Y4 Quadrotor frame
|
2016-12-14 01:46:42 -04:00
|
|
|
};
|
|
|
|
|
2020-11-05 15:59:35 -04:00
|
|
|
|
2021-06-19 20:54:22 -03:00
|
|
|
// returns a formatted string into buffer, e.g. "QUAD/X"
|
|
|
|
void get_frame_and_type_string(char *buffer, uint8_t buflen) const;
|
|
|
|
|
2012-10-26 20:59:07 -03:00
|
|
|
// Constructor
|
2022-12-06 21:03:36 -04:00
|
|
|
AP_Motors(uint16_t speed_hz = AP_MOTORS_SPEED_DEFAULT);
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2018-03-21 21:45:52 -03:00
|
|
|
// singleton support
|
2019-04-19 21:59:40 -03:00
|
|
|
static AP_Motors *get_singleton(void) { return _singleton; }
|
2018-03-21 21:45:52 -03:00
|
|
|
|
2016-12-14 01:46:42 -04:00
|
|
|
// check initialisation succeeded
|
2022-09-03 22:58:37 -03:00
|
|
|
virtual bool arming_checks(size_t buflen, char *buffer) const;
|
2023-06-18 15:56:32 -03:00
|
|
|
virtual bool motor_test_checks(size_t buflen, char *buffer) const;
|
2019-05-03 02:27:09 -03:00
|
|
|
bool initialised_ok() const { return _initialised_ok; }
|
|
|
|
void set_initialised_ok(bool val) { _initialised_ok = val; }
|
2012-10-26 20:59:07 -03:00
|
|
|
|
|
|
|
// arm, disarm or check status status of motors
|
2019-05-03 02:27:09 -03:00
|
|
|
bool armed() const { return _armed; }
|
2013-08-08 10:15:04 -03:00
|
|
|
void armed(bool arm);
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2015-04-17 12:58:26 -03:00
|
|
|
// set motor interlock status
|
2019-05-03 02:27:09 -03:00
|
|
|
void set_interlock(bool set) { _interlock = set;}
|
2015-04-17 12:58:26 -03:00
|
|
|
|
2015-05-01 00:16:32 -03:00
|
|
|
// get motor interlock status. true means motors run, false motors don't run
|
2019-05-03 02:27:09 -03:00
|
|
|
bool get_interlock() const { return _interlock; }
|
2015-04-17 12:58:26 -03:00
|
|
|
|
2022-06-28 03:51:52 -03:00
|
|
|
// get/set spoolup block
|
|
|
|
bool get_spoolup_block() const { return _spoolup_block; }
|
|
|
|
void set_spoolup_block(bool set) { _spoolup_block = set; }
|
|
|
|
|
2014-02-10 00:20:26 -04:00
|
|
|
// set_roll, set_pitch, set_yaw, set_throttle
|
2016-01-21 22:08:55 -04:00
|
|
|
void set_roll(float roll_in) { _roll_in = roll_in; }; // range -1 ~ +1
|
2019-06-27 06:32:30 -03:00
|
|
|
void set_roll_ff(float roll_in) { _roll_in_ff = roll_in; }; // range -1 ~ +1
|
2016-01-21 22:08:55 -04:00
|
|
|
void set_pitch(float pitch_in) { _pitch_in = pitch_in; }; // range -1 ~ +1
|
2019-06-27 06:32:30 -03:00
|
|
|
void set_pitch_ff(float pitch_in) { _pitch_in_ff = pitch_in; }; // range -1 ~ +1
|
2016-01-21 22:08:55 -04:00
|
|
|
void set_yaw(float yaw_in) { _yaw_in = yaw_in; }; // range -1 ~ +1
|
2019-06-27 06:32:30 -03:00
|
|
|
void set_yaw_ff(float yaw_in) { _yaw_in_ff = yaw_in; }; // range -1 ~ +1
|
2016-03-22 23:28:18 -03:00
|
|
|
void set_throttle(float throttle_in) { _throttle_in = throttle_in; }; // range 0 ~ 1
|
2019-04-19 21:59:40 -03:00
|
|
|
void set_throttle_avg_max(float throttle_avg_max) { _throttle_avg_max = constrain_float(throttle_avg_max, 0.0f, 1.0f); }; // range 0 ~ 1
|
2016-01-21 01:58:55 -04:00
|
|
|
void set_throttle_filter_cutoff(float filt_hz) { _throttle_filter.set_cutoff_frequency(filt_hz); }
|
2022-05-11 06:14:51 -03:00
|
|
|
void set_slew_filter_cutoff(float filt_hz) { _throttle_slew_filter.set_cutoff_frequency(filt_hz); }
|
2016-01-01 18:20:32 -04:00
|
|
|
void set_forward(float forward_in) { _forward_in = forward_in; }; // range -1 ~ +1
|
|
|
|
void set_lateral(float lateral_in) { _lateral_in = lateral_in; }; // range -1 ~ +1
|
2016-01-21 01:58:55 -04:00
|
|
|
|
2021-01-26 09:01:02 -04:00
|
|
|
// for 6DoF vehicles, sets the roll and pitch offset, this rotates the thrust vector in body frame
|
|
|
|
virtual void set_roll_pitch(float roll_deg, float pitch_deg) {};
|
|
|
|
|
2015-01-24 00:57:32 -04:00
|
|
|
// accessors for roll, pitch, yaw and throttle inputs to motors
|
2016-01-21 22:08:55 -04:00
|
|
|
float get_roll() const { return _roll_in; }
|
2021-04-11 23:53:33 -03:00
|
|
|
float get_roll_ff() const { return _roll_in_ff; }
|
2016-01-21 22:08:55 -04:00
|
|
|
float get_pitch() const { return _pitch_in; }
|
2021-04-11 23:53:33 -03:00
|
|
|
float get_pitch_ff() const { return _pitch_in_ff; }
|
2016-01-21 22:08:55 -04:00
|
|
|
float get_yaw() const { return _yaw_in; }
|
2021-04-11 23:53:33 -03:00
|
|
|
float get_yaw_ff() const { return _yaw_in_ff; }
|
2019-07-10 04:26:12 -03:00
|
|
|
float get_throttle_out() const { return _throttle_out; }
|
2024-04-02 17:03:30 -03:00
|
|
|
virtual bool get_thrust(uint8_t motor_num, float& thr_out) const { return false; }
|
2019-04-19 21:59:40 -03:00
|
|
|
float get_throttle() const { return constrain_float(_throttle_filter.get(), 0.0f, 1.0f); }
|
|
|
|
float get_throttle_bidirectional() const { return constrain_float(2 * (_throttle_filter.get() - 0.5f), -1.0f, 1.0f); }
|
2022-05-11 06:14:51 -03:00
|
|
|
float get_throttle_slew_rate() const { return _throttle_slew_rate; }
|
2016-01-01 18:20:32 -04:00
|
|
|
float get_forward() const { return _forward_in; }
|
|
|
|
float get_lateral() const { return _lateral_in; }
|
2016-03-22 10:57:26 -03:00
|
|
|
virtual float get_throttle_hover() const = 0;
|
2014-07-17 06:15:07 -03:00
|
|
|
|
2018-08-12 11:19:20 -03:00
|
|
|
// motor failure handling
|
|
|
|
void set_thrust_boost(bool enable) { _thrust_boost = enable; }
|
|
|
|
bool get_thrust_boost() const { return _thrust_boost; }
|
|
|
|
virtual uint8_t get_lost_motor() const { return 0; }
|
|
|
|
|
2018-12-28 02:31:38 -04:00
|
|
|
// desired spool states
|
2019-04-09 09:15:45 -03:00
|
|
|
enum class DesiredSpoolState : uint8_t {
|
|
|
|
SHUT_DOWN = 0, // all motors should move to stop
|
|
|
|
GROUND_IDLE = 1, // all motors should move to ground idle
|
|
|
|
THROTTLE_UNLIMITED = 2, // motors should move to being a state where throttle is unconstrained (e.g. by start up procedure)
|
2016-02-02 08:14:12 -04:00
|
|
|
};
|
|
|
|
|
2019-04-09 09:15:45 -03:00
|
|
|
void set_desired_spool_state(enum DesiredSpoolState spool);
|
2016-02-02 08:14:12 -04:00
|
|
|
|
2019-04-09 09:15:45 -03:00
|
|
|
enum DesiredSpoolState get_desired_spool_state(void) const { return _spool_desired; }
|
2018-12-28 02:31:38 -04:00
|
|
|
|
|
|
|
// spool states
|
2019-04-09 09:15:45 -03:00
|
|
|
enum class SpoolState : uint8_t {
|
2018-12-28 02:31:38 -04:00
|
|
|
SHUT_DOWN = 0, // all motors stop
|
|
|
|
GROUND_IDLE = 1, // all motors at ground idle
|
2019-04-09 09:15:45 -03:00
|
|
|
SPOOLING_UP = 2, // increasing maximum throttle while stabilizing
|
2018-12-28 02:31:38 -04:00
|
|
|
THROTTLE_UNLIMITED = 3, // throttle is no longer constrained by start up procedure
|
2019-04-09 09:15:45 -03:00
|
|
|
SPOOLING_DOWN = 4, // decreasing maximum throttle while stabilizing
|
2018-12-28 02:31:38 -04:00
|
|
|
};
|
|
|
|
|
2019-04-09 09:15:45 -03:00
|
|
|
// get_spool_state - get current spool state
|
|
|
|
enum SpoolState get_spool_state(void) const { return _spool_state; }
|
2018-12-28 02:31:38 -04:00
|
|
|
|
2022-12-06 21:03:36 -04:00
|
|
|
// set_dt / get_dt - dt is the time since the last time the motor mixers were updated
|
|
|
|
// _dt should be set based on the time of the last IMU read used by these controllers
|
|
|
|
// the motor mixers should run on each loop to ensure normal operation
|
|
|
|
void set_dt(float dt) { _dt = dt; }
|
|
|
|
float get_dt() const { return _dt; }
|
|
|
|
|
2013-07-21 01:58:24 -03:00
|
|
|
// structure for holding motor limit flags
|
|
|
|
struct AP_Motors_limit {
|
2022-10-21 20:45:43 -03:00
|
|
|
bool roll; // we have reached roll or pitch limit
|
|
|
|
bool pitch; // we have reached roll or pitch limit
|
|
|
|
bool yaw; // we have reached yaw limit
|
|
|
|
bool throttle_lower; // we have reached throttle's lower limit
|
|
|
|
bool throttle_upper; // we have reached throttle's upper limit
|
2013-07-21 01:58:24 -03:00
|
|
|
} limit;
|
|
|
|
|
2020-12-01 17:35:45 -04:00
|
|
|
// set limit flag for pitch, roll and yaw
|
|
|
|
void set_limit_flag_pitch_roll_yaw(bool flag);
|
|
|
|
|
2022-10-21 20:45:43 -03:00
|
|
|
#if AP_SCRIPTING_ENABLED
|
|
|
|
// set limit flag for pitch, roll and yaw
|
|
|
|
void set_external_limits(bool roll, bool pitch, bool yaw, bool throttle_lower, bool throttle_upper);
|
|
|
|
#endif
|
|
|
|
|
2015-07-13 01:39:57 -03:00
|
|
|
//
|
|
|
|
// virtual functions that should be implemented by child classes
|
|
|
|
//
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2016-12-14 01:34:15 -04:00
|
|
|
// set update rate to motors - a value in hertz
|
|
|
|
virtual void set_update_rate( uint16_t speed_hz ) { _speed_hz = speed_hz; }
|
|
|
|
|
2015-07-02 18:15:09 -03:00
|
|
|
// init
|
2016-12-14 01:46:42 -04:00
|
|
|
virtual void init(motor_frame_class frame_class, motor_frame_type frame_type) = 0;
|
|
|
|
|
|
|
|
// set frame class (i.e. quad, hexa, heli) and type (i.e. x, plus)
|
|
|
|
virtual void set_frame_class_and_type(motor_frame_class frame_class, motor_frame_type frame_type) = 0;
|
2012-10-26 20:59:07 -03:00
|
|
|
|
2015-07-02 18:15:09 -03:00
|
|
|
// output - sends commands to the motors
|
|
|
|
virtual void output() = 0;
|
2015-02-23 05:09:08 -04:00
|
|
|
|
2015-07-02 18:15:09 -03:00
|
|
|
// output_min - sends minimum values out to the motors
|
|
|
|
virtual void output_min() = 0;
|
2013-05-26 23:21:31 -03:00
|
|
|
|
2018-04-27 13:22:07 -03:00
|
|
|
// output_test_seq - spin a motor at the pwm value specified
|
2015-07-02 18:15:09 -03:00
|
|
|
// motor_seq is the motor's sequence number from 1 to the number of motors on the frame
|
|
|
|
// pwm value is an actual pwm value that will be output, normally in the range of 1000 ~ 2000
|
2022-01-27 11:37:06 -04:00
|
|
|
void output_test_seq(uint8_t motor_seq, int16_t pwm);
|
2015-02-21 03:55:13 -04:00
|
|
|
|
2015-07-02 18:15:09 -03:00
|
|
|
// get_motor_mask - returns a bitmask of which outputs are being used for motors (1 means being used)
|
|
|
|
// this can be used to ensure other pwm outputs (i.e. for servos) do not conflict
|
2021-12-10 12:45:20 -04:00
|
|
|
virtual uint32_t get_motor_mask() = 0;
|
2015-07-02 18:15:09 -03:00
|
|
|
|
2016-02-03 07:55:55 -04:00
|
|
|
// pilot input in the -1 ~ +1 range for roll, pitch and yaw. 0~1 range for throttle
|
|
|
|
void set_radio_passthrough(float roll_input, float pitch_input, float throttle_input, float yaw_input);
|
|
|
|
|
2018-12-29 11:43:58 -04:00
|
|
|
// return the roll factor of any motor, this is used for tilt rotors and tail sitters
|
|
|
|
// using copter motors for forward flight
|
|
|
|
virtual float get_roll_factor(uint8_t i) { return 0.0f; }
|
|
|
|
|
2021-07-27 16:51:00 -03:00
|
|
|
// return the pitch factor of any motor
|
|
|
|
virtual float get_pitch_factor(uint8_t i) { return 0.0f; }
|
|
|
|
|
|
|
|
// return whether a motor is enabled or not
|
|
|
|
virtual bool is_motor_enabled(uint8_t i) { return false; }
|
|
|
|
|
2019-09-30 17:54:29 -03:00
|
|
|
// This function required for tradheli. Tradheli initializes targets when going from unarmed to armed state.
|
|
|
|
// This function is overriden in motors_heli class. Always true for multicopters.
|
|
|
|
virtual bool init_targets_on_arming() const { return true; }
|
|
|
|
|
2021-09-22 12:18:05 -03:00
|
|
|
// returns true if the configured PWM type is digital and should have fixed endpoints
|
|
|
|
bool is_digital_pwm_type() const;
|
|
|
|
|
|
|
|
// returns true is pwm type is brushed
|
2024-07-25 22:06:14 -03:00
|
|
|
bool is_brushed_pwm_type() const { return _pwm_type == PWMType::BRUSHED; }
|
2021-09-22 12:18:05 -03:00
|
|
|
|
|
|
|
// returns true is pwm type is normal
|
2024-07-25 22:06:14 -03:00
|
|
|
bool is_normal_pwm_type() const { return (_pwm_type == PWMType::NORMAL) || (_pwm_type == PWMType::PWM_RANGE) || (_pwm_type == PWMType::PWM_ANGLE); }
|
2019-05-03 02:27:09 -03:00
|
|
|
|
2020-12-24 17:17:37 -04:00
|
|
|
MAV_TYPE get_frame_mav_type() const { return _mav_type; }
|
|
|
|
|
2021-07-27 16:51:00 -03:00
|
|
|
// direct motor write
|
|
|
|
virtual void rc_write(uint8_t chan, uint16_t pwm);
|
|
|
|
|
2022-01-01 11:55:34 -04:00
|
|
|
#if AP_SCRIPTING_ENABLED
|
|
|
|
void set_frame_string(const char * str);
|
|
|
|
#endif
|
|
|
|
|
2023-07-13 21:58:07 -03:00
|
|
|
#if HAL_LOGGING_ENABLED
|
2021-12-21 16:53:58 -04:00
|
|
|
// write log, to be called at 10hz
|
|
|
|
virtual void Log_Write() {};
|
2023-07-13 21:58:07 -03:00
|
|
|
#endif
|
2021-12-21 16:53:58 -04:00
|
|
|
|
2023-03-16 20:19:29 -03:00
|
|
|
enum MotorOptions : uint8_t {
|
|
|
|
BATT_RAW_VOLTAGE = (1 << 0U)
|
|
|
|
};
|
|
|
|
bool has_option(MotorOptions option) { return _options.get() & uint8_t(option); }
|
|
|
|
|
2015-07-02 18:15:09 -03:00
|
|
|
protected:
|
|
|
|
// output functions that should be overloaded by child classes
|
2019-04-19 21:59:40 -03:00
|
|
|
virtual void output_armed_stabilizing() = 0;
|
2018-05-20 22:37:38 -03:00
|
|
|
virtual void rc_write_angle(uint8_t chan, int16_t angle_cd);
|
2016-01-04 06:24:06 -04:00
|
|
|
virtual void rc_set_freq(uint32_t mask, uint16_t freq_hz);
|
2021-01-02 08:09:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
map an internal motor mask to real motor mask, accounting for
|
|
|
|
SERVOn_FUNCTION mappings, and allowing for multiple outputs per
|
|
|
|
motor number
|
|
|
|
*/
|
|
|
|
uint32_t motor_mask_to_srv_channel_mask(uint32_t mask) const;
|
2016-04-21 04:32:25 -03:00
|
|
|
|
|
|
|
// add a motor to the motor map
|
|
|
|
void add_motor_num(int8_t motor_num);
|
2016-01-04 01:56:54 -04:00
|
|
|
|
2015-07-02 18:15:09 -03:00
|
|
|
// update the throttle input filter
|
2016-12-14 01:34:15 -04:00
|
|
|
virtual void update_throttle_filter() = 0;
|
2015-04-02 17:54:15 -03:00
|
|
|
|
2016-06-09 02:21:04 -03:00
|
|
|
// save parameters as part of disarming
|
|
|
|
virtual void save_params_on_disarm() {}
|
|
|
|
|
2013-09-12 10:27:44 -03:00
|
|
|
// internal variables
|
2022-12-06 21:03:36 -04:00
|
|
|
float _dt; // time difference (in seconds) since the last loop time
|
2015-05-14 22:00:46 -03:00
|
|
|
uint16_t _speed_hz; // speed in hz to send updates to motors
|
2016-01-21 22:08:55 -04:00
|
|
|
float _roll_in; // desired roll control from attitude controllers, -1 ~ +1
|
2019-06-27 06:32:30 -03:00
|
|
|
float _roll_in_ff; // desired roll feed forward control from attitude controllers, -1 ~ +1
|
2016-01-21 22:08:55 -04:00
|
|
|
float _pitch_in; // desired pitch control from attitude controller, -1 ~ +1
|
2019-06-27 06:32:30 -03:00
|
|
|
float _pitch_in_ff; // desired pitch feed forward control from attitude controller, -1 ~ +1
|
2016-01-21 22:08:55 -04:00
|
|
|
float _yaw_in; // desired yaw control from attitude controller, -1 ~ +1
|
2019-06-27 06:32:30 -03:00
|
|
|
float _yaw_in_ff; // desired yaw feed forward control from attitude controller, -1 ~ +1
|
2015-07-13 01:39:57 -03:00
|
|
|
float _throttle_in; // last throttle input from set_throttle caller
|
2019-07-10 04:26:12 -03:00
|
|
|
float _throttle_out; // throttle after mixing is complete
|
2022-05-11 06:14:51 -03:00
|
|
|
float _throttle_slew_rate; // throttle slew rate from input
|
2016-01-01 18:20:32 -04:00
|
|
|
float _forward_in; // last forward input from set_forward caller
|
|
|
|
float _lateral_in; // last lateral input from set_lateral caller
|
2016-06-08 05:48:54 -03:00
|
|
|
float _throttle_avg_max; // last throttle input from set_throttle_avg_max
|
2022-05-11 06:14:51 -03:00
|
|
|
LowPassFilterFloat _throttle_filter; // pilot throttle input filter
|
|
|
|
DerivativeFilterFloat_Size7 _throttle_slew; // throttle output slew detector
|
|
|
|
LowPassFilterFloat _throttle_slew_filter; // filter for the output of the throttle slew
|
2019-04-09 09:15:45 -03:00
|
|
|
DesiredSpoolState _spool_desired; // desired spool state
|
|
|
|
SpoolState _spool_state; // current spool mode
|
2015-02-23 02:35:10 -04:00
|
|
|
|
2017-04-17 05:15:55 -03:00
|
|
|
// mask of what channels need fast output
|
2022-05-15 18:30:16 -03:00
|
|
|
uint32_t _motor_fast_mask;
|
2016-02-03 07:55:55 -04:00
|
|
|
|
2024-07-25 22:06:14 -03:00
|
|
|
// Used with PWMType::PWM_RANGE and PWMType::PWM_ANGLE
|
2024-03-05 21:03:28 -04:00
|
|
|
struct {
|
|
|
|
// Mask of motors using scaled output
|
|
|
|
uint32_t mask;
|
|
|
|
|
|
|
|
// Offset used to convert from PWM to scaled value
|
|
|
|
float offset;
|
|
|
|
} _motor_pwm_scaled;
|
|
|
|
|
2019-10-12 06:28:24 -03:00
|
|
|
|
2016-02-03 07:55:55 -04:00
|
|
|
// pass through variables
|
2018-03-21 21:45:52 -03:00
|
|
|
float _roll_radio_passthrough; // roll input from pilot in -1 ~ +1 range. used for setup and providing servo feedback while landed
|
|
|
|
float _pitch_radio_passthrough; // pitch input from pilot in -1 ~ +1 range. used for setup and providing servo feedback while landed
|
|
|
|
float _throttle_radio_passthrough; // throttle/collective input from pilot in 0 ~ 1 range. used for setup and providing servo feedback while landed
|
|
|
|
float _yaw_radio_passthrough; // yaw input from pilot in -1 ~ +1 range. used for setup and providing servo feedback while landed
|
2016-04-13 03:33:20 -03:00
|
|
|
|
2024-07-25 22:06:14 -03:00
|
|
|
enum class PWMType : uint8_t {
|
|
|
|
NORMAL = 0,
|
|
|
|
ONESHOT = 1,
|
|
|
|
ONESHOT125 = 2,
|
|
|
|
BRUSHED = 3,
|
|
|
|
DSHOT150 = 4,
|
|
|
|
DSHOT300 = 5,
|
|
|
|
DSHOT600 = 6,
|
|
|
|
DSHOT1200 = 7,
|
|
|
|
PWM_RANGE = 8,
|
|
|
|
PWM_ANGLE = 9,
|
|
|
|
};
|
|
|
|
|
|
|
|
AP_Enum<PWMType> _pwm_type; // PWM output type
|
2018-03-21 21:45:52 -03:00
|
|
|
|
2018-08-12 11:19:20 -03:00
|
|
|
// motor failure handling
|
|
|
|
bool _thrust_boost; // true if thrust boost is enabled to handle motor failure
|
|
|
|
bool _thrust_balanced; // true when output thrust is well balanced
|
|
|
|
float _thrust_boost_ratio; // choice between highest and second highest motor output for output mixing (0 ~ 1). Zero is normal operation
|
|
|
|
|
2023-03-16 20:19:29 -03:00
|
|
|
// motor options
|
|
|
|
AP_Int16 _options;
|
|
|
|
|
2020-12-24 17:17:37 -04:00
|
|
|
MAV_TYPE _mav_type; // MAV_TYPE_GENERIC = 0;
|
|
|
|
|
2022-01-01 11:55:34 -04:00
|
|
|
// return string corresponding to frame_class
|
|
|
|
virtual const char* _get_frame_string() const = 0;
|
|
|
|
|
|
|
|
// return string corresponding to frame_type
|
|
|
|
virtual const char* get_type_string() const { return ""; }
|
|
|
|
|
2022-01-27 11:37:06 -04:00
|
|
|
// output_test_seq - spin a motor at the pwm value specified
|
|
|
|
// motor_seq is the motor's sequence number from 1 to the number of motors on the frame
|
|
|
|
// pwm value is an actual pwm value that will be output, normally in the range of 1000 ~ 2000
|
|
|
|
virtual void _output_test_seq(uint8_t motor_seq, int16_t pwm) = 0;
|
|
|
|
|
2022-01-01 11:55:34 -04:00
|
|
|
#if AP_SCRIPTING_ENABLED
|
|
|
|
// Custom frame string set from scripting
|
|
|
|
char* custom_frame_string;
|
2022-10-21 20:45:43 -03:00
|
|
|
|
|
|
|
// external limits from scripting
|
|
|
|
AP_Motors_limit external_limits;
|
2022-01-01 11:55:34 -04:00
|
|
|
#endif
|
|
|
|
|
2018-03-21 21:45:52 -03:00
|
|
|
private:
|
2019-05-03 02:27:09 -03:00
|
|
|
|
|
|
|
bool _armed; // 0 if disarmed, 1 if armed
|
|
|
|
bool _interlock; // 1 if the motor interlock is enabled (i.e. motors run), 0 if disabled (motors don't run)
|
|
|
|
bool _initialised_ok; // 1 if initialisation was successful
|
2022-06-28 03:51:52 -03:00
|
|
|
bool _spoolup_block; // true if spoolup is blocked
|
2019-05-03 02:27:09 -03:00
|
|
|
|
2019-02-10 14:04:50 -04:00
|
|
|
static AP_Motors *_singleton;
|
2012-10-26 20:59:07 -03:00
|
|
|
};
|
2019-11-28 16:23:47 -04:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_Motors *motors();
|
2020-01-14 02:24:55 -04:00
|
|
|
};
|