ocra-recipes
Doxygen documentation for the ocra-recipes repository
ControllerClient.h
Go to the documentation of this file.
1 #ifndef CONTROLLER_CLIENT_H
2 #define CONTROLLER_CLIENT_H
3 
6 #include <ocra/control/Model.h>
9 #include <yarp/os/Network.h>
10 #include <yarp/os/Port.h>
11 #include <yarp/os/Log.h>
12 #include <yarp/os/LogStream.h>
13 #include <yarp/os/RateThread.h>
14 #include <yarp/os/ResourceFinder.h>
15 
16 #include <ocra/util/Macros.h>
17 #include <ocra/util/ErrorsHelper.h>
18 
19 
20 
21 namespace ocra_recipes
22 {
23 
24 class ControllerClient : public yarp::os::RateThread
25 {
27 
28 public:
30  ControllerClient (ocra::Model::Ptr derivedModelPtr, const int loopPeriod = DEFAULT_LOOP_PERIOD);
31  virtual ~ControllerClient ();
32 
33  // RateThread virtual functions
34  virtual bool threadInit();
35  virtual void threadRelease();
36  virtual void run();
37 
38  virtual void printHelp(){std::cout << "Hey I am the base ControllerClient class!" << std::endl;}
39 
40  int getExpectedPeriod(){return expectedPeriod;}
41 
47  virtual bool configure(yarp::os::ResourceFinder &rf){return true;};
48 
49 public:
50  void addTasks(const std::string& pathToXmlFile, bool overwrite);
51  void addTask(ocra::TaskBuilderOptions& tmOpts, bool overwrite);
53  std::vector<std::string> getTaskTypes();
54  std::vector<std::string> getTaskNames();
55 
56  bool removeTask(const std::string& taskName);
57  bool removeTasks(const std::vector<std::string>& taskNameVector);
58 
59  bool hasBeenReleased(){return clientThreadHasBeenReleased;}
60  bool changeFixedLink(std::string newFixedLink, int isInLeftSupport, int isInRightSupport);
61 
62 
63 protected:
64  virtual bool initialize(){return true;}
65  virtual void release(){/* Do nothing. */}
66  virtual void loop() = 0;
67 
68  ClientCommunications::Ptr clientComs;
69  ocra::Model::Ptr model;
70 
71 private:
72  bool clientThreadHasBeenReleased;
73  bool isReady;
74 
75  yarp::os::Port statesPort;
76  StateListener stateCallback;
77 
78  static int CONTROLLER_CLIENT_COUNT;
79  int clientNumber;
80 
81  yarp::os::Network yarp;
82  yarp::os::Log yLog;
83 
84  int expectedPeriod;
85  static const int DEFAULT_LOOP_PERIOD = 10; // ms
86 };
87 
88 
89 } // namespace ocra_recipes
90 #endif // CONTROLLER_CLIENT_H
void addTasks(const std::string &pathToXmlFile, bool overwrite)
ClientCommunications::Ptr clientComs
std::vector< std::string > getTaskNames()
Declaration file of the Model class.
#define DEFINE_CLASS_POINTER_TYPEDEFS(Class)
Definition: Macros.h:8
A callback for a port listing to robot states.
Definition: RobotState.h:57
bool checkIfTaskExists(ocra::TaskBuilderOptions &tmOpts)
bool removeTasks(const std::vector< std::string > &taskNameVector)
virtual bool configure(yarp::os::ResourceFinder &rf)
std::vector< std::string > getTaskTypes()
bool changeFixedLink(std::string newFixedLink, int isInLeftSupport, int isInRightSupport)
void addTask(ocra::TaskBuilderOptions &tmOpts, bool overwrite)
bool removeTask(const std::string &taskName)