Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <labust/vehicles/VehicleApp.hpp>
00038 #include <labust/vehicles/VehicleDriver.hpp>
00039 #include <labust/vehicles/VehicleFactoryName.hpp>
00040 #include <labust/xml/GyrosReader.hpp>
00041 #include <labust/xml/GyrosWriter.hpp>
00042
00043 using namespace labust::vehicles;
00044
00045 VehicleApp::VehicleApp():
00046 nhandle(),
00047 phandle("~")
00048 {
00049
00050 std::string pluginName, pluginConfig, pluginId;
00051 phandle.param("PluginName",pluginName, pluginName);
00052 phandle.param("PluginConfig",pluginConfig,pluginConfig);
00053 if (pluginName.empty() || pluginConfig.empty())
00054 {
00055 throw std::runtime_error("Plugin name and configuration missing.");
00056 }
00057 phandle.param("PluginId",pluginId,pluginId);
00058 this->loadPlugin(pluginName, pluginConfig, pluginId);
00059
00060
00061 std::string stateName("state"), dataName("data");
00062 phandle.param("StateOut",stateName,stateName);
00063 phandle.param("DataOut",dataName,dataName);
00064 this->publish(stateName, dataName);
00065
00066 std::string tauName("tau"), cmdName("cmd");
00067 phandle.param("TauIn",tauName,tauName);
00068 phandle.param("CommandIn",cmdName,cmdName);
00069 this->subscribe(tauName, cmdName);
00070
00071 std::cerr<<"VehicleApp successfully configured."<<std::endl;
00072 }
00073
00074 void VehicleApp::loadPlugin(const std::string& pluginName, const std::string& pluginConfig, const std::string& pluginId)
00075 {
00076
00077 uuv.reset();
00078
00079 plugin.reset(new labust::vehicles::VehiclePlugin(pluginName,FactoryCreatorName::value));
00080
00081 labust::xml::ReaderPtr reader(new labust::xml::Reader(pluginConfig,true));
00082 reader->useNode(reader->value<_xmlNode*>("//configurations"));
00083
00084 uuv.reset((*plugin)(reader));
00085 }
00086
00087 void VehicleApp::subscribe(const std::string& tauName, const std::string& cmdName)
00088 {
00089 tau = nhandle.subscribe<std_msgs::String>(tauName,msgBuf,boost::bind(&VehicleApp::onTau,this,_1));
00090 cmd = nhandle.subscribe<std_msgs::String>(tauName,msgBuf,boost::bind(&VehicleApp::onCmd,this,_1));
00091 }
00092
00093 void VehicleApp::publish(const std::string& stateName, const std::string& dataName)
00094 {
00095 state = nhandle.advertise<std_msgs::String>(stateName,msgBuf);
00096 data = nhandle.advertise<std_msgs::String>(dataName,msgBuf);
00097 }
00098
00099 void VehicleApp::onTau(const std_msgs::String::ConstPtr& tau)
00100 {
00101 std::cerr<<"Tau received."<<std::endl;
00102 labust::xml::GyrosReader reader(tau->data);
00103 std::map<int,double> tauM;
00104 reader.dictionary(tauM);
00105
00106 ROS_INFO("Tau decoded:%f",tauM[labust::vehicles::tau::N]);
00107
00108 labust::vehicles::tauMap tauC;
00109 for (size_t i=labust::vehicles::tau::X;
00110 i<=labust::vehicles::tau::N; ++i) tauC[i] = tauM[i];
00111
00112 ROS_INFO("Tau setting:%f",tauC[labust::vehicles::tau::N]);
00113
00114 uuv->setTAU(tauC);
00115
00116 std::cerr<<"Tau set."<<std::endl;
00117
00118 labust::vehicles::stateMapPtr state(new labust::vehicles::stateMap());
00119 uuv->getState(*state);
00120 std::cerr<<"State:"<<(*state)[labust::vehicles::state::yaw]<<std::endl;
00121
00122 labust::xml::GyrosWriter writer(state->begin(),state->end());
00123 writer.SetTimeStamp(true);
00124 std_msgs::StringPtr str(new std_msgs::String());
00125 str->data = writer.GyrosXML();
00126 std::cerr<<"State publishing."<<std::endl;
00127 this->state.publish(str);
00128
00129 std::cerr<<"State published."<<std::endl;
00130 }
00131
00132 void VehicleApp::onCmd(const std_msgs::String::ConstPtr& cmd)
00133 {
00134 uuv->setCommand(cmd->data);
00135 }
00136
00137
00138