25 #include <boost/shared_ptr.hpp> 26 #include <boost/filesystem/path.hpp> 27 #include <boost/algorithm/string/split.hpp> 28 #include <boost/algorithm/string/classification.hpp> 33 #include <visualization_msgs/Marker.h> 34 #include <visualization_msgs/MarkerArray.h> 38 #include <asr_msgs/AsrObject.h> 41 #include <ISM/heuristic_trainer/Trainer.hpp> 42 #include <ISM/heuristic_trainer/DataCollector.hpp> 43 #include <ISM/heuristic_trainer/ManuallyDefPseudoHeuristic.hpp> 44 #include <ISM/utility/Util.hpp> 49 #define LINEWIDTH 0.008 60 typedef boost::filesystem::path
path;
69 std::string dbfilename;
70 bool useUserDefCluster;
71 bool usePredefinedRefs;
72 path preDefRefListFile;
74 bool dropOldModelTables;
77 getNodeParameters(dbfilename, useUserDefCluster, clusterListFile, dropOldModelTables,
78 usePredefinedRefs, preDefRefListFile);
80 ISM::DataCollector::setCollect(
true);
83 ISM::TableHelperPtr table_helper = ISM::TableHelperPtr(
new ISM::TableHelper(dbfilename));
84 if(!table_helper->recordDataExists())
86 ISM::printRed(
"The database \"" + dbfilename +
"\" doesn't contain any recordings!\n");
93 throw std::runtime_error(
"No db specified");
98 std::ifstream manualList(clusterListFile.string());
100 std::vector<std::pair<std::vector<ISM::ManuallyDefPseudoHeuristic::ClusterObject>,
102 while(std::getline(manualList, line))
104 std::vector<ISM::ManuallyDefPseudoHeuristic::ClusterObject> clusterObjects;
105 std::vector<std::string> objAndId;
106 boost::split(objAndId, line, boost::is_any_of(
";"));
107 uint16_t clusterId = boost::lexical_cast<uint16_t>(objAndId[1]);
108 std::vector<std::string> objSs;
109 boost::split(objSs, objAndId[0], boost::is_any_of(
","));
110 for(std::string& objS : objSs)
116 subId = boost::lexical_cast<
int>(objS);
118 catch(boost::bad_lexical_cast& e)
124 clusterObjects.push_back(ISM::ManuallyDefPseudoHeuristic::ClusterObject(subId));
127 clusterObjects.push_back(ISM::ManuallyDefPseudoHeuristic::ClusterObject(objS));
130 cluster.push_back(std::make_pair(clusterObjects, clusterId));
132 mTrainer->setClusterForManualDefHeuristic(cluster);
135 if(usePredefinedRefs)
138 std::ifstream preDefRefS (preDefRefListFile.string());
139 std::map<std::string, std::string> preDefRefList;
140 while(std::getline(preDefRefS, line))
142 std::vector<std::string> patternType;
143 boost::split(patternType, line, boost::is_any_of(
","));
144 preDefRefList[patternType[0]] = patternType[1];
146 mTrainer->setPredefinedRefs(preDefRefList);
163 void getNodeParameters(std::string& pDbfilename,
bool& useUserDefCluster, path& clusterListFile,
164 bool& dropOldModelTables,
bool& usePredefinedRefs, path& preDefRefListFile) {
196 if (!
mNh.
getParam(
"useUserDefCluster", useUserDefCluster)) {
197 useUserDefCluster =
false;
200 if(useUserDefCluster)
203 if (!
mNh.
getParam(
"manualHeuristicListFile", temp)) {
207 clusterListFile = temp;
209 if(!boost::filesystem::is_regular_file(clusterListFile))
211 std::stringstream ss;
212 ss << clusterListFile <<
" does not exist or is not a file";
214 throw std::runtime_error(ss.str());
222 preDefRefListFile = temp;
223 if(boost::filesystem::is_regular_file(preDefRefListFile))
225 usePredefinedRefs =
true;
232 if (!
mNh.
getParam(
"dropOldModelTables", dropOldModelTables)) {
233 dropOldModelTables =
false;
263 int main(
int argc,
char **argv) {
271 ISM::printGreen(
"Training is done!\n\n");
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
boost::filesystem::path path
boost::shared_ptr< ISM::Trainer > mTrainer
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
void getNodeParameters(std::string &pDbfilename, bool &useUserDefCluster, path &clusterListFile, bool &dropOldModelTables, bool &usePredefinedRefs, path &preDefRefListFile)
double mMaxAngleDeviation
#define ROS_ERROR_STREAM(args)