42 #include "ml_classifiers/CreateClassifier.h" 43 #include "ml_classifiers/AddClassData.h" 44 #include "ml_classifiers/TrainClassifier.h" 45 #include "ml_classifiers/ClearClassifier.h" 46 #include "ml_classifiers/SaveClassifier.h" 47 #include "ml_classifiers/LoadClassifier.h" 48 #include "ml_classifiers/ClassifyData.h" 63 ROS_ERROR(
"Classifer plugin failed to load! Error: %s", ex.what());
70 CreateClassifier::Request & req,
71 CreateClassifier::Response & res)
73 string id = req.identifier;
82 cout <<
"WARNING: ID already exists, overwriting: " << req.identifier << endl;
93 AddClassData::Request & req,
94 AddClassData::Response & res)
96 string id = req.identifier;
103 for (
size_t i = 0; i < req.data.size(); i++) {
104 classifier_list[id]->addTrainingPoint(req.data[i].target_class, req.data[i].point);
112 TrainClassifier::Request & req,
113 TrainClassifier::Response & res)
115 string id = req.identifier;
122 cout <<
"Training " <<
id << endl;
130 ClearClassifier::Request & req,
131 ClearClassifier::Response & res)
133 string id = req.identifier;
147 SaveClassifier::Request & req,
148 SaveClassifier::Response & res)
150 string id = req.identifier;
164 LoadClassifier::Request & req,
165 LoadClassifier::Response & res)
167 string id = req.identifier;
175 if (!c->load(req.filename)) {
181 cout <<
"WARNING: ID already exists, overwriting: " << req.identifier << endl;
192 ClassifyData::Request & req,
193 ClassifyData::Response & res)
195 string id = req.identifier;
197 for (
size_t i = 0; i < req.data.size(); i++) {
198 string class_num =
classifier_list[id]->classifyPoint(req.data[i].point);
199 res.classifications.push_back(class_num);
205 int main(
int argc,
char ** argv)
207 ros::init(argc, argv,
"classifier_server");
225 ROS_INFO(
"Classifier services now ready");
bool createHelper(string class_type, boost::shared_ptr< Classifier > &c)
bool createCallback(CreateClassifier::Request &req, CreateClassifier::Response &res)
boost::shared_ptr< T > createInstance(const std::string &lookup_name)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::map< string, boost::shared_ptr< Classifier > > classifier_list
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool clearCallback(ClearClassifier::Request &req, ClearClassifier::Response &res)
bool saveCallback(SaveClassifier::Request &req, SaveClassifier::Response &res)
bool loadCallback(LoadClassifier::Request &req, LoadClassifier::Response &res)
bool trainCallback(TrainClassifier::Request &req, TrainClassifier::Response &res)
pluginlib::ClassLoader< Classifier > c_loader("ml_classifiers", "ml_classifiers::Classifier")
bool classifyCallback(ClassifyData::Request &req, ClassifyData::Response &res)
int main(int argc, char **argv)
bool addCallback(AddClassData::Request &req, AddClassData::Response &res)