-
Notifications
You must be signed in to change notification settings - Fork 12
/
BasicCartesianControl.hpp
218 lines (155 loc) · 7.98 KB
/
BasicCartesianControl.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#ifndef __BASIC_CARTESIAN_CONTROL_HPP__
#define __BASIC_CARTESIAN_CONTROL_HPP__
#include <yarp/os/all.h>
#include <yarp/dev/Drivers.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/ControlBoardInterfaces.h>
#include <iostream> // only windows
#include <vector>
#include "ICartesianSolver.h"
#include "ICartesianControl.h"
#include "LineTrajectory.hpp"
#define DEFAULT_SOLVER "KdlSolver"
#define DEFAULT_ROBOT "remote_controlboard"
#define DEFAULT_INIT_STATE VOCAB_CC_NOT_CONTROLLING
#define DEFAULT_MS 50
#define MAX_ANG_VEL 7.5
#define DEFAULT_GAIN 0.05
#define DEFAULT_QDOT_LIMIT 10
namespace roboticslab
{
/**
* @ingroup YarpPlugins
* \defgroup BasicCartesianControl
*
* @brief Contains roboticslab::BasicCartesianControl.
@section BasicCartesianControl_Running1 Example with a Fake robot
First we must run a YARP name server if it is not running in our current namespace:
\verbatim
[on terminal 1] yarp server
\endverbatim
And then launch the actual library:
\verbatim
[on terminal 2] yarpdev --device BasicCartesianControl --robot FakeControlboard --angleRepr axisAngle --link_0 "(A 1)"
\endverbatim
Along the output, observe a line like the following.
\verbatim
[info] DeviceDriverImpl.cpp:26 open(): Using angleRepr: axisAngle.
\endverbatim
This would mean we are using an axis/angle notation (par de rotación). Note that it is a variable parameter; in fact, we have forced it above.
We connect, can ask for help, etc. Here's an example interaction:
\verbatim
[on terminal 3] yarp rpc /CartesianControl/rpc_transform:s
[>>] help
Response: [stat] [inv] [movj] [movl] [movv] [gcmp] [forc] [stop]
[>>] stat
Response: [ccnc] 1.0 0.0 0.0 0.0 0.0 1.0 0.0
\endverbatim
Stat returns the controller status, and forward kinematics.
[ccnc] means Cartesian Control Not Controlling (also note that notation is in constant evolution, so put an issue if it's not updated!).
The first 3 parameters of the forward kinnematics are X,Y,Z of the end-effector. The other parameters correspond to orientation in the previously
set notation, which in this example is axis/angle, so this would read: on Z, 0 degrees.
Let's now move to a reachable position/orientation.
\verbatim
[>>] movj 1.0 0.0 0.0 0.0 0.0 1.0 0.0
Response: [ok]
\endverbatim
@section BasicCartesianControl_Running2 Example with teoSim
What moslty changes is the library command line invocation. We also change the server port name. The following is an example for the simulated robot's right arm.
\verbatim
[on terminal 2] yarpdev --device BasicCartesianControl --name /teoSim/rightArm/CartesianControl --from /usr/local/share/teo-configuration-files/contexts/kinematics/rightArmKinematics.ini --angleRepr axisAngle --robot remote_controlboard --local /BasicCartesianControl/teoSim/rightArm --remote /teoSim/rightArm
[on terminal 3] yarp rpc /teoSim/rightArm/CartesianControl/rpc_transform:s
\endverbatim
@section BasicCartesianControl_Running3 Example with real TEO
What moslty changes is the library command line invocation. We also change the server port name. The following is an example for the robot's right arm.
\verbatim
[on terminal 2] yarpdev --device BasicCartesianControl --name /teo/rightArm/CartesianControl --from /usr/local/share/teo-configuration-files/contexts/kinematics/rightArmKinematics.ini --angleRepr axisAngle --robot remote_controlboard --local /BasicCartesianControl/teo/rightArm --remote /teo/rightArm
[on terminal 3] yarp rpc /teo/rightArm/CartesianControl/rpc:s
\endverbatim
On the real robot, you can even activate Gravity Compensation (warning: dangerous if kinematic/dynamic model has not been reviewed!).
\verbatim
[>>] gcmp
\endverbatim
@section BasicCartesianControl_Running4 Very Important
When you launch the BasicCartesianControl device as in [terminal 2], it's actually wrapped: CartesianControlServer is the device that is
actually loaded, and BasicCartesianControl becomes its subdevice. The server is what allows us to interact via the YARP RPC port mechanism.
If you are creating a C++ program, you do not have to sned these raw port commands. Use CartesianControlClient instead, because the server and client
are YARP devices (further reading on why this is good: <a href="http://asrob.uc3m.es/index.php/Tutorial_yarp_devices#.C2.BFQu.C3.A9_m.C3.A1s_nos_permiten_los_YARP_device.3F">here (spanish)</a>).
*/
/**
* @ingroup BasicCartesianControl
* @brief The BasicCartesianControl class implements ICartesianControl.
*/
class BasicCartesianControl : public yarp::dev::DeviceDriver, public ICartesianControl, public yarp::os::RateThread
{
public:
BasicCartesianControl() : currentState(DEFAULT_INIT_STATE), RateThread(DEFAULT_MS) {}
// -- ICartesianControl declarations. Implementation in ICartesianControlImpl.cpp--
virtual bool stat(int &state, std::vector<double> &x);
virtual bool inv(const std::vector<double> &xd, std::vector<double> &q);
virtual bool movj(const std::vector<double> &xd);
virtual bool relj(const std::vector<double> &xd);
virtual bool movl(const std::vector<double> &xd);
virtual bool movv(const std::vector<double> &xdotd);
virtual bool gcmp();
virtual bool forc(const std::vector<double> &td);
virtual bool stopControl();
virtual bool tool(const std::vector<double> &x);
virtual void fwd(const std::vector<double> &rot, double step);
virtual void bkwd(const std::vector<double> &rot, double step);
virtual void rot(const std::vector<double> &rot);
virtual void pan(const std::vector<double> &transl);
virtual void vmos(const std::vector<double> &xdot);
virtual void eff(const std::vector<double> &xdotee);
virtual void pose(const std::vector<double> &x, double interval);
// -------- RateThread declarations. Implementation in RateThreadImpl.cpp --------
/** Loop function. This is the thread itself. */
virtual void run();
// -------- DeviceDriver declarations. Implementation in IDeviceImpl.cpp --------
/**
* Open the DeviceDriver.
* @param config is a list of parameters for the device.
* Which parameters are effective for your device can vary.
* See \ref dev_examples "device invocation examples".
* If there is no example for your device,
* you can run the "yarpdev" program with the verbose flag
* set to probe what parameters the device is checking.
* If that fails too,
* you'll need to read the source code (please nag one of the
* yarp developers to add documentation for your device).
* @return true/false upon success/failure
*/
virtual bool open(yarp::os::Searchable& config);
/**
* Close the DeviceDriver.
* @return true/false on success/failure.
*/
virtual bool close();
protected:
yarp::dev::PolyDriver solverDevice;
roboticslab::ICartesianSolver *iCartesianSolver;
yarp::dev::PolyDriver robotDevice;
yarp::dev::IEncoders *iEncoders;
yarp::dev::IPositionControl *iPositionControl;
yarp::dev::IVelocityControl *iVelocityControl;
yarp::dev::IControlLimits *iControlLimits;
yarp::dev::ITorqueControl *iTorqueControl;
yarp::dev::IControlMode *iControlMode;
int numRobotJoints, numSolverJoints;
/** State encoded as a VOCAB which can be stored as an int */
int currentState;
int getCurrentState();
void setCurrentState(int value);
yarp::os::Semaphore currentStateReady;
/** MOVL keep track of movement start time to know at what time of trajectory movement we are */
double movementStartTime;
/** MOVL store Cartesian trajectory */
LineTrajectory trajectory;
/** MOVV desired Cartesian velocity */
std::vector<double> xdotd;
/** FORC desired Cartesian force */
std::vector<double> td;
};
} // namespace roboticslab
#endif // __BASIC_CARTESIAN_CONTROL_HPP__