You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.9 KiB
75 lines
2.9 KiB
10 years ago
|
#include "Copter.h"
|
||
|
|
||
11 years ago
|
#if FRAME_CONFIG == HELI_FRAME
|
||
|
/*
|
||
9 years ago
|
* Init and run calls for stabilize flight mode for trad heli
|
||
11 years ago
|
*/
|
||
|
|
||
|
// stabilize_init - initialise stabilize controller
|
||
7 years ago
|
bool Copter::ModeStabilize_Heli::init(bool ignore_checks)
|
||
11 years ago
|
{
|
||
|
// set target altitude to zero for reporting
|
||
|
// To-Do: make pos controller aware when it's active/inactive so it can always report the altitude error?
|
||
8 years ago
|
pos_control->set_alt_target(0);
|
||
9 years ago
|
|
||
|
// set stab collective true to use stabilize scaled collective pitch range
|
||
8 years ago
|
_copter.input_manager.set_use_stab_col(true);
|
||
9 years ago
|
|
||
11 years ago
|
return true;
|
||
|
}
|
||
|
|
||
|
// stabilize_run - runs the main stabilize controller
|
||
|
// should be called at 100hz or more
|
||
7 years ago
|
void Copter::ModeStabilize_Heli::run()
|
||
11 years ago
|
{
|
||
10 years ago
|
float target_roll, target_pitch;
|
||
11 years ago
|
float target_yaw_rate;
|
||
9 years ago
|
float pilot_throttle_scaled;
|
||
11 years ago
|
|
||
|
// Tradheli should not reset roll, pitch, yaw targets when motors are not runup, because
|
||
|
// we may be in autorotation flight. These should be reset only when transitioning from disarmed
|
||
|
// to armed, because the pilot will have placed the helicopter down on the landing pad. This is so
|
||
|
// that the servos move in a realistic fashion while disarmed for operational checks.
|
||
|
// Also, unlike multicopters we do not set throttle (i.e. collective pitch) to zero so the swash servos move
|
||
|
|
||
8 years ago
|
if(!motors->armed()) {
|
||
8 years ago
|
_copter.heli_flags.init_targets_on_arming = true;
|
||
8 years ago
|
attitude_control->set_yaw_target_to_current_heading();
|
||
7 years ago
|
attitude_control->reset_rate_controller_I_terms();
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
if(motors->armed() && _copter.heli_flags.init_targets_on_arming) {
|
||
8 years ago
|
attitude_control->set_yaw_target_to_current_heading();
|
||
7 years ago
|
attitude_control->reset_rate_controller_I_terms();
|
||
|
if (motors->get_interlock()) {
|
||
8 years ago
|
_copter.heli_flags.init_targets_on_arming=false;
|
||
10 years ago
|
}
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
// clear landing flag above zero throttle
|
||
8 years ago
|
if (motors->armed() && motors->get_interlock() && motors->rotor_runup_complete() && !ap.throttle_zero) {
|
||
9 years ago
|
set_land_complete(false);
|
||
|
}
|
||
|
|
||
11 years ago
|
// apply SIMPLE mode transform to pilot inputs
|
||
|
update_simple_mode();
|
||
|
|
||
|
// convert pilot input to lean angles
|
||
|
// To-Do: convert get_pilot_desired_lean_angles to return angles as floats
|
||
8 years ago
|
get_pilot_desired_lean_angles(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_roll, target_pitch, _copter.aparm.angle_max);
|
||
11 years ago
|
|
||
|
// get pilot's desired yaw rate
|
||
9 years ago
|
target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
||
11 years ago
|
|
||
|
// get pilot's desired throttle
|
||
8 years ago
|
pilot_throttle_scaled = _copter.input_manager.get_pilot_desired_collective(channel_throttle->get_control_in());
|
||
11 years ago
|
|
||
|
// call attitude controller
|
||
8 years ago
|
attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw(target_roll, target_pitch, target_yaw_rate, get_smoothing_gain());
|
||
11 years ago
|
|
||
|
// output pilot's throttle - note that TradHeli does not used angle-boost
|
||
8 years ago
|
attitude_control->set_throttle_out(pilot_throttle_scaled, false, g.throttle_filt);
|
||
11 years ago
|
}
|
||
|
|
||
|
#endif //HELI_FRAME
|