2015-07-21 07:07:54 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2016-02-17 21:25:38 -04:00
|
|
|
#pragma once
|
2015-07-21 07:07:54 -03:00
|
|
|
|
2015-08-15 13:42:46 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
|
|
|
|
#include <RC_Channel/RC_Channel.h> // RC Channel Library
|
2015-07-21 07:07:54 -03:00
|
|
|
|
2015-08-07 20:52:22 -03:00
|
|
|
// rotor controller states
|
2015-08-28 03:20:42 -03:00
|
|
|
enum RotorControlState {
|
|
|
|
ROTOR_CONTROL_STOP = 0,
|
|
|
|
ROTOR_CONTROL_IDLE,
|
|
|
|
ROTOR_CONTROL_ACTIVE
|
|
|
|
};
|
2015-08-07 20:52:22 -03:00
|
|
|
|
2015-08-11 15:31:20 -03:00
|
|
|
// rotor control modes
|
2015-08-28 03:22:23 -03:00
|
|
|
enum RotorControlMode {
|
|
|
|
ROTOR_CONTROL_MODE_DISABLED = 0,
|
|
|
|
ROTOR_CONTROL_MODE_SPEED_PASSTHROUGH,
|
|
|
|
ROTOR_CONTROL_MODE_SPEED_SETPOINT,
|
|
|
|
ROTOR_CONTROL_MODE_OPEN_LOOP_POWER_OUTPUT,
|
|
|
|
ROTOR_CONTROL_MODE_CLOSED_LOOP_POWER_OUTPUT
|
|
|
|
};
|
2015-08-11 15:31:20 -03:00
|
|
|
|
2015-07-21 07:07:54 -03:00
|
|
|
class AP_MotorsHeli_RSC {
|
|
|
|
public:
|
2016-06-04 05:03:16 -03:00
|
|
|
friend class AP_MotorsHeli_Single;
|
|
|
|
|
2015-12-05 06:10:52 -04:00
|
|
|
AP_MotorsHeli_RSC(RC_Channel_aux::Aux_servo_function_t aux_fn,
|
2016-06-04 22:20:58 -03:00
|
|
|
uint8_t default_channel) :
|
2015-12-05 06:10:52 -04:00
|
|
|
_aux_fn(aux_fn),
|
2016-01-06 23:25:26 -04:00
|
|
|
_default_channel(default_channel)
|
2015-07-21 07:07:54 -03:00
|
|
|
{};
|
|
|
|
|
2015-08-11 12:01:11 -03:00
|
|
|
// init_servo - servo initialization on start-up
|
|
|
|
void init_servo();
|
|
|
|
|
2015-08-11 15:31:20 -03:00
|
|
|
// set_control_mode - sets control mode
|
2015-08-28 03:22:23 -03:00
|
|
|
void set_control_mode(RotorControlMode mode) { _control_mode = mode; }
|
2015-08-11 15:31:20 -03:00
|
|
|
|
2015-07-21 07:07:54 -03:00
|
|
|
// set_critical_speed
|
2016-02-03 04:53:34 -04:00
|
|
|
void set_critical_speed(float critical_speed) { _critical_speed = critical_speed; }
|
2015-07-21 07:07:54 -03:00
|
|
|
|
|
|
|
// get_critical_speed
|
2016-02-03 04:53:34 -04:00
|
|
|
float get_critical_speed() const { return _critical_speed; }
|
2015-07-21 07:07:54 -03:00
|
|
|
|
2015-08-11 21:20:28 -03:00
|
|
|
// set_idle_output
|
2016-02-03 04:51:45 -04:00
|
|
|
float get_idle_output() { return _idle_output; }
|
2016-02-03 04:53:34 -04:00
|
|
|
void set_idle_output(float idle_output) { _idle_output = idle_output; }
|
2015-08-07 22:14:45 -03:00
|
|
|
|
2015-07-21 07:07:54 -03:00
|
|
|
// get_desired_speed
|
2016-02-03 04:53:34 -04:00
|
|
|
float get_desired_speed() const { return _desired_speed; }
|
2015-07-21 07:07:54 -03:00
|
|
|
|
|
|
|
// set_desired_speed
|
2016-02-03 04:53:34 -04:00
|
|
|
void set_desired_speed(float desired_speed) { _desired_speed = desired_speed; }
|
2015-07-21 07:07:54 -03:00
|
|
|
|
2015-08-07 22:14:45 -03:00
|
|
|
// get_control_speed
|
2016-02-03 04:53:34 -04:00
|
|
|
float get_control_output() const { return _control_output; }
|
2015-08-07 22:14:45 -03:00
|
|
|
|
2015-08-11 15:31:20 -03:00
|
|
|
// get_rotor_speed - return estimated or measured rotor speed
|
2016-02-03 04:53:34 -04:00
|
|
|
float get_rotor_speed() const;
|
2015-07-21 07:07:54 -03:00
|
|
|
|
|
|
|
// is_runup_complete
|
|
|
|
bool is_runup_complete() const { return _runup_complete; }
|
|
|
|
|
|
|
|
// set_ramp_time
|
2015-08-06 05:22:56 -03:00
|
|
|
void set_ramp_time(int8_t ramp_time) { _ramp_time = ramp_time; }
|
2015-07-21 07:07:54 -03:00
|
|
|
|
|
|
|
// set_runup_time
|
2015-08-06 05:22:56 -03:00
|
|
|
void set_runup_time(int8_t runup_time) { _runup_time = runup_time; }
|
2015-07-21 07:07:54 -03:00
|
|
|
|
2015-08-11 21:20:28 -03:00
|
|
|
// set_power_output_range
|
2016-06-29 23:28:34 -03:00
|
|
|
void set_power_output_range(float power_low, float power_high, float power_negc, uint16_t slewrate);
|
2015-08-11 21:20:28 -03:00
|
|
|
|
2016-06-29 23:28:34 -03:00
|
|
|
// set_motor_load. +ve numbers for +ve collective. -ve numbers for negative collective
|
2015-08-11 21:20:28 -03:00
|
|
|
void set_motor_load(float load) { _load_feedforward = load; }
|
|
|
|
|
2015-08-07 22:14:45 -03:00
|
|
|
// output - update value to send to ESC/Servo
|
2015-08-28 03:20:42 -03:00
|
|
|
void output(RotorControlState state);
|
2015-07-21 07:07:54 -03:00
|
|
|
|
|
|
|
private:
|
2016-06-04 22:20:58 -03:00
|
|
|
uint64_t _last_update_us;
|
|
|
|
|
2015-12-05 06:10:52 -04:00
|
|
|
// channel setup for aux function
|
|
|
|
RC_Channel_aux::Aux_servo_function_t _aux_fn;
|
|
|
|
uint8_t _default_channel;
|
|
|
|
|
2015-07-21 07:07:54 -03:00
|
|
|
// internal variables
|
2015-08-28 03:22:23 -03:00
|
|
|
RotorControlMode _control_mode = ROTOR_CONTROL_MODE_DISABLED; // motor control mode, Passthrough or Setpoint
|
2016-02-03 04:53:34 -04:00
|
|
|
float _critical_speed = 0.0f; // rotor speed below which flight is not possible
|
|
|
|
float _idle_output = 0.0f; // motor output idle speed
|
|
|
|
float _desired_speed = 0.0f; // latest desired rotor speed from pilot
|
|
|
|
float _control_output = 0.0f; // latest logic controlled output
|
|
|
|
float _rotor_ramp_output = 0.0f; // scalar used to ramp rotor speed between _rsc_idle_output and full speed (0.0-1.0f)
|
|
|
|
float _rotor_runup_output = 0.0f; // scalar used to store status of rotor run-up time (0.0-1.0f)
|
2015-07-21 07:07:54 -03:00
|
|
|
int8_t _ramp_time = 0; // time in seconds for the output to the main rotor's ESC to reach full speed
|
|
|
|
int8_t _runup_time = 0; // time in seconds for the main rotor to reach full speed. Must be longer than _rsc_ramp_time
|
|
|
|
bool _runup_complete = false; // flag for determining if runup is complete
|
2016-02-03 04:53:34 -04:00
|
|
|
float _power_output_low = 0.0f; // setpoint for power output at minimum rotor power
|
|
|
|
float _power_output_high = 0.0f; // setpoint for power output at maximum rotor power
|
2016-06-29 23:28:34 -03:00
|
|
|
float _power_output_negc = 0.0f; // setpoint for power output at full negative collective
|
|
|
|
uint16_t _power_slewrate = 0; // slewrate for throttle (percentage per second)
|
2016-02-03 04:53:34 -04:00
|
|
|
float _load_feedforward = 0.0f; // estimate of motor load, range 0-1.0f
|
2015-07-21 07:07:54 -03:00
|
|
|
|
2016-06-04 05:03:16 -03:00
|
|
|
AP_Int16 _pwm_min;
|
|
|
|
AP_Int16 _pwm_max;
|
|
|
|
AP_Int8 _pwm_rev;
|
|
|
|
|
2015-08-11 15:31:20 -03:00
|
|
|
// update_rotor_ramp - slews rotor output scalar between 0 and 1, outputs float scalar to _rotor_ramp_output
|
2016-06-04 22:20:58 -03:00
|
|
|
void update_rotor_ramp(float rotor_ramp_input, float dt);
|
2015-08-07 22:14:45 -03:00
|
|
|
|
2015-08-11 15:31:20 -03:00
|
|
|
// update_rotor_runup - function to slew rotor runup scalar, outputs float scalar to _rotor_runup_ouptut
|
2016-06-04 22:20:58 -03:00
|
|
|
void update_rotor_runup(float dt);
|
2015-08-10 18:24:57 -03:00
|
|
|
|
2016-02-03 04:53:34 -04:00
|
|
|
// write_rsc - outputs pwm onto output rsc channel. servo_out parameter is of the range 0 ~ 1
|
|
|
|
void write_rsc(float servo_out);
|
2015-07-21 07:07:54 -03:00
|
|
|
};
|