Go to the documentation of this file.00001
00002
00003 #include <pluginlib/class_list_macros.h>
00004 #include <uwsim/SimDev_Echo.h>
00005
00006 SimDev_Echo::SimDev_Echo(SimDev_Echo_Config * cfg) :
00007 SimulatedDevice(cfg)
00008 {
00009 this->info = cfg->info;
00010 }
00011
00012 SimulatedDeviceConfig::Ptr SimDev_Echo_Factory::processConfig(const xmlpp::Node* node, ConfigFile * config)
00013 {
00014 SimDev_Echo_Config * cfg = new SimDev_Echo_Config(getType());
00015 xmlpp::Node::NodeList list = node->get_children();
00016 for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
00017 {
00018 const xmlpp::Node* child = dynamic_cast<const xmlpp::Node*>(*iter);
00019 if (child->get_name() == "info")
00020 config->extractStringChar(child, cfg->info);
00021 }
00022 return SimulatedDeviceConfig::Ptr(cfg);
00023 }
00024
00025 bool SimDev_Echo_Factory::applyConfig(SimulatedIAUV * auv, Vehicle &vehicleChars, SceneBuilder *sceneBuilder,
00026 size_t iteration)
00027 {
00028 if (iteration > 0)
00029 return true;
00030 for (size_t i = 0; i < vehicleChars.simulated_devices.size(); ++i)
00031 if (vehicleChars.simulated_devices[i]->getType() == this->getType())
00032 {
00033 SimDev_Echo_Config * cfg = dynamic_cast<SimDev_Echo_Config *>(vehicleChars.simulated_devices[i].get());
00034 if (cfg && cfg->info.length() > 0)
00035 {
00036 auv->devices->all.push_back(SimDev_Echo::Ptr(new SimDev_Echo(cfg)));
00037 }
00038 else
00039 OSG_FATAL << "SimDev_Echo device '" << vehicleChars.simulated_devices[i]->name << "' inside robot '"
00040 << vehicleChars.name << "' has empty info, discarding..." << std::endl;
00041 }
00042 return true;
00043 }
00044
00045 std::vector<boost::shared_ptr<ROSInterface> > SimDev_Echo_Factory::getInterface(
00046 ROSInterfaceInfo & rosInterface, std::vector<boost::shared_ptr<SimulatedIAUV> > & iauvFile)
00047 {
00048 std::vector < boost::shared_ptr<ROSInterface> > ifaces;
00049 for (size_t i = 0; i < iauvFile.size(); ++i)
00050 for (size_t d = 0; d < iauvFile[i]->devices->all.size(); ++d)
00051 if (iauvFile[i]->devices->all[d]->getType() == this->getType()
00052 && iauvFile[i]->devices->all[d]->name == rosInterface.targetName)
00053 {
00054 ifaces.push_back(
00055 boost::shared_ptr < ROSInterface
00056 > (new SimDev_Echo_ROSPublisher(dynamic_cast<SimDev_Echo*>(iauvFile[i]->devices->all[d].get()),
00057 rosInterface.topic, rosInterface.rate)));
00058
00059
00060
00061
00062 }
00063 if (ifaces.size() == 0)
00064 ROS_WARN("Returning empty ROS interface for device %s...", rosInterface.targetName.c_str());
00065 return ifaces;
00066 }
00067
00068 void SimDev_Echo_ROSPublisher::createPublisher(ros::NodeHandle &nh)
00069 {
00070 ROS_INFO("SimDev_Echo_ROSPublisher on topic %s", topic.c_str());
00071 pub_ = nh.advertise < std_msgs::String > (topic, 1);
00072 }
00073
00074 void SimDev_Echo_ROSPublisher::publish()
00075 {
00076 std_msgs::String msg;
00077 if (dev != NULL)
00078 msg.data = dev->info;
00079 else
00080 msg.data = "dev==NULL";
00081 pub_.publish(msg);
00082 }
00083
00084 #if ROS_VERSION_MINIMUM(1, 9, 0)
00085
00086 PLUGINLIB_EXPORT_CLASS(SimDev_Echo_Factory, uwsim::SimulatedDeviceFactory)
00087 #else
00088 PLUGINLIB_REGISTER_CLASS(SimDev_Echo_Factory, SimDev_Echo_Factory, uwsim::SimulatedDeviceFactory)
00089 #endif
00090