ctrl_interface.h
Go to the documentation of this file.
00001 /*
00002  *  MAV Ctrl Interface
00003  *  Copyright (C) 2011, CCNY Robotics Lab
00004  *  Ivan Dryanovski <ivan.dryanovski@gmail.com>
00005  *
00006  *  http://robotics.ccny.cuny.edu
00007  *
00008  *  This program is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 #ifndef MAV_CTRL_INTERFACE_CTRL_INTERFACE_H
00023 #define MAV_CTRL_INTERFACE_CTRL_INTERFACE_H
00024 
00025 #include <boost/thread/mutex.hpp>
00026 
00027 #include <ros/ros.h>
00028 #include <ros/service_server.h>
00029 #include <tf/transform_datatypes.h>
00030 #include <tf/transform_listener.h>
00031 #include <costmap_2d/costmap_2d_ros.h>
00032 #include <navfn/navfn_ros.h>
00033 #include <nav_msgs/Path.h>
00034 
00035 #include <geometry_msgs/Pose.h>
00036 #include <geometry_msgs/PoseStamped.h>
00037 #include <geometry_msgs/PoseArray.h>
00038 #include <geometry_msgs/Twist.h>
00039 #include <geometry_msgs/TwistStamped.h>
00040 
00041 #include <mav_srvs/ChangeDesPose.h>
00042 #include <mav_srvs/PositionHold.h>
00043 #include <mav_srvs/VelocityHold.h>
00044 #include <mav_srvs/SetCtrlType.h>
00045 
00046 #include <mav_common/control_types.h>
00047 
00048 namespace mav
00049 {
00050 
00051 class CtrlInterface
00052 {
00053   private:
00054 
00055     // **** ROS-related
00056 
00057     ros::NodeHandle nh_;
00058     ros::NodeHandle nh_private_;
00059 
00060     ros::Subscriber cur_pose_subscriber_;
00061     ros::Subscriber goal2D_subscriber_; // receives goals from rviz
00062 
00063     ros::Subscriber cmd_joy_vel_subscriber_;  //receives cmd_vel from joystick
00064     ros::Subscriber cmd_plan_vel_subscriber_; //receives cmd_vel from planner
00065 
00066     ros::Publisher cmd_pose_publisher_; // passes cmd_pose to MAV
00067     ros::Publisher cmd_vel_publisher_;  // passer cmd_vel to MAV
00068 
00069     ros::Publisher goal_publisher_;  // for visualization
00070     ros::Publisher plan_publisher_;  // for visualization
00071     ros::Publisher array_publisher_; // for visualization
00072 
00073     ros::ServiceServer change_des_pose_srv_;
00074     ros::ServiceServer pos_hold_srv_;
00075     ros::ServiceServer vel_hold_srv_;
00076 
00077     ros::ServiceClient set_ctrl_type_client_;
00078 
00079     ros::Timer cmd_timer_;
00080     ros::Timer plan_timer_;
00081 
00082     tf::TransformListener tf_listener_;
00083     costmap_2d::Costmap2DROS costmap_;
00084     navfn::NavfnROS navfn_;
00085 
00086     // **** state variables    
00087 
00088     boost::mutex mutex_;
00089 
00090     ControlType ctrl_type_; // ROS-level control mode (position, velocity)
00091 
00092     geometry_msgs::PoseStamped cur_pose_;
00093     geometry_msgs::PoseStamped des_pose_;
00094     geometry_msgs::PoseStamped cur_goal_;
00095 
00096     std::vector<geometry_msgs::PoseStamped> plan_;
00097     std::vector<geometry_msgs::PoseStamped> plan_decomposed_;
00098 
00099     geometry_msgs::Twist des_vel_;
00100 
00101     // **** parameters
00102 
00103     std::string fixed_frame_;
00104 
00105     bool direct_pos_ctrl_;
00106 
00107     bool allow_joy_vel_cmd_;
00108     bool allow_plan_vel_cmd_;
00109 
00110     double wp_dist_max_;         // for waypont pos ctrl, max allowed dist b/n waypoints  
00111     double yaw_turn_tolerance_;  // when to turn on a dime
00112     double plan_goal_tolerance_; // for the NavFN planner
00113 
00114     double wp_dist_tolerance_;   // when to consider a waypoint reached
00115     double wp_angle_tolerance_;  // when to consider a waypoint reached 
00116 
00117     double goal_tf_tolerance_;   // when transfroming goals to the fixed_frame
00118    
00119     // **** member functions
00120 
00121     void initializeParams();
00122 
00123     void curPoseCallback(const geometry_msgs::PoseStamped::ConstPtr pose_msg);
00124     void goal2Dcallback(const geometry_msgs::PoseStamped::ConstPtr pose_msg);
00125 
00126     void cmdJoyVelCallback(const geometry_msgs::TwistStamped::ConstPtr twist_msg);
00127     void cmdPlanVelCallback(const geometry_msgs::Twist::ConstPtr twist_msg);
00128 
00129 
00130     bool changeDesPose(mav_srvs::ChangeDesPose::Request  &req,
00131                        mav_srvs::ChangeDesPose::Response &res);
00132 
00133     bool positionHold(mav_srvs::PositionHold::Request  &req,
00134                       mav_srvs::PositionHold::Response &res);
00135     bool velocityHold(mav_srvs::VelocityHold::Request  &req,
00136                       mav_srvs::VelocityHold::Response &res);
00137  
00138     void cmdTimerCallback(const ros::TimerEvent& event);
00139     void planTimerCallback(const ros::TimerEvent& event);
00140 
00141     void publishCmdPose();
00142     void publishCmdVel();
00143     void publishPlans();
00144 
00145     void computePlan();
00146     void computeWpFromPlan();
00147 
00148     bool decomposePlan(
00149       const std::vector<geometry_msgs::PoseStamped>& plan_in, 
00150       std::vector<geometry_msgs::PoseStamped>& plan_out);
00151 
00152     bool decomposePlan(
00153       const costmap_2d::Costmap2D& costmap,
00154       const std::vector<geometry_msgs::PoseStamped>& plan_in, 
00155       std::vector<geometry_msgs::PoseStamped>& plan_out,
00156       int start, int end);
00157 
00158   public:
00159 
00160     CtrlInterface(ros::NodeHandle nh, ros::NodeHandle nh_private);
00161     virtual ~CtrlInterface();
00162 };
00163 
00164 } // end namespace mav
00165 
00166 #endif // MAV_CTRL_INTERFACE_CTRL_INTERFACE_H


mav_ctrl_interface
Author(s): Ivan Dryanovski
autogenerated on Thu Jan 2 2014 11:28:04