123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #pragma once
- #include <inttypes.h>
- #include <AP_Common/AP_Common.h>
- #include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
- #include <RC_Channel/RC_Channel.h>
- #include <SRV_Channel/SRV_Channel.h>
- #include "AP_Motors_Class.h"
- #include "AP_MotorsHeli_RSC.h"
- #define AP_MOTORS_HELI_SPEED_DEFAULT 125
- #define AP_MOTORS_HELI_SWASH_CYCLIC_MAX 2500
- #define AP_MOTORS_HELI_COLLECTIVE_MIN 1250
- #define AP_MOTORS_HELI_COLLECTIVE_MAX 1750
- #define AP_MOTORS_HELI_COLLECTIVE_MID 1500
- #define AP_MOTORS_HELI_NOFLYBAR 0
- #define AP_MOTORS_HELI_RSC CH_8
- class AP_HeliControls;
- class AP_MotorsHeli : public AP_Motors {
- public:
-
- AP_MotorsHeli( uint16_t loop_rate,
- uint16_t speed_hz = AP_MOTORS_HELI_SPEED_DEFAULT) :
- AP_Motors(loop_rate, speed_hz),
- _main_rotor(SRV_Channel::k_heli_rsc, AP_MOTORS_HELI_RSC)
- {
- AP_Param::setup_object_defaults(this, var_info);
- };
-
- void init(motor_frame_class frame_class, motor_frame_type frame_type) override;
-
- void set_frame_class_and_type(motor_frame_class frame_class, motor_frame_type frame_type) override;
-
- virtual void set_update_rate( uint16_t speed_hz ) override = 0;
-
- void output_min() override;
-
-
-
- virtual void output_test_seq(uint8_t motor_seq, int16_t pwm) override = 0;
-
-
-
-
- virtual bool parameter_check(bool display_msg) const;
-
- virtual bool has_flybar() const { return AP_MOTORS_HELI_NOFLYBAR; }
-
- void set_collective_for_landing(bool landing) { _heliflags.landing_collective = landing; }
-
- void set_inverted_flight(bool inverted) { _heliflags.inverted_flight = inverted; }
-
- uint8_t get_rsc_mode() const { return _main_rotor.get_control_mode(); }
-
- float get_rsc_setpoint() const { return _main_rotor._rsc_setpoint.get() * 0.01f; }
-
-
- virtual void set_rpm(float rotor_rpm) = 0;
-
- virtual void set_desired_rotor_speed(float desired_speed) = 0;
-
- virtual float get_desired_rotor_speed() const = 0;
-
- virtual float get_main_rotor_speed() const = 0;
-
- bool rotor_runup_complete() const { return _heliflags.rotor_runup_complete; }
-
- virtual bool rotor_speed_above_critical() const = 0;
-
-
- virtual float get_governor_output() const = 0;
-
-
- virtual float get_control_output() const = 0;
-
-
- virtual uint16_t get_motor_mask() override = 0;
- virtual void set_acro_tail(bool set) {}
-
- virtual void ext_gyro_gain(float gain) {}
-
- void output() override;
-
- virtual bool supports_yaw_passthrough() const { return false; }
- float get_throttle_hover() const override { return 0.5f; }
-
- bool init_targets_on_arming() const { return _heliflags.init_targets_on_arming; }
-
- static const struct AP_Param::GroupInfo var_info[];
- protected:
-
- enum ServoControlModes {
- SERVO_CONTROL_MODE_AUTOMATED = 0,
- SERVO_CONTROL_MODE_MANUAL_PASSTHROUGH,
- SERVO_CONTROL_MODE_MANUAL_MAX,
- SERVO_CONTROL_MODE_MANUAL_CENTER,
- SERVO_CONTROL_MODE_MANUAL_MIN,
- SERVO_CONTROL_MODE_MANUAL_OSCILLATE,
- };
-
- void output_armed_stabilizing() override;
- void output_armed_zero_throttle();
- void output_disarmed();
-
- AP_MotorsHeli_RSC _main_rotor;
-
- virtual void update_motor_control(RotorControlState state) = 0;
-
- void output_logic();
-
- virtual void output_to_motors() = 0;
-
- void reset_flight_controls();
-
- void update_throttle_filter() override;
-
- virtual void move_actuators(float roll_out, float pitch_out, float coll_in, float yaw_out) = 0;
-
- void reset_swash_servo(SRV_Channel::Aux_servo_function_t function);
-
- virtual bool init_outputs() = 0;
-
- virtual void calculate_armed_scalars() = 0;
-
- virtual void calculate_scalars() = 0;
-
-
- virtual void servo_test() = 0;
-
- void rc_write_swash(uint8_t chan, float swash_in);
-
- struct heliflags_type {
- uint8_t landing_collective : 1;
- uint8_t rotor_runup_complete : 1;
- uint8_t inverted_flight : 1;
- uint8_t init_targets_on_arming : 1;
- uint8_t save_rsc_mode : 1;
- } _heliflags;
-
- AP_Int16 _cyclic_max;
- AP_Int16 _collective_min;
- AP_Int16 _collective_max;
- AP_Int16 _collective_mid;
- AP_Int8 _servo_mode;
- AP_Int8 _servo_test;
-
- float _collective_mid_pct = 0.0f;
- uint8_t _servo_test_cycle_counter = 0;
- motor_frame_type _frame_type;
- motor_frame_class _frame_class;
- };
|