2013-05-29 20:51:34 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2012-04-02 05:26:37 -03:00
|
|
|
|
|
|
|
/// @file AP_MotorsMatrix.h
|
|
|
|
/// @brief Motor control class for Matrixcopters
|
|
|
|
|
2012-10-26 20:59:07 -03:00
|
|
|
#ifndef __AP_MOTORS_MATRIX_H__
|
|
|
|
#define __AP_MOTORS_MATRIX_H__
|
2012-04-02 05:26:37 -03:00
|
|
|
|
|
|
|
#include <AP_Common.h>
|
|
|
|
#include <AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
|
|
|
|
#include <RC_Channel.h> // RC Channel Library
|
2012-10-26 20:59:07 -03:00
|
|
|
#include "AP_Motors_Class.h"
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2013-04-25 05:52:19 -03:00
|
|
|
#define AP_MOTORS_MATRIX_YAW_FACTOR_CW -1
|
|
|
|
#define AP_MOTORS_MATRIX_YAW_FACTOR_CCW 1
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2013-05-26 23:21:31 -03:00
|
|
|
#define AP_MOTORS_MATRIX_YAW_LOWER_LIMIT_PWM 200
|
2012-10-09 03:48:15 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
/// @class AP_MotorsMatrix
|
|
|
|
class AP_MotorsMatrix : public AP_Motors {
|
|
|
|
public:
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
/// Constructor
|
2014-02-10 00:22:18 -04:00
|
|
|
AP_MotorsMatrix( RC_Channel& rc_roll, RC_Channel& rc_pitch, RC_Channel& rc_throttle, RC_Channel& rc_yaw, uint16_t speed_hz = AP_MOTORS_SPEED_DEFAULT) :
|
2014-02-09 05:10:09 -04:00
|
|
|
AP_Motors(rc_roll, rc_pitch, rc_throttle, rc_yaw, speed_hz)
|
|
|
|
{};
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
// init
|
|
|
|
virtual void Init();
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-09-13 09:31:13 -03:00
|
|
|
// set update rate to motors - a value in hertz
|
2012-08-17 03:20:27 -03:00
|
|
|
// you must have setup_motors before calling this
|
2013-05-14 05:35:27 -03:00
|
|
|
virtual void set_update_rate( uint16_t speed_hz );
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
// set frame orientation (normally + or X)
|
2013-05-14 05:35:27 -03:00
|
|
|
virtual void set_frame_orientation( uint8_t new_orientation );
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
// enable - starts allowing signals to be sent to motors
|
2013-05-14 05:35:27 -03:00
|
|
|
virtual void enable();
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2014-04-28 04:29:09 -03:00
|
|
|
// output_test - 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(uint8_t motor_seq, int16_t pwm);
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
// output_min - sends minimum values out to the motors
|
|
|
|
virtual void output_min();
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2013-04-25 05:52:19 -03:00
|
|
|
// add_motor using just position and yaw_factor (or prop direction)
|
2013-05-14 06:03:34 -03:00
|
|
|
void add_motor(int8_t motor_num, float angle_degrees, float yaw_factor, uint8_t testing_order);
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
// remove_motor
|
2013-05-14 05:41:12 -03:00
|
|
|
void remove_motor(int8_t motor_num);
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
// remove_all_motors - removes all motor definitions
|
2013-05-14 05:41:12 -03:00
|
|
|
void remove_all_motors();
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-08-17 03:20:27 -03:00
|
|
|
// setup_motors - configures the motors for a given frame type - should be overwritten by child classes
|
|
|
|
virtual void setup_motors() {
|
|
|
|
remove_all_motors();
|
|
|
|
};
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2014-07-26 04:29:48 -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
|
|
|
|
virtual uint16_t get_motor_mask();
|
|
|
|
|
2012-04-02 05:26:37 -03:00
|
|
|
protected:
|
2012-08-17 03:20:27 -03:00
|
|
|
// output - sends commands to the motors
|
|
|
|
virtual void output_armed();
|
|
|
|
virtual void output_disarmed();
|
|
|
|
|
|
|
|
// add_motor using raw roll, pitch, throttle and yaw factors
|
2013-05-14 06:03:34 -03:00
|
|
|
void add_motor_raw(int8_t motor_num, float roll_fac, float pitch_fac, float yaw_fac, uint8_t testing_order);
|
2012-08-17 03:20:27 -03:00
|
|
|
|
|
|
|
float _roll_factor[AP_MOTORS_MAX_NUM_MOTORS]; // each motors contribution to roll
|
|
|
|
float _pitch_factor[AP_MOTORS_MAX_NUM_MOTORS]; // each motors contribution to pitch
|
|
|
|
float _yaw_factor[AP_MOTORS_MAX_NUM_MOTORS]; // each motors contribution to yaw (normally 1 or -1)
|
2013-05-14 06:03:34 -03:00
|
|
|
uint8_t _test_order[AP_MOTORS_MAX_NUM_MOTORS]; // order of the motors in the test sequence
|
2012-08-17 03:20:27 -03:00
|
|
|
};
|
2012-04-02 05:26:37 -03:00
|
|
|
|
2012-10-26 20:59:07 -03:00
|
|
|
#endif // AP_MOTORSMATRIX
|