2015-07-21 07:07:54 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
#ifndef __AP_MOTORS_HELI_RSC_H__
|
|
|
|
#define __AP_MOTORS_HELI_RSC_H__
|
|
|
|
|
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:
|
2015-12-05 06:10:52 -04:00
|
|
|
AP_MotorsHeli_RSC(RC_Channel_aux::Aux_servo_function_t aux_fn,
|
|
|
|
uint8_t default_channel,
|
2016-01-06 23:25:26 -04:00
|
|
|
uint16_t loop_rate) :
|
|
|
|
_loop_rate(loop_rate),
|
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
|
|
|
|
void set_critical_speed(int16_t critical_speed) { _critical_speed = critical_speed; }
|
|
|
|
|
|
|
|
// get_critical_speed
|
|
|
|
int16_t get_critical_speed() const { return _critical_speed; }
|
|
|
|
|
2015-08-11 21:20:28 -03:00
|
|
|
// set_idle_output
|
|
|
|
void set_idle_output(int16_t 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
|
|
|
|
int16_t get_desired_speed() const { return _desired_speed; }
|
|
|
|
|
|
|
|
// set_desired_speed
|
|
|
|
void set_desired_speed(int16_t desired_speed) { _desired_speed = desired_speed; }
|
|
|
|
|
2015-08-07 22:14:45 -03:00
|
|
|
// get_control_speed
|
2015-08-11 21:20:28 -03:00
|
|
|
int16_t 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
|
|
|
|
int16_t 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
|
|
|
|
void set_power_output_range(uint16_t power_low, uint16_t power_high);
|
|
|
|
|
|
|
|
// set_motor_load
|
|
|
|
void set_motor_load(float load) { _load_feedforward = load; }
|
|
|
|
|
2015-07-21 07:07:54 -03:00
|
|
|
// recalc_scalers
|
|
|
|
void recalc_scalers();
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
// external variables
|
|
|
|
float _loop_rate; // main loop rate
|
|
|
|
|
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
|
2015-07-21 07:07:54 -03:00
|
|
|
int16_t _critical_speed = 0; // rotor speed below which flight is not possible
|
2015-08-11 21:20:28 -03:00
|
|
|
int16_t _idle_output = 0; // motor output idle speed
|
2015-08-11 15:31:20 -03:00
|
|
|
int16_t _max_speed = 1000; // rotor maximum speed. Placeholder value until we have measured speed input (ToDo)
|
2015-07-21 07:07:54 -03:00
|
|
|
int16_t _desired_speed = 0; // latest desired rotor speed from pilot
|
2015-08-11 21:20:28 -03:00
|
|
|
int16_t _control_output = 0; // latest logic controlled output
|
|
|
|
float _rotor_ramp_output = 0; // scalar used to ramp rotor speed between _rsc_idle_output and full speed (0.0-1.0f)
|
2015-08-11 15:31:20 -03:00
|
|
|
float _rotor_runup_output = 0; // scalar used to store status of rotor run-up time (0.0-1.0f)
|
|
|
|
float _ramp_increment = 0; // the amount to increase/decrease the rotor ramp scalar during each iteration
|
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
|
2015-08-11 15:31:20 -03:00
|
|
|
float _runup_increment = 0; // the amount to increase/decrease the rotor run-up scalar during each iteration
|
2015-07-21 07:07:54 -03:00
|
|
|
bool _runup_complete = false; // flag for determining if runup is complete
|
2015-08-11 21:20:28 -03:00
|
|
|
uint16_t _power_output_low = 0; // setpoint for power output at minimum rotor power
|
|
|
|
uint16_t _power_output_high = 0; // setpoint for power output at maximum rotor power
|
|
|
|
uint16_t _power_output_range = 0; // maximum range of output power
|
|
|
|
float _load_feedforward = 0; // estimate of motor load, range 0-1.0f
|
2015-07-21 07:07:54 -03:00
|
|
|
|
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
|
|
|
|
void update_rotor_ramp(float rotor_ramp_input);
|
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
|
|
|
|
void update_rotor_runup();
|
2015-08-10 18:24:57 -03:00
|
|
|
|
2015-07-21 07:07:54 -03:00
|
|
|
// write_rsc - outputs pwm onto output rsc channel. servo_out parameter is of the range 0 ~ 1000
|
|
|
|
void write_rsc(int16_t servo_out);
|
|
|
|
};
|
|
|
|
|
2015-08-28 03:22:23 -03:00
|
|
|
#endif // AP_MOTORS_HELI_RSC_H
|