set_mode(flight_modes[switchPosition])
exit_mode(control_mode, mode);
control_mode = mode;
Log_Write_Mode(control_mode);
end
-----------flight_mode.pde--------------
triggered by update_flight_mode()
100hz or more (pixhawk 400hz, called directly in fast_loop)
switch (control_mode)
-- stabilize_run();
end
-----------control_stabilize.pde--------------
inside stabilize_run();
// convert pilot input to lean angles
get_pilot_desired_lean_angles(g.rc_1.control_in, g.rc_2.control_in, target_roll, target_pitch); (range 4500)
- where does control_in come from:
--radio.pde--
init_rc_in()
g.rc_1.set_angle(ROLL_PITCH_INPUT_MAX); //4500 g.rc_2.set_angle(ROLL_PITCH_INPUT_MAX); g.rc_3.set_range(g.throttle_min, g.throttle_max); g.rc_4.set_angle(4500); g.rc_1.set_type(RC_CHANNEL_TYPE_ANGLE_RAW); g.rc_2.set_type(RC_CHANNEL_TYPE_ANGLE_RAW); g.rc_4.set_type(RC_CHANNEL_TYPE_ANGLE_RAW); --RCchannel.cpp-- |
--set_pwm_no_deadzone(int16_t pwm)-- if (_type == RC_CHANNEL_TYPE_RANGE) { control_in = pwm_to_range_dz(0); } else { //RC_CHANNEL_ANGLE, RC_CHANNEL_ANGLE_RAW control_in = pwm_to_angle_dz(0); } |
target_yaw_rate = get_pilot_desired_yaw_rate(g.rc_4.control_in);
// get pilot's desired throttle
pilot_throttle_scaled = get_pilot_desired_throttle(g.rc_3.control_in);
// call attitude controller
attitude_control.angle_ef_roll_pitch_rate_ef_yaw_smooth(target_roll, target_pitch, target_yaw_rate, get_smoothing_gain());
parameter used above : RC_FEEL_RP, ACCEL_RP_MAX
// calculate earth-frame feed forward roll rate using linear response when close to the target, sqrt response when we're further away
angle_to_target = roll_angle_ef (=target_roll,-4500~+4500) - _angle_ef_target.x (angle controller earth-frame targets);
// body-frame rate controller is run directly from 100hz loop
// output pilot's throttle
attitude_control.set_throttle_out(pilot_throttle_scaled, true);