ocra-recipes
Doxygen documentation for the ocra-recipes repository
TaskConnection.h
Go to the documentation of this file.
1 #ifndef TASK_CONNECTION_H
2 #define TASK_CONNECTION_H
3 
4 #include <iostream>
5 #include <string>
7 #include <ocra/control/Task.h>
8 
9 #include <yarp/os/RpcClient.h>
10 #include <yarp/os/Network.h>
11 #include <yarp/os/PortReader.h>
12 #include <yarp/os/Log.h>
13 #include <yarp/os/LogStream.h>
14 
16 
17 #include <Eigen/Dense>
18 #include <Eigen/Lgsm>
19 #include <ocra/util/Macros.h>
22 
23 
24 namespace ocra_recipes {
25 
28 
29 public:
30  TaskConnection ();
31  TaskConnection (const std::string& destinationTaskName);
32  virtual ~TaskConnection ();
33 
34  void reconnect();
35  void disconnect();
36 
37 
38 
39 private:
40  yarp::os::Network yarp;
41  yarp::os::Log yLog;
42  yarp::os::RpcClient taskRpcClient;
43  std::string taskName;
44  std::string taskRpcServerName;
45  std::string taskRpcClientName;
47  std::string taskOutputPortName;
48  std::string taskInputPortName;
49  std::string inputPortName;
50  std::string outputPortName;
51 
52  std::string taskDesiredStateOutputPortName;
53  std::string desiredStateInputPortName;
54 
55  yarp::os::Port desiredStateInputPort;
56  yarp::os::Port inputPort;
57  yarp::os::Port outputPort;
58 
59  ocra::TaskState currentState;
60  ocra::TaskState currentDesiredState;
61  bool firstUpdateOfTaskStateHasOccured;
62  bool firstUpdateOfTaskDesiredStateHasOccured;
63  bool controlPortsAreOpen;
64 
65  static int TASK_CONNECTION_COUNT;
66  int taskConnectionNumber;
67 
68 private:
69  void parseInput(yarp::os::Bottle& input);
70  void parseDesiredStateInput(yarp::os::Bottle& input);
71 
72 
73 public:
74 
80  bool activate();
81 
86  bool deactivate();
87 
92  std::string getPortName();
93 
98  bool isActivated();
99 
105  Eigen::VectorXd getTaskError();
106 
112  double getTaskErrorNorm();
113 
117  void setStiffness(double K);
118 
122  void setStiffness(const Eigen::VectorXd& K);
123 
124 
128  void setStiffness(const Eigen::MatrixXd& K);
129 
134  double getStiffness();
135 
140  Eigen::MatrixXd getStiffnessMatrix();
141 
145  void setDamping(double B);
146 
150  void setDamping(const Eigen::VectorXd& B);
151 
152 
156  void setDamping(const Eigen::MatrixXd& B);
157 
162  double getDamping();
163 
168  Eigen::MatrixXd getDampingMatrix();
169 
170 
174  void setWeight(double weight);
175 
179  void setWeight(Eigen::VectorXd& weights);
180 
185  Eigen::VectorXd getWeight();
186 
192  bool openControlPorts(bool connect=true);
193 
198  std::string getTaskName(){return taskName;}
199 
200 
206  std::string getTaskTypeAsString();
207 
208  int getTaskDimension();
209 
212  void setDesiredTaskState(const ocra::TaskState& newDesiredTaskState);
213  void setDesiredTaskStateDirect(const ocra::TaskState& newDesiredTaskState);
214 
215  bool closeControlPorts();
216 
217  std::string getTaskOutputPortName();
218  std::string getTaskInputPortName();
219 
220  Eigen::Displacementd getTaskFrameDisplacement();
221  Eigen::Twistd getTaskFrameVelocity();
222  Eigen::Twistd getTaskFrameAcceleration();
223  Eigen::Vector3d getTaskFramePosition();
224  Eigen::Rotation3d getTaskFrameOrientation();
225  Eigen::Vector3d getTaskFrameLinearVelocity();
226  Eigen::Vector3d getTaskFrameAngularVelocity();
227  Eigen::Vector3d getTaskFrameLinearAcceleration();
228  Eigen::Vector3d getTaskFrameAngularAcceleration();
229 
230  void queryTask(ocra::TASK_MESSAGE tag, yarp::os::Bottle& bottle);
231 
232  /************** controlInputCallback *************/
233  class InputCallback : public yarp::os::PortReader {
234  private:
235  TaskConnection& tcRef;
236 
237  public:
238  InputCallback(TaskConnection& _tcRef);
239 
240  virtual bool read(yarp::os::ConnectionReader& connection);
241  };
242  /************** controlInputCallback *************/
243  /************** desStateInputCallback *************/
244  class DesiredStateInputCallback : public yarp::os::PortReader {
245  private:
246  TaskConnection& tcRef;
247 
248  public:
250 
251  virtual bool read(yarp::os::ConnectionReader& connection);
252  };
253  /************** desStateInputCallback *************/
254 
255 private:
256  std::shared_ptr<InputCallback> inpCallback;
257  std::shared_ptr<DesiredStateInputCallback> desiredStateInputCallback;
258 
259 
260 
261 };
262 } /* ocra_recipes */
263 
264 #endif // TASK_CONNECTION_H
bool openControlPorts(bool connect=true)
Eigen::Twistd getTaskFrameVelocity()
ocra::Task::META_TASK_TYPE getTaskType()
Eigen::Twistd getTaskFrameAcceleration()
Eigen::Rotation3d getTaskFrameOrientation()
ocra::TaskState getDesiredTaskState()
#define DEFINE_CLASS_POINTER_TYPEDEFS(Class)
Definition: Macros.h:8
Eigen::Vector3d getTaskFrameAngularVelocity()
void setDesiredTaskState(const ocra::TaskState &newDesiredTaskState)
META_TASK_TYPE
Definition: Task.h:44
virtual bool read(yarp::os::ConnectionReader &connection)
Eigen::Vector3d getTaskFrameAngularAcceleration()
Eigen::MatrixXd getStiffnessMatrix()
void setDesiredTaskStateDirect(const ocra::TaskState &newDesiredTaskState)
Eigen::Vector3d getTaskFramePosition()
Eigen::Vector3d getTaskFrameLinearAcceleration()
void setWeight(double weight)
Eigen::Vector3d getTaskFrameLinearVelocity()
Eigen::MatrixXd getDampingMatrix()
void queryTask(ocra::TASK_MESSAGE tag, yarp::os::Bottle &bottle)
Eigen::Displacementd getTaskFrameDisplacement()