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/control_mode_attitude.h"
00035
00036 namespace flyer_controller
00037 {
00038 void ControlModeAttitude::onInit()
00039 {
00040 JoystickMode::onInit();
00041
00042 double max_pitch_cmd = 10;
00043 double max_roll_cmd = 10;
00044 bool external_command_frame = false;
00045 double external_frame_heading = 0;
00046 bool direct_yaw_rate_control = false;
00047
00048 nh_priv.param("max_pitch_cmd", max_pitch_cmd, max_pitch_cmd);
00049 nh_priv.param("max_roll_cmd", max_roll_cmd, max_roll_cmd);
00050 nh_priv.param("external_command_frame", external_command_frame, external_command_frame);
00051 nh_priv.param("external_frame_heading", external_frame_heading, external_frame_heading);
00052 nh_priv.param("direct_yaw_rate_control", direct_yaw_rate_control, direct_yaw_rate_control);
00053 nh_priv.param("step_input_mode_enabled", step_input_mode_enabled, false);
00054 nh_priv.param("step_input_magnitude", step_input_magnitude, 0.5);
00055 nh_priv.param("step_input_joystick_roll_axis", step_input_joystick_roll_axis, 4);
00056 nh_priv.param("step_input_joystick_pitch_axis", step_input_joystick_pitch_axis, 5);
00057 CHECK_PARAMETER(max_pitch_cmd >= 0, "parameter value out of range");
00058 CHECK_PARAMETER(max_roll_cmd >= 0, "parameter value out of range");
00059
00060 CHECK_PARAMETER((external_frame_heading >= -360) && (external_frame_heading <= 360), "parameter value out of range");
00061 NODELET_INFO_STREAM("max_pitch_cmd = " << max_pitch_cmd);
00062
00063 att_control.configure(external_command_frame, external_frame_heading, direct_yaw_rate_control, max_pitch_cmd,
00064 max_roll_cmd, max_yaw_rate_cmd, min_alt_cmd, max_alt_cmd);
00065
00066 requestRegistration(mode_name_);
00067 }
00068
00069
00070 void ControlModeAttitude::outputControl()
00071 {
00072 control_mode_outputPtr output_msg(new control_mode_output);
00073 bool do_calcs = false;
00074 bool do_publish = false;
00075 output_msg->header.stamp = ros::Time::now();
00076
00077 switch (state)
00078 {
00079 case ControlModeTypes::STANDBY:
00080 do_calcs = got_first_joy and got_first_state;
00081 do_publish = true;
00082 break;
00083 case ControlModeTypes::ACTIVE:
00084 do_calcs = true;
00085 do_publish = true;
00086 break;
00087 default:
00088 break;
00089 }
00090
00091 if (do_calcs)
00092 {
00093 att_control.outputControl(boost::make_shared<nav_msgs::Odometry>(latest_state), boost::make_shared<
00094 starmac_msgs::OperatorCommands>(latest_opercmd), output_msg);
00095 if (step_input_mode_enabled)
00096 {
00097
00098 }
00099 }
00100
00101 if (do_publish)
00102 {
00103 output_msg->control_mode = "attitude";
00104 output_pub.publish(output_msg);
00105 }
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 void ControlModeAttitude::reportStatusTimerCallback(const ros::TimerEvent& e)
00129 {
00130 control_mode_statusPtr msg(new control_mode_status);
00131
00132 msg->state = state;
00133 msg->info = info;
00134 msg->header.stamp = e.current_real;
00135 ready = (got_first_joy and got_first_state);
00136 msg->ready = ready;
00137 control_mode_status_pub.publish(msg);
00138 diag_updater.update();
00139 }
00140
00141 void ControlModeAttitude::controlModeCmdCallback(const control_mode_cmdConstPtr& msg)
00142 {
00143 NODELET_INFO_STREAM("Heard command: " << msg->cmd);
00144 if (msg->cmd == "mode idle")
00145 {
00146 state = IDLE;
00147 info = "";
00148 }
00149 else if (msg->cmd == "mode standby")
00150 {
00151 state = STANDBY;
00152 info = "";
00153 }
00154 else if (msg->cmd == "mode active")
00155 {
00156 if (state == STANDBY)
00157 {
00158 state = ACTIVE;
00159 att_control.useCurrentYaw(boost::make_shared<nav_msgs::Odometry>(latest_state));
00160 info = "";
00161 }
00162 else
00163 {
00164 NODELET_ERROR("Invalid transition");
00165 }
00166 }
00167 else
00168 {
00169 NODELET_ERROR_STREAM("Command unknown: " << msg->cmd);
00170 }
00171 }
00172
00173 PLUGINLIB_DECLARE_CLASS(flyer_controller, ControlModeAttitude, flyer_controller::ControlModeAttitude, nodelet::Nodelet)
00174
00175 }