control_mode_idle.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, UC Regents
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the University of California nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 #include "flyer_controller/control_mode.h"
00035 
00036 using namespace flyer_controller::ControlModeTypes;
00037 
00038 namespace flyer_controller
00039 {
00040 class ControlModeIdle : public ControlMode
00041 {
00042 
00043 public:
00044   ControlModeIdle()
00045   {
00046   }
00047 
00048   void onInit()
00049   {
00050     ROS_INFO("ControlModeIdle onInit() called");
00051     ControlMode::onInit();
00052     requestRegistration("idle");
00053     ready = true; // idle mode is always ready for inaction!
00054   }
00055 
00056 private:
00057   void controlModeCmdCallback(const control_mode_cmdConstPtr& msg)
00058   {
00059     NODELET_INFO_STREAM("Heard command: " << msg->cmd);
00060     if (msg->cmd == "mode idle")
00061     {
00062       state = IDLE;
00063       info = "";
00064     }
00065     else if (msg->cmd == "mode standby")
00066     {
00067       state = STANDBY;
00068       info = "";
00069     }
00070     else if (msg->cmd == "mode active")
00071     {
00072       if (state == STANDBY)
00073       {
00074         state = ACTIVE;
00075         info = "";
00076       }
00077       else
00078       {
00079         ROS_ERROR("Invalid transition");
00080       }
00081     }
00082     else
00083     {
00084       ROS_ERROR_STREAM("Command unknown: " << msg->cmd);
00085     }
00086   }
00087 
00088   void outputControl()
00089   {
00090     //ROS_INFO_STREAM(__PRETTY_FUNCTION__);
00091     control_mode_outputPtr output_msg(new control_mode_output);
00092     output_msg->control_mode = "idle";
00093     output_msg->motors_on = false;
00094     output_msg->direct_yaw_rate_commands = false;
00095     output_msg->yaw_cmd = 0;
00096     output_msg->yaw_rate_cmd = 0; //std::numeric_limits<double>::quiet_NaN();
00097     output_msg->direct_thrust_commands = true;
00098     output_msg->thrust_cmd = 0;
00099     output_msg->alt_cmd = 0;
00100     output_msg->header.stamp = ros::Time::now();
00101     switch (state)
00102     {
00103       case ControlModeTypes::STANDBY:
00104         output_pub.publish(output_msg);
00105         break;
00106       case ControlModeTypes::ACTIVE:
00107         output_pub.publish(output_msg);
00108         break;
00109       default:
00110         break;
00111     }
00112   }
00113 
00114 }; // class
00115 PLUGINLIB_DECLARE_CLASS(flyer_controller, ControlModeIdle, flyer_controller::ControlModeIdle, nodelet::Nodelet)
00116 ;
00117 
00118 } // namespace


flyer_controller
Author(s): Patrick Bouffard
autogenerated on Sun Jan 5 2014 11:37:53