stdr_server.h
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
22 #ifndef STDR_SERVER_H
23 #define STDR_SERVER_H
24 
25 #define USAGE "\nUSAGE: stdr_server <map.yaml>\n" \
26  " map.yaml: map description file\n"
27 
28 #include <ros/ros.h>
30 #include <stdr_server/map_server.h>
31 #include <stdr_msgs/LoadMap.h>
32 #include <stdr_msgs/LoadExternalMap.h>
33 #include <stdr_msgs/RegisterGui.h>
34 #include <stdr_msgs/RegisterRobotAction.h>
35 #include <stdr_msgs/SpawnRobotAction.h>
36 #include <stdr_msgs/DeleteRobotAction.h>
37 #include <stdr_msgs/RobotIndexedMsg.h>
38 #include <stdr_msgs/RobotIndexedVectorMsg.h>
39 
40 #include <visualization_msgs/Marker.h>
41 #include <visualization_msgs/MarkerArray.h>
42 
43 #include <stdr_msgs/RfidTagVector.h>
44 #include <stdr_msgs/AddRfidTag.h>
45 #include <stdr_msgs/DeleteRfidTag.h>
46 
47 #include <stdr_msgs/CO2SourceVector.h>
48 #include <stdr_msgs/AddCO2Source.h>
49 #include <stdr_msgs/DeleteCO2Source.h>
50 
51 #include <stdr_msgs/ThermalSourceVector.h>
52 #include <stdr_msgs/AddThermalSource.h>
53 #include <stdr_msgs/DeleteThermalSource.h>
54 
55 #include <stdr_msgs/SoundSourceVector.h>
56 #include <stdr_msgs/AddSoundSource.h>
57 #include <stdr_msgs/DeleteSoundSource.h>
58 
59 #include <nodelet/NodeletLoad.h>
60 #include <nodelet/NodeletUnload.h>
61 
66 namespace stdr_server {
67 
69 
72 
75 
78 
79  typedef std::map<std::string, stdr_msgs::RobotIndexedMsg> RobotMap;
80 
81  typedef std::map<std::string, stdr_msgs::RfidTag> RfidTagMap;
82  typedef std::map<std::string, stdr_msgs::RfidTag>::iterator RfidTagMapIt;
83 
84  typedef std::map<std::string, stdr_msgs::CO2Source> CO2SourceMap;
85  typedef std::map<std::string, stdr_msgs::CO2Source>::iterator CO2SourceMapIt;
86 
87  typedef std::map<std::string, stdr_msgs::ThermalSource> ThermalSourceMap;
88  typedef std::map<std::string, stdr_msgs::ThermalSource>::iterator
90 
91  typedef std::map<std::string, stdr_msgs::SoundSource> SoundSourceMap;
92  typedef std::map<std::string, stdr_msgs::SoundSource>::iterator
94 
99  class Server
100  {
101 
102  public:
103 
110  Server(int argc, char** argv);
111 
113 
120  bool loadMapCallback(stdr_msgs::LoadMap::Request& req,
121  stdr_msgs::LoadMap::Response& res);
122 
129  bool loadExternalMapCallback(stdr_msgs::LoadExternalMap::Request& req,
130  stdr_msgs::LoadExternalMap::Response& res);
131 
133 
139  void spawnRobotCallback(const stdr_msgs::SpawnRobotGoalConstPtr& goal);
140 
146  void deleteRobotCallback(
147  const stdr_msgs::DeleteRobotGoalConstPtr& goal);
148 
155  const stdr_msgs::RegisterRobotGoalConstPtr& goal);
156 
157  private:
158 
163  void activateActionServers(void);
164 
171  bool addNewRobot(stdr_msgs::RobotMsg description,
172  stdr_msgs::SpawnRobotResult* result);
173 
180  bool deleteRobot(std::string name, stdr_msgs::DeleteRobotResult* result);
181 
188  bool addRfidTagCallback(
189  stdr_msgs::AddRfidTag::Request &req,
190  stdr_msgs::AddRfidTag::Response &res);
191 
199  stdr_msgs::DeleteRfidTag::Request &req,
200  stdr_msgs::DeleteRfidTag::Response &res);
201 
209  stdr_msgs::AddCO2Source::Request &req,
210  stdr_msgs::AddCO2Source::Response &res);
211 
219  stdr_msgs::DeleteCO2Source::Request &req,
220  stdr_msgs::DeleteCO2Source::Response &res);
221 
229  stdr_msgs::AddThermalSource::Request &req,
230  stdr_msgs::AddThermalSource::Response &res);
231 
239  stdr_msgs::DeleteThermalSource::Request &req,
240  stdr_msgs::DeleteThermalSource::Response &res);
241 
249  stdr_msgs::AddSoundSource::Request &req,
250  stdr_msgs::AddSoundSource::Response &res);
251 
259  stdr_msgs::DeleteSoundSource::Request &req,
260  stdr_msgs::DeleteSoundSource::Response &res);
261 
262  bool hasDublicateFrameIds(const stdr_msgs::RobotMsg& robot,
263  std::string &f_id);
264 
271  visualization_msgs::Marker toMarker(const stdr_msgs::CO2Source& msg,bool added);
272 
279  visualization_msgs::Marker toMarker(const stdr_msgs::ThermalSource& msg,bool added);
280 
287  visualization_msgs::Marker toMarker(const stdr_msgs::SoundSource& msg,bool added);
288 
295  visualization_msgs::Marker toMarker(const stdr_msgs::RfidTag& msg,bool added);
296 
301  void republishSources();
302 
310  template <class SourceMsg>
311  visualization_msgs::Marker createMarker(const SourceMsg& msg,bool added);
312 
316  MapServerPtr _mapServer;
317 
320 
331 
338 
340  RobotMap _robotMap;
342  int _id;
343 
345  RfidTagMap _rfidTagMap;
347  CO2SourceMap _CO2SourceMap;
349  ThermalSourceMap _thermalSourceMap;
351  SoundSourceMap _soundSourceMap;
352 
354  boost::mutex _mut;
357 
358 
361 
368 
369 
376 
383 
390  };
391 }
392 
393 
394 #endif
bool deleteThermalSourceCallback(stdr_msgs::DeleteThermalSource::Request &req, stdr_msgs::DeleteThermalSource::Response &res)
Service callback for deleting a thermal source from the environment.
void registerRobotCallback(const stdr_msgs::RegisterRobotGoalConstPtr &goal)
Action callback for robot registering.
bool hasDublicateFrameIds(const stdr_msgs::RobotMsg &robot, std::string &f_id)
MapServerPtr _mapServer
ROS publisher for the ensemble of robots.
Definition: stdr_server.h:316
ros::Publisher _CO2SourceVectorPublisher
The addThermalSource srv server.
Definition: stdr_server.h:375
bool addNewRobot(stdr_msgs::RobotMsg description, stdr_msgs::SpawnRobotResult *result)
Adds new robot to simulator.
std::map< std::string, stdr_msgs::SoundSource > SoundSourceMap
Definition: stdr_server.h:91
ros::ServiceServer _addSoundSourceServiceServer
The deleteSoundSource srv server.
Definition: stdr_server.h:385
void spawnRobotCallback(const stdr_msgs::SpawnRobotGoalConstPtr &goal)
Action callback for robot spawning.
bool deleteSoundSourceCallback(stdr_msgs::DeleteSoundSource::Request &req, stdr_msgs::DeleteSoundSource::Response &res)
Service callback for deleting a sound source from the environment.
ros::ServiceServer _deleteCO2SourceServiceServer
The CO2 source list publisher towards the GUI.
Definition: stdr_server.h:373
SpawnRobotServer _spawnRobotServer
Action server for deleting robots.
Definition: stdr_server.h:335
bool addSoundSourceCallback(stdr_msgs::AddSoundSource::Request &req, stdr_msgs::AddSoundSource::Response &res)
Service callback for adding new sound source to the environment.
bool loadExternalMapCallback(stdr_msgs::LoadExternalMap::Request &req, stdr_msgs::LoadExternalMap::Response &res)
Service callback for loading the map from GUI.
ros::Publisher _rfidTagVectorPublisher
The addCO2Source srv server.
Definition: stdr_server.h:367
The main namespace for STDR Server.
bool deleteRfidTagCallback(stdr_msgs::DeleteRfidTag::Request &req, stdr_msgs::DeleteRfidTag::Response &res)
Service callback for deleting an rfid tag from the environment.
bool addCO2SourceCallback(stdr_msgs::AddCO2Source::Request &req, stdr_msgs::AddCO2Source::Response &res)
Service callback for adding new CO2 source to the environment.
ros::NodeHandle _nh
A pointer to a MapServe object.
Definition: stdr_server.h:314
RegisterRobotServer _registerRobotServer
Action server for spawning robots.
Definition: stdr_server.h:333
ros::ServiceClient _spawnRobotClient
Action client for robot unloading.
Definition: stdr_server.h:322
RfidTagMap _rfidTagMap
An std::map that contains the CO2 sources existent in the environment.
Definition: stdr_server.h:345
std::map< std::string, stdr_msgs::RobotIndexedMsg > RobotMap
Definition: stdr_server.h:79
bool deleteRobot(std::string name, stdr_msgs::DeleteRobotResult *result)
Deletes a robot from simulator.
ros::ServiceServer _deleteRfidTagServiceServer
The rfid tag list publisher.
Definition: stdr_server.h:365
CO2SourceMap _CO2SourceMap
An std::map that contains the thermal sources existent in the environment.
Definition: stdr_server.h:347
ros::ServiceServer _deleteSoundSourceServiceServer
The sound source list publisher.
Definition: stdr_server.h:387
std::map< std::string, stdr_msgs::CO2Source >::iterator CO2SourceMapIt
Definition: stdr_server.h:85
ros::ServiceServer _loadMapService
Service server for loading maps from GUI.
Definition: stdr_server.h:326
RobotMap _robotMap
Index that shows the next robot id.
Definition: stdr_server.h:340
ros::Publisher _thermalSourceVectorPublisher
The addSoundSource srv server.
Definition: stdr_server.h:382
std::map< std::string, stdr_msgs::ThermalSource >::iterator ThermalSourceMapIt
Definition: stdr_server.h:89
ros::ServiceServer _addThermalSourceServiceServer
The deleteThermalSource srv server.
Definition: stdr_server.h:378
visualization_msgs::Marker createMarker(const SourceMsg &msg, bool added)
Creates a marker message corresponding to every element of msg that is independent of the source&#39;s sp...
SoundSourceMap _soundSourceMap
Boost mutex for conflict avoidance.
Definition: stdr_server.h:351
bool addThermalSourceCallback(stdr_msgs::AddThermalSource::Request &req, stdr_msgs::AddThermalSource::Response &res)
Service callback for adding new thermal source to the environment.
ros::ServiceServer _addCO2SourceServiceServer
The deleteCO2Source srv server.
Definition: stdr_server.h:371
ros::ServiceServer _loadExternalMapService
Service server for moving robots.
Definition: stdr_server.h:328
ThermalSourceMap _thermalSourceMap
An std::map that contains the sound sources existent in the environment.
Definition: stdr_server.h:349
std::map< std::string, stdr_msgs::RfidTag >::iterator RfidTagMapIt
Definition: stdr_server.h:82
ros::ServiceServer _addRfidTagServiceServer
The deleteRfidTag srv server.
Definition: stdr_server.h:363
ros::ServiceClient _unloadRobotClient
Service server for loading maps from files.
Definition: stdr_server.h:324
int _id
An std::map that contains the rfid tags existent in the environment.
Definition: stdr_server.h:342
bool loadMapCallback(stdr_msgs::LoadMap::Request &req, stdr_msgs::LoadMap::Response &res)
Service callback for loading the map.
ros::ServiceServer _deleteThermalSourceServiceServer
The thermal source list publisher.
Definition: stdr_server.h:380
void republishSources()
Republishes existing sources to RVIZ after a successful deletion.
visualization_msgs::Marker toMarker(const stdr_msgs::CO2Source &msg, bool added)
Translate the stdr_C02Source message into a marker message.
void deleteRobotCallback(const stdr_msgs::DeleteRobotGoalConstPtr &goal)
Action callback for robot deletion.
bool addRfidTagCallback(stdr_msgs::AddRfidTag::Request &req, stdr_msgs::AddRfidTag::Response &res)
Service callback for adding new rfid tag to the environment.
Implements the STDR server functionalities.
Definition: stdr_server.h:99
ros::Publisher _soundSourceVectorPublisher
Definition: stdr_server.h:389
std::map< std::string, stdr_msgs::SoundSource >::iterator SoundSourceMapIt
Definition: stdr_server.h:93
bool deleteCO2SourceCallback(stdr_msgs::DeleteCO2Source::Request &req, stdr_msgs::DeleteCO2Source::Response &res)
Service callback for deleting a CO2 source from the environment.
actionlib::SimpleActionServer< stdr_msgs::RegisterRobotAction > RegisterRobotServer
Definition: stdr_server.h:74
ros::Publisher _sourceVectorPublisherRviz
The addRfidTag srv server.
Definition: stdr_server.h:360
boost::mutex _mut
Boost condition variable for conflicting avoidance.
Definition: stdr_server.h:354
actionlib::SimpleActionServer< stdr_msgs::SpawnRobotAction > SpawnRobotServer
Definition: stdr_server.h:71
boost::condition_variable _cond
A general Rviz publisher for all source types.
Definition: stdr_server.h:356
ros::ServiceServer _moveRobotService
Action server for registering robots.
Definition: stdr_server.h:330
void activateActionServers(void)
Initializes the spawn,delete,register action servers.
std::map< std::string, stdr_msgs::ThermalSource > ThermalSourceMap
Definition: stdr_server.h:87
std::map< std::string, stdr_msgs::RfidTag > RfidTagMap
Definition: stdr_server.h:81
ros::Publisher _robotsPublisher
Action client for robot spawning.
Definition: stdr_server.h:319
DeleteRobotServer _deleteRobotServer
An std::map that contains the robots based on theor frame_id.
Definition: stdr_server.h:337
boost::shared_ptr< MapServer > MapServerPtr
Definition: stdr_server.h:68
std::map< std::string, stdr_msgs::CO2Source > CO2SourceMap
Definition: stdr_server.h:84
actionlib::SimpleActionServer< stdr_msgs::DeleteRobotAction > DeleteRobotServer
Definition: stdr_server.h:77
Server(int argc, char **argv)
Default constructor.
Definition: stdr_server.cpp:30


stdr_server
Author(s): Chris Zalidis
autogenerated on Mon Jun 10 2019 15:15:07