31 :_spawnRobotServer(_nh,
"stdr_server/spawn_robot",
32 boost::bind(&
Server::spawnRobotCallback, this, _1), false)
34 ,_registerRobotServer(_nh,
"stdr_server/register_robot",
35 boost::bind(&
Server::registerRobotCallback, this, _1), false)
37 ,_deleteRobotServer(_nh,
"stdr_server/delete_robot",
38 boost::bind(&
Server::deleteRobotCallback, this, _1), false)
51 std::string fname(argv[1]);
62 "/stdr_server/load_static_map_external",
68 ROS_WARN(
"Trying to register to robot_manager/load_nodelet...");
72 (
"robot_manager/load_nodelet",
true);
77 ROS_WARN(
"Trying to register to robot_manager/unload_nodelet...");
85 (
"stdr_server/active_robots", 10,
true);
89 "stdr_server/sources_visualization_markers", 1,
true);
101 "stdr_server/rfid_list", 1,
true);
106 "stdr_server/add_co2_source",
114 "stdr_server/co2_sources_list", 1,
true);
119 "stdr_server/add_thermal_source",
128 "stdr_server/thermal_sources_list", 1,
true);
133 "stdr_server/add_sound_source",
141 "stdr_server/sound_sources_list", 1,
true);
148 stdr_msgs::AddRfidTag::Request &req,
149 stdr_msgs::AddRfidTag::Response &res)
152 stdr_msgs::RfidTag new_rfid = req.newTag;
156 res.message =
"Duplicate rfid_id";
161 _rfidTagMap.insert(std::pair<std::string, stdr_msgs::RfidTag>(
162 new_rfid.tag_id, new_rfid));
165 stdr_msgs::RfidTagVector rfidTagList;
166 visualization_msgs::MarkerArray RFIDMarkerArray;
170 rfidTagList.rfid_tags.push_back(it->second);
171 RFIDMarkerArray.markers.push_back(
toMarker(it->second,
true));
189 stdr_msgs::AddCO2Source::Request &req,
190 stdr_msgs::AddCO2Source::Response &res)
193 stdr_msgs::CO2Source new_source = req.newSource;
197 res.message =
"Duplicate CO2 id";
202 _CO2SourceMap.insert(std::pair<std::string, stdr_msgs::CO2Source>(
203 new_source.id, new_source));
206 stdr_msgs::CO2SourceVector CO2SourceList;
207 visualization_msgs::MarkerArray C02MarkerArray;
212 CO2SourceList.co2_sources.push_back(it->second);
213 C02MarkerArray.markers.push_back(
toMarker(it->second,
true));
231 stdr_msgs::AddThermalSource::Request &req,
232 stdr_msgs::AddThermalSource::Response &res)
235 stdr_msgs::ThermalSource new_source = req.newSource;
239 res.message =
"Duplicate thermal source is";
245 new_source.id, new_source));
248 stdr_msgs::ThermalSourceVector thermalSourceList;
249 visualization_msgs::MarkerArray thermalMarkerArray;
254 thermalSourceList.thermal_sources.push_back(it->second);
255 thermalMarkerArray.markers.push_back(
toMarker(it->second,
true));
273 stdr_msgs::AddSoundSource::Request &req,
274 stdr_msgs::AddSoundSource::Response &res)
277 stdr_msgs::SoundSource new_source = req.newSource;
281 res.message =
"Duplicate sound source is";
287 new_source.id, new_source));
290 stdr_msgs::SoundSourceVector soundSourceList;
291 visualization_msgs::MarkerArray soundMarkerArray;
296 soundSourceList.sound_sources.push_back(it->second);
297 soundMarkerArray.markers.push_back(
toMarker(it->second,
true));
315 stdr_msgs::DeleteRfidTag::Request &req,
316 stdr_msgs::DeleteRfidTag::Response &res)
319 std::string name = req.name;
323 visualization_msgs::MarkerArray rfidMarkerArray;
330 stdr_msgs::RfidTagVector rfidTagList;
335 rfidTagList.rfid_tags.push_back(it->second);
352 stdr_msgs::DeleteCO2Source::Request &req,
353 stdr_msgs::DeleteCO2Source::Response &res)
355 std::string name = req.name;
359 visualization_msgs::MarkerArray CO2MarkerArray;
366 stdr_msgs::CO2SourceVector CO2SourceList;
371 CO2SourceList.co2_sources.push_back(it->second);
389 stdr_msgs::DeleteThermalSource::Request &req,
390 stdr_msgs::DeleteThermalSource::Response &res)
393 std::string name = req.name;
397 visualization_msgs::MarkerArray thermalMarkerArray;
404 stdr_msgs::ThermalSourceVector thermalSourceList;
409 thermalSourceList.thermal_sources.push_back(it->second);
426 stdr_msgs::DeleteSoundSource::Request &req,
427 stdr_msgs::DeleteSoundSource::Response &res)
430 std::string name = req.name;
434 visualization_msgs::MarkerArray soundMarkerArray;
441 stdr_msgs::SoundSourceVector soundSourceList;
447 soundSourceList.sound_sources.push_back(it->second);
468 stdr_msgs::LoadMap::Request& req,
469 stdr_msgs::LoadMap::Response& res)
489 stdr_msgs::LoadExternalMap::Request& req,
490 stdr_msgs::LoadExternalMap::Response& res)
510 const stdr_msgs::SpawnRobotGoalConstPtr& goal)
512 stdr_msgs::SpawnRobotResult result;
517 result.message = std::string(
"Double frame_id:") + f_id;
526 stdr_msgs::RobotIndexedVectorMsg msg;
527 for (RobotMap::iterator it =
_robotMap.begin();
530 msg.robots.push_back( it->second );
546 const stdr_msgs::DeleteRobotGoalConstPtr& goal)
549 stdr_msgs::DeleteRobotResult result;
554 stdr_msgs::RobotIndexedVectorMsg msg;
555 for (RobotMap::iterator it =
_robotMap.begin();
558 msg.robots.push_back( it->second );
574 const stdr_msgs::RegisterRobotGoalConstPtr& goal)
577 boost::unique_lock<boost::mutex> lock(
_mut);
578 stdr_msgs::RegisterRobotResult result;
585 result.description =
_robotMap[goal->name].robot;
615 stdr_msgs::RobotMsg description,
616 stdr_msgs::SpawnRobotResult* result)
619 stdr_msgs::RobotIndexedMsg namedRobot;
621 if(description.kinematicModel.type ==
"")
622 description.kinematicModel.type =
"ideal";
624 namedRobot.robot = description;
626 namedRobot.name =
"robot" + boost::lexical_cast<std::string>(
_id++);
628 _robotMap.insert( std::make_pair(namedRobot.name, namedRobot) );
630 nodelet::NodeletLoad srv;
631 srv.request.name = namedRobot.name;
632 srv.request.type =
"stdr_robot/Robot";
634 boost::unique_lock<boost::mutex> lock(
_mut);
640 result->indexedDescription = namedRobot;
648 "Robot didn't respond within time or registered with incorrect name.";
661 stdr_msgs::DeleteRobotResult* result)
664 RobotMap::iterator it =
_robotMap.find(name);
668 nodelet::NodeletUnload srv;
669 srv.request.name = name;
673 if (srv.response.success) {
677 result->success = srv.response.success;
678 return srv.response.success;
681 result->success =
false;
685 ROS_WARN(
"Requested to delete robot, with name %s does not exist.",
688 result->success =
false;
695 std::set<std::string> f_ids;
696 for(
unsigned int i = 0 ; i < robot.laserSensors.size() ; i++)
698 if(f_ids.find(robot.laserSensors[i].frame_id) == f_ids.end())
700 f_ids.insert(robot.laserSensors[i].frame_id);
704 f_id = robot.laserSensors[i].frame_id;
708 for(
unsigned int i = 0 ; i < robot.sonarSensors.size() ; i++)
710 if(f_ids.find(robot.sonarSensors[i].frame_id) == f_ids.end())
712 f_ids.insert(robot.sonarSensors[i].frame_id);
716 f_id = robot.sonarSensors[i].frame_id;
720 for(
unsigned int i = 0 ; i < robot.rfidSensors.size() ; i++)
722 if(f_ids.find(robot.rfidSensors[i].frame_id) == f_ids.end())
724 f_ids.insert(robot.rfidSensors[i].frame_id);
728 f_id = robot.rfidSensors[i].frame_id;
732 for(
unsigned int i = 0 ; i < robot.co2Sensors.size() ; i++)
734 if(f_ids.find(robot.co2Sensors[i].frame_id) == f_ids.end())
736 f_ids.insert(robot.co2Sensors[i].frame_id);
740 f_id = robot.co2Sensors[i].frame_id;
744 for(
unsigned int i = 0 ; i < robot.soundSensors.size() ; i++)
746 if(f_ids.find(robot.soundSensors[i].frame_id) == f_ids.end())
748 f_ids.insert(robot.soundSensors[i].frame_id);
752 f_id = robot.soundSensors[i].frame_id;
756 for(
unsigned int i = 0 ; i < robot.thermalSensors.size() ; i++)
758 if(f_ids.find(robot.thermalSensors[i].frame_id) == f_ids.end())
760 f_ids.insert(robot.thermalSensors[i].frame_id);
764 f_id = robot.thermalSensors[i].frame_id;
776 visualization_msgs::Marker marker =
createMarker(msg, added);
781 marker.id = atoi(msg.id.c_str());
784 marker.color.r = 0.0f;
785 marker.color.g = 1.0f;
786 marker.color.b = 0.0f;
787 marker.color.a = 1.0;
795 visualization_msgs::Marker
Server::toMarker(
const stdr_msgs::ThermalSource& msg,
bool added)
797 visualization_msgs::Marker marker =
createMarker(msg, added);
801 marker.ns =
"thermal";
802 marker.id = atoi(msg.id.c_str());
805 marker.color.r = 1.0f;
806 marker.color.g = 0.0f;
807 marker.color.b = 0.0f;
808 marker.color.a = 1.0;
818 visualization_msgs::Marker marker =
createMarker(msg, added);
823 marker.id = atoi(msg.id.c_str());
826 marker.color.r = 0.0f;
827 marker.color.g = 0.0f;
828 marker.color.b = 1.0f;
829 marker.color.a = 1.0;
839 visualization_msgs::Marker marker =
createMarker(msg, added);
844 marker.id = atoi(msg.tag_id.c_str());
847 marker.color.r = 0.0f;
848 marker.color.g = 0.0f;
849 marker.color.b = 0.0f;
850 marker.color.a = 1.0;
857 visualization_msgs::MarkerArray ma;
861 ma.markers.push_back(
toMarker(it->second,
true));
866 ma.markers.push_back(
toMarker(it->second,
true));
871 ma.markers.push_back(
toMarker(it->second,
true));
875 ma.markers.push_back(
toMarker(it->second,
true));
884 template <
class SourceMsg>
887 visualization_msgs::Marker marker;
889 marker.header.frame_id =
"/map_static";
892 uint32_t shape = visualization_msgs::Marker::SPHERE;
897 marker.action = visualization_msgs::Marker::ADD;
900 marker.action = visualization_msgs::Marker::DELETE;
903 marker.pose.position.x = msg.pose.x;
904 marker.pose.position.y = msg.pose.y;
905 marker.pose.position.z = 0;
906 marker.pose.orientation.x = 0.0;
907 marker.pose.orientation.y = 0.0;
908 marker.pose.orientation.z = 0.0;
909 marker.pose.orientation.w = 1.0;
911 marker.scale.x = 0.5;
912 marker.scale.y = 0.5;
913 marker.scale.z = 0.5;
bool deleteThermalSourceCallback(stdr_msgs::DeleteThermalSource::Request &req, stdr_msgs::DeleteThermalSource::Response &res)
Service callback for deleting a thermal source from the environment.
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void registerRobotCallback(const stdr_msgs::RegisterRobotGoalConstPtr &goal)
Action callback for robot registering.
bool hasDublicateFrameIds(const stdr_msgs::RobotMsg &robot, std::string &f_id)
Implements the STDR map server functionalities.
MapServerPtr _mapServer
ROS publisher for the ensemble of robots.
ros::Publisher _CO2SourceVectorPublisher
The addThermalSource srv server.
bool addNewRobot(stdr_msgs::RobotMsg description, stdr_msgs::SpawnRobotResult *result)
Adds new robot to simulator.
ros::ServiceServer _addSoundSourceServiceServer
The deleteSoundSource srv server.
void publish(const boost::shared_ptr< M > &message) const
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.
SpawnRobotServer _spawnRobotServer
Action server for deleting robots.
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.
The main namespace for STDR Server.
bool call(MReq &req, MRes &res)
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.
RegisterRobotServer _registerRobotServer
Action server for spawning robots.
ros::ServiceClient _spawnRobotClient
Action client for robot unloading.
RfidTagMap _rfidTagMap
An std::map that contains the CO2 sources existent in the environment.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool deleteRobot(std::string name, stdr_msgs::DeleteRobotResult *result)
Deletes a robot from simulator.
ros::ServiceServer _deleteRfidTagServiceServer
The rfid tag list publisher.
CO2SourceMap _CO2SourceMap
An std::map that contains the thermal sources existent in the environment.
ros::ServiceServer _deleteSoundSourceServiceServer
The sound source list publisher.
std::map< std::string, stdr_msgs::CO2Source >::iterator CO2SourceMapIt
ros::ServiceServer _loadMapService
Service server for loading maps from GUI.
RobotMap _robotMap
Index that shows the next robot id.
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
ros::Publisher _thermalSourceVectorPublisher
The addSoundSource srv server.
std::map< std::string, stdr_msgs::ThermalSource >::iterator ThermalSourceMapIt
ros::ServiceServer _addThermalSourceServiceServer
The deleteThermalSource srv server.
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's sp...
SoundSourceMap _soundSourceMap
Boost mutex for conflict avoidance.
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.
ros::ServiceServer _loadExternalMapService
Service server for moving robots.
ThermalSourceMap _thermalSourceMap
An std::map that contains the sound sources existent in the environment.
std::map< std::string, stdr_msgs::RfidTag >::iterator RfidTagMapIt
ros::ServiceServer _addRfidTagServiceServer
The deleteRfidTag srv server.
ros::ServiceClient _unloadRobotClient
Service server for loading maps from files.
int _id
An std::map that contains the rfid tags existent in the environment.
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.
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.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Implements the STDR server functionalities.
ros::Publisher _soundSourceVectorPublisher
std::map< std::string, stdr_msgs::SoundSource >::iterator SoundSourceMapIt
bool deleteCO2SourceCallback(stdr_msgs::DeleteCO2Source::Request &req, stdr_msgs::DeleteCO2Source::Response &res)
Service callback for deleting a CO2 source from the environment.
ros::Publisher _sourceVectorPublisherRviz
The addRfidTag srv server.
boost::mutex _mut
Boost condition variable for conflicting avoidance.
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
boost::condition_variable _cond
A general Rviz publisher for all source types.
void activateActionServers(void)
Initializes the spawn,delete,register action servers.
ros::Publisher _robotsPublisher
Action client for robot spawning.
void notify_one() BOOST_NOEXCEPT
ROSCPP_DECL bool search(const std::string &ns, const std::string &key, std::string &result)
DeleteRobotServer _deleteRobotServer
An std::map that contains the robots based on theor frame_id.
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)
Server(int argc, char **argv)
Default constructor.