Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "flyer_controller/attitude_controller.h"
00035 namespace flyer_controller
00036 {
00037
00038 AttitudeController::AttitudeController() :
00039 yaw_cmd(0), max_pitch_cmd(10), max_roll_cmd(10), external_command_frame(false), external_frame_heading(0)
00040 {
00041 }
00042
00043 void AttitudeController::outputControl(const nav_msgs::OdometryConstPtr& latest_state,
00044 const starmac_msgs::OperatorCommandsConstPtr& latest_opercmd,
00045 control_mode_outputPtr& control_out)
00046
00047 {
00048 ros::Time now_time = ros::Time::now();
00049 double dt = (now_time - last_time).toSec();
00050
00051 double roll_cmd, pitch_cmd, alt_cmd;
00052 double roll_cmd_rot, pitch_cmd_rot;
00053 double relative_angle, cos_ang, sin_ang;
00054
00055 roll_cmd = latest_opercmd->roll_cmd * max_roll_cmd;
00056 pitch_cmd = latest_opercmd->pitch_cmd * max_pitch_cmd;
00057
00058 double yaw_rate_cmd = 0;
00059 if (not direct_yaw_rate_control)
00060 {
00061 yaw_cmd = yaw_cmd + latest_opercmd->yaw_cmd * max_yaw_rate_cmd * dt;
00062 yaw_rate_cmd = 0;
00063 }
00064 else
00065 {
00066
00067
00068 yaw_rate_cmd = latest_opercmd->yaw_cmd * max_yaw_rate_cmd;
00069 }
00070
00071 alt_cmd = min_alt_cmd + (max_alt_cmd - min_alt_cmd) * latest_opercmd->alt_cmd;
00072
00073 if (external_command_frame)
00074 {
00075 double current_yaw, current_pitch, current_roll;
00076 odom_msg_to_ypr(latest_state, current_yaw, current_pitch, current_roll);
00077 relative_angle = current_yaw - angles::from_degrees(external_frame_heading);
00078 cos_ang = cos(relative_angle);
00079 sin_ang = sin(relative_angle);
00080 roll_cmd_rot = cos_ang * roll_cmd + sin_ang * pitch_cmd;
00081 pitch_cmd_rot = -sin_ang * roll_cmd + cos_ang * pitch_cmd;
00082 }
00083 else
00084 {
00085 roll_cmd_rot = roll_cmd;
00086 pitch_cmd_rot = pitch_cmd;
00087 }
00088
00089 control_out->roll_cmd = roll_cmd_rot;
00090 control_out->pitch_cmd = pitch_cmd_rot;
00091 control_out->direct_thrust_commands = false;
00092 control_out->alt_cmd = alt_cmd;
00093 control_out->thrust_cmd = 0;
00094 control_out->direct_yaw_rate_commands = direct_yaw_rate_control;
00095 control_out->yaw_cmd = yaw_cmd;
00096 control_out->yaw_rate_cmd = yaw_rate_cmd;
00097 control_out->motors_on = latest_opercmd->motors_on;
00098
00099 last_time = now_time;
00100 }
00101
00102 void AttitudeController::useCurrentYaw(const nav_msgs::OdometryConstPtr& latest_state)
00103 {
00104 double current_yaw, current_pitch, current_roll;
00105 odom_msg_to_ypr(latest_state, current_yaw, current_pitch, current_roll);
00106 setYawCmd(to_degrees(current_yaw));
00107
00108 }
00109 }