33 #include <hector_worldmodel_msgs/GetObjectModel.h> 38 #include <boost/date_time/posix_time/posix_time.hpp> 39 #include <boost/date_time/gregorian/formatters.hpp> 41 #include <boost/tokenizer.hpp> 53 virtual void initialize(
const std::string& name);
77 std::string service_name_;
79 plugin_nh.
param(
"service_name", service_name_, std::string(
"worldmodel/get_object_model"));
99 hector_worldmodel_msgs::GetObjectModel data;
105 std::string team_name;
107 std::string mission_name;
113 boost::gregorian::date now_date(now.date());
114 boost::posix_time::time_duration now_time(now.time_of_day().hours(), now.time_of_day().minutes(), now.time_of_day().seconds(), 0);
117 if (description_file.is_open()) {
118 description_file <<
"\"victims\"" << std::endl;
119 description_file <<
"\"1.0\"" << std::endl;
120 if (!team_name.empty()) description_file <<
"\"" << team_name <<
"\"" << std::endl;
121 if (!country.empty()) description_file <<
"\"" << country <<
"\"" << std::endl;
122 description_file <<
"\"" << now_date <<
"\"" << std::endl;
123 description_file <<
"\"" << now_time <<
"\"" << std::endl;
124 if (!mission_name.empty()) description_file <<
"\"" << mission_name <<
"\"" << std::endl;
125 description_file << std::endl;
126 description_file <<
"id,time,name,x,y,z" << std::endl;
130 for(hector_worldmodel_msgs::ObjectModel::_objects_type::const_iterator it = data.response.model.objects.begin(); it != data.response.model.objects.end(); ++it) {
131 const hector_worldmodel_msgs::Object&
object = *it;
132 if (!
draw_all_objects_ &&
object.state.state != hector_worldmodel_msgs::ObjectState::CONFIRMED)
continue;
135 Eigen::Vector2f coords;
136 coords.x() =
object.pose.pose.position.x;
137 coords.y() =
object.pose.pose.position.y;
138 interface->
drawObjectOfInterest(coords, boost::lexical_cast<std::string>(++counter), MapWriterInterface::Color(240,10,10));
140 if (description_file.is_open()) {
141 boost::posix_time::time_duration time_of_day(
object.
header.stamp.toBoost().time_of_day());
142 boost::posix_time::time_duration time(time_of_day.hours(), time_of_day.minutes(), time_of_day.seconds(), 0);
143 description_file << counter <<
"," << time <<
"," <<
object.info.object_id <<
"," <<
object.pose.pose.position.x <<
"," <<
object.pose.pose.position.y <<
"," <<
object.pose.pose.position.z << std::endl;
158 hector_worldmodel_msgs::GetObjectModel data;
164 std::string team_name;
166 std::string mission_name;
172 boost::gregorian::date now_date(now.date());
173 boost::posix_time::time_duration now_time(now.time_of_day().hours(), now.time_of_day().minutes(), now.time_of_day().seconds(), 0);
176 if (description_file.is_open()) {
177 description_file <<
"\"qr codes\"" << std::endl;
178 description_file <<
"\"1.0\"" << std::endl;
179 if (!team_name.empty()) description_file <<
"\"" << team_name <<
"\"" << std::endl;
180 if (!country.empty()) description_file <<
"\"" << country <<
"\"" << std::endl;
181 description_file <<
"\"" << now_date <<
"\"" << std::endl;
182 description_file <<
"\"" << now_time <<
"\"" << std::endl;
183 if (!mission_name.empty()) description_file <<
"\"" << mission_name <<
"\"" << std::endl;
184 description_file << std::endl;
185 description_file <<
"id,time,text,x,y,z" << std::endl;
238 for(hector_worldmodel_msgs::ObjectModel::_objects_type::const_iterator it = data.response.model.objects.begin(); it != data.response.model.objects.end(); ++it) {
239 const hector_worldmodel_msgs::Object&
object = *it;
241 if (!
draw_all_objects_ &&
object.state.state != hector_worldmodel_msgs::ObjectState::CONFIRMED)
continue;
242 if (
object.state.state == hector_worldmodel_msgs::ObjectState::DISCARDED)
continue;
247 if (isLargest(
object, data.response.model.objects)) {
248 Eigen::Vector2f coords;
249 coords.x() =
object.pose.pose.position.x;
250 coords.y() =
object.pose.pose.position.y;
251 interface->
drawObjectOfInterest(coords, boost::lexical_cast<std::string>(counter), MapWriterInterface::Color(10,10,240));
254 if (description_file.is_open()) {
255 boost::posix_time::time_duration time_of_day(
object.
header.stamp.toBoost().time_of_day());
256 boost::posix_time::time_duration time(time_of_day.hours(), time_of_day.minutes(), time_of_day.seconds(), 0);
257 description_file << counter <<
"," << time <<
"," <<
object.info.name <<
"," <<
object.pose.pose.position.x <<
"," <<
object.pose.pose.position.y <<
"," <<
object.pose.pose.position.z << std::endl;
261 description_file.close();
268 boost::tokenizer<boost::char_separator<char> > tokens(name, boost::char_separator<char>(
"_"));
269 boost::tokenizer<boost::char_separator<char> >::const_iterator it = tokens.begin();
271 if (it == tokens.end())
274 for (
unsigned int i = 0; i < 3; i++) {
275 if (++it == tokens.end())
279 return it->size() > 2 ? boost::lexical_cast<
float>(it->substr(0, it->size()-2)) : -1.0f;
281 catch (boost::bad_lexical_cast&) {
286 bool isLargest(
const hector_worldmodel_msgs::Object&
object,
const std::vector<hector_worldmodel_msgs::Object>& objects )
289 float size = getSizeFromName(
object.info.name);
295 for (hector_worldmodel_msgs::ObjectModel::_objects_type::const_iterator it = objects.begin(); it != objects.end(); ++it) {
296 const hector_worldmodel_msgs::Object& object2 = *it;
298 float dist_sqr = (
object.pose.pose.position.x-object2.pose.pose.position.x) * (
object.pose.pose.position.x-object2.pose.pose.position.x)
299 +(
object.pose.pose.position.y-object2.pose.pose.position.y) * (
object.pose.pose.position.y-object2.pose.pose.position.y);
302 if (dist_sqr < 0.75
f) {
303 float size2 = getSizeFromName(object2.info.name);
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
virtual void initialize(const std::string &name)
virtual std::string getBasePathAndFileName() const =0
#define ROS_INFO_NAMED(name,...)
void draw(MapWriterInterface *interface)
ROSCONSOLE_DECL void initialize()
bool getParamCached(const std::string &key, std::string &s) const
bool call(MReq &req, MRes &res)
virtual ~VictimMapWriter()
std_msgs::Header * header(M &m)
virtual ~QRCodeMapWriter()
float getSizeFromName(const std::string &name)
bool isLargest(const hector_worldmodel_msgs::Object &object, const std::vector< hector_worldmodel_msgs::Object > &objects)
ros::ServiceClient service_client_
void draw(MapWriterInterface *interface)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
virtual void drawObjectOfInterest(const Eigen::Vector2f &coords, const std::string &txt, const Color &color)=0
virtual ~MapWriterPlugin()
#define ROS_ERROR_NAMED(name,...)
boost::posix_time::ptime toBoost() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)