00001 /****************************************************************************** 00002 STDR Simulator - Simple Two DImensional Robot Simulator 00003 Copyright (C) 2013 STDR Simulator 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 3 of the License, or 00007 (at your option) any later version. 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software Foundation, 00014 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 00016 Authors : 00017 * Manos Tsardoulias, etsardou@gmail.com 00018 * Aris Thallas, aris.thallas@gmail.com 00019 * Chris Zalidis, zalidis@gmail.com 00020 ******************************************************************************/ 00021 00022 #ifndef ROBOT_H 00023 #define ROBOT_H 00024 00025 #include <ros/ros.h> 00026 #include <nodelet/nodelet.h> 00027 #include <tf/transform_broadcaster.h> 00028 #include <stdr_msgs/RobotMsg.h> 00029 #include <stdr_msgs/MoveRobot.h> 00030 #include <stdr_robot/sensors/sensor_base.h> 00031 #include <stdr_robot/sensors/laser.h> 00032 #include <stdr_robot/sensors/sonar.h> 00033 #include <stdr_robot/sensors/rfid_reader.h> 00034 #include <stdr_robot/sensors/co2.h> 00035 #include <stdr_robot/sensors/microphone.h> 00036 #include <stdr_robot/sensors/thermal.h> 00037 #include <stdr_robot/motion/motion_controller_base.h> 00038 #include <stdr_robot/motion/ideal_motion_controller.h> 00039 #include <stdr_robot/motion/omni_motion_controller.h> 00040 #include <nav_msgs/OccupancyGrid.h> 00041 #include <nav_msgs/Odometry.h> 00042 #include <actionlib/client/simple_action_client.h> 00043 #include <stdr_msgs/RegisterRobotAction.h> 00044 00049 namespace stdr_robot { 00050 00051 typedef actionlib::SimpleActionClient<stdr_msgs::RegisterRobotAction> 00052 RegisterRobotClient; 00053 typedef boost::shared_ptr<RegisterRobotClient> RegisterRobotClientPtr; 00054 00059 class Robot : public nodelet::Nodelet { 00060 00061 public: 00062 00067 Robot(void); 00068 00073 void onInit(void); 00074 00081 void initializeRobot(const actionlib::SimpleClientGoalState& state, 00082 const stdr_msgs::RegisterRobotResultConstPtr result); 00083 00089 void mapCallback(const nav_msgs::OccupancyGridConstPtr& msg); 00090 00097 bool moveRobotCallback(stdr_msgs::MoveRobot::Request& req, 00098 stdr_msgs::MoveRobot::Response& res); 00099 00104 ~Robot(void); 00105 00106 private: 00107 00112 bool collisionExists( 00113 const geometry_msgs::Pose2D& newPose, 00114 const geometry_msgs::Pose2D& collisionPoint); 00115 00116 bool collisionExistsNoPath( 00117 const geometry_msgs::Pose2D& newPose); 00118 00124 bool checkUnknownOccupancy(const geometry_msgs::Pose2D& newPose); 00125 00130 void publishTransforms(const ros::TimerEvent&); 00131 00132 00133 private: 00134 00136 ros::Subscriber _mapSubscriber; 00137 00139 ros::Timer _tfTimer; 00140 00142 ros::ServiceServer _moveRobotService; 00143 00145 SensorPtrVector _sensors; 00146 00148 nav_msgs::OccupancyGrid _map; 00149 00151 tf::TransformBroadcaster _tfBroadcaster; 00152 00154 ros::Publisher _odomPublisher; 00155 00157 geometry_msgs::Pose2D _currentPose; 00158 00160 geometry_msgs::Pose2D _previousPose; 00161 00163 MotionControllerPtr _motionControllerPtr; 00164 00166 RegisterRobotClientPtr _registerClientPtr; 00167 00169 std::vector<std::pair<float,float> > _footprint; 00170 00171 std::vector<std::pair<int,int> > getPointsBetween( 00172 int x1, int y1, int x2, int y2) ; 00173 00175 bool _previousMovementXAxis; 00176 00178 bool _previousMovementYAxis; 00179 }; 00180 00181 } // namespace stdr_robot 00182 00183 00184 #endif