iCub-main
IMachineLearnerModule.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2010 RobotCub Consortium, European Commission FP6 Project IST-004370
3  * author: Arjan Gijsberts
4  * email: arjan.gijsberts@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef LM_IMACHINELEARNERMODULE__
20 #define LM_IMACHINELEARNERMODULE__
21 
22 #include <yarp/os/RFModule.h>
23 #include <yarp/os/ResourceFinder.h>
24 #include <yarp/os/Bottle.h>
25 #include <yarp/os/BufferedPort.h>
26 #include <yarp/os/Time.h>
27 
29 
30 
31 namespace iCub {
32 namespace learningmachine {
33 
59 class IMachineLearnerModule : public yarp::os::RFModule {
60 protected:
64  yarp::os::Port cmd_in;
65 
69  std::string portPrefix;
70 
75 
79  yarp::os::ResourceFinder* rf;
80 
85 
90 
98  void registerPort(yarp::os::Contactable& port, std::string name);
99 
103  virtual void registerAllPorts() = 0;
104 
108  virtual void unregisterAllPorts() = 0;
109 
113  virtual void printOptions(std::string error = "") = 0;
114 
121  virtual void loadCommandFile(std::string fname, yarp::os::Bottle* out = (yarp::os::Bottle*) 0);
122 
129  virtual yarp::os::ResourceFinder& getResourceFinder() {
130  if(this->rf == (yarp::os::ResourceFinder*) 0) {
131  throw std::runtime_error("Attempt to retrieve inexistent resource finder.");
132  }
133  return *(this->rf);
134  }
135 
145  std::string findFile(std::string fname);
146 
153  virtual void setResourceFinder(yarp::os::ResourceFinder* rf) {
154  this->rf = rf;
155  }
156 
157 public:
163  IMachineLearnerModule(std::string pp) : portPrefix(pp), rf((yarp::os::ResourceFinder*) 0) { }
164 
169 
175  virtual bool close();
176 
180  virtual bool updateModule() {
181  yarp::os::Time::delay(1.);
182  return true;
183  }
184 
185 };
186 
187 } // learningmachine
188 } // iCub
189 
190 #endif
191 
The DispatcherManager provides a YARP-based configuration interface for the EventDispatcher.
An abstract base module for the machine learning YARP interface.
virtual bool updateModule()
Default empty update loop with 1 second delay.
DispatcherManager dmanager
An instance of the DispatchManager to configure event listeners.
virtual void registerAllPorts()=0
Registers all ports used by this module.
IMachineLearnerModule & operator=(const IMachineLearnerModule &other)
Assignment operator (private and unimplemented on purpose).
std::string portPrefix
A prefix path for the ports that will be registered.
virtual void setResourceFinder(yarp::os::ResourceFinder *rf)
Mutator for the locally stored ResourceFinder.
virtual void unregisterAllPorts()=0
Unregisters all ports used by this module.
IMachineLearnerModule(const IMachineLearnerModule &other)
Copy Constructor (private and unimplemented on purpose).
std::string findFile(std::string fname)
Finds the full path to a specified filename using the ResourceFinder.
void registerPort(yarp::os::Contactable &port, std::string name)
Register a port with a given name.
virtual yarp::os::ResourceFinder & getResourceFinder()
Returns a reference to the cached ResourceFinder.
yarp::os::ResourceFinder * rf
A pointer to the ResourceFinder.
yarp::os::Port cmd_in
An input port for commands.
virtual void printOptions(std::string error="")=0
Prints the accepted command line options with an optional error message.
virtual void loadCommandFile(std::string fname, yarp::os::Bottle *out=(yarp::os::Bottle *) 0)
Reads bottles from a file and sends these one by one to the respond method.
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Copyright (C) 2008 RobotCub Consortium.
out
Definition: sine.m:8