kinematics-dynamics
CartesianControlClient.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __CARTESIAN_CONTROL_CLIENT_HPP__
4 #define __CARTESIAN_CONTROL_CLIENT_HPP__
5 
6 #include <mutex>
7 
8 #include <yarp/os/Bottle.h>
9 #include <yarp/os/BufferedPort.h>
10 #include <yarp/os/PortReaderBuffer.h>
11 #include <yarp/os/RpcClient.h>
12 
13 #include <yarp/dev/Drivers.h>
14 
15 #include <vector>
16 
17 #include "ICartesianControl.h"
18 
19 namespace roboticslab
20 {
21 
33 class FkStreamResponder : public yarp::os::TypedReaderCallback<yarp::os::Bottle>
34 {
35 public:
37  void onRead(yarp::os::Bottle& b) override;
38  bool getLastStatData(std::vector<double> &x, int *state, double * timestamp, double timeout);
39 
40 private:
41  double localArrivalTime;
42  int state;
43  double timestamp;
44  std::vector<double> x;
45  mutable std::mutex mtx;
46 };
47 
52 class CartesianControlClient : public yarp::dev::DeviceDriver,
53  public ICartesianControl
54 {
55 public:
56  // -- ICartesianControl declarations. Implementation in ICartesianControlImpl.cpp--
57  bool stat(std::vector<double> &x, int * state = nullptr, double * timestamp = nullptr) override;
58  bool inv(const std::vector<double> &xd, std::vector<double> &q) override;
59  bool movj(const std::vector<double> &xd) override;
60  bool relj(const std::vector<double> &xd) override;
61  bool movl(const std::vector<double> &xd) override;
62  bool movv(const std::vector<double> &xdotd) override;
63  bool gcmp() override;
64  bool forc(const std::vector<double> &fd) override;
65  bool stopControl() override;
66  bool wait(double timeout) override;
67  bool tool(const std::vector<double> &x) override;
68  bool act(int command) override;
69  void pose(const std::vector<double> &x) override;
70  void twist(const std::vector<double> &xdot) override;
71  void wrench(const std::vector<double> &w) override;
72  bool setParameter(int vocab, double value) override;
73  bool getParameter(int vocab, double * value) override;
74  bool setParameters(const std::map<int, double> & params) override;
75  bool getParameters(std::map<int, double> & params) override;
76 
77  // -------- DeviceDriver declarations. Implementation in IDeviceImpl.cpp --------
78  bool open(yarp::os::Searchable& config) override;
79  bool close() override;
80 
81 private:
82  bool handleRpcRunnableCmd(int vocab);
83  bool handleRpcConsumerCmd(int vocab, const std::vector<double>& in);
84  bool handleRpcFunctionCmd(int vocab, const std::vector<double>& in, std::vector<double>& out);
85 
86  void handleStreamingConsumerCmd(int vocab, const std::vector<double>& in);
87  void handleStreamingBiConsumerCmd(int vocab, const std::vector<double>& in1, double in2);
88 
89  yarp::os::RpcClient rpcClient;
90  yarp::os::BufferedPort<yarp::os::Bottle> fkInPort, commandPort;
91 
92  FkStreamResponder fkStreamResponder;
93  double fkStreamTimeoutSecs;
94 };
95 
96 } // namespace roboticslab
97 
98 #endif // __CARTESIAN_CONTROL_CLIENT_HPP__
Contains roboticslab::ICartesianControl and related vocabs.
The CartesianControlClient class implements ICartesianControl client side.
Definition: CartesianControlClient.hpp:54
bool stopControl() override
Stop control.
Definition: ICartesianControlImpl.cpp:237
bool forc(const std::vector< double > &fd) override
Force control.
Definition: ICartesianControlImpl.cpp:230
bool tool(const std::vector< double > &x) override
Change tool.
Definition: ICartesianControlImpl.cpp:258
void pose(const std::vector< double > &x) override
Achieve pose.
Definition: ICartesianControlImpl.cpp:279
bool movl(const std::vector< double > &xd) override
Linear move to target position.
Definition: ICartesianControlImpl.cpp:209
bool inv(const std::vector< double > &xd, std::vector< double > &q) override
Inverse kinematics.
Definition: ICartesianControlImpl.cpp:188
bool stat(std::vector< double > &x, int *state=nullptr, double *timestamp=nullptr) override
Current state and position.
Definition: ICartesianControlImpl.cpp:141
void twist(const std::vector< double > &xdot) override
Instantaneous velocity steps.
Definition: ICartesianControlImpl.cpp:286
bool gcmp() override
Gravity compensation.
Definition: ICartesianControlImpl.cpp:223
bool setParameter(int vocab, double value) override
Set a configuration parameter.
Definition: ICartesianControlImpl.cpp:300
bool relj(const std::vector< double > &xd) override
Move in joint space, relative coordinates.
Definition: ICartesianControlImpl.cpp:202
void wrench(const std::vector< double > &w) override
Exert force.
Definition: ICartesianControlImpl.cpp:293
bool getParameter(int vocab, double *value) override
Retrieve a configuration parameter.
Definition: ICartesianControlImpl.cpp:315
bool movv(const std::vector< double > &xdotd) override
Linear move with given velocity.
Definition: ICartesianControlImpl.cpp:216
bool movj(const std::vector< double > &xd) override
Move in joint space, absolute coordinates.
Definition: ICartesianControlImpl.cpp:195
bool setParameters(const std::map< int, double > &params) override
Set multiple configuration parameters.
Definition: ICartesianControlImpl.cpp:336
bool getParameters(std::map< int, double > &params) override
Retrieve multiple configuration parameters.
Definition: ICartesianControlImpl.cpp:357
bool act(int command) override
Actuate tool.
Definition: ICartesianControlImpl.cpp:265
bool wait(double timeout) override
Wait until completion.
Definition: ICartesianControlImpl.cpp:244
Responds to streaming FK messages.
Definition: CartesianControlClient.hpp:34
Abstract base class for a cartesian controller.
Definition: ICartesianControl.h:146
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6