-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
111 lines (84 loc) · 2.38 KB
/
main.cpp
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
// Assignment on Inverse Kinematics.
//
// Author: Ugo Pattacini - <[email protected]>
#include <cstdlib>
#include <string>
#include <cmath>
#include <yarp/os/Network.h>
#include <yarp/os/LogStream.h>
#include <yarp/os/ResourceFinder.h>
#include <yarp/os/RFModule.h>
#include <yarp/os/BufferedPort.h>
#include <yarp/sig/Vector.h>
#include <yarp/sig/Matrix.h>
#include <yarp/math/Math.h>
#include <yarp/math/SVD.h>
using namespace std;
using namespace yarp::os;
using namespace yarp::sig;
using namespace yarp::math;
class Controller : public RFModule
{
double link_length;
BufferedPort<Vector> portMotors;
BufferedPort<Vector> portEncoders;
BufferedPort<Vector> portTarget;
Vector encoders;
Vector target;
public:
bool configure(ResourceFinder &rf)override
{
link_length=rf.check("link-length",Value(60.0)).asFloat64();
portMotors.open("/assignment_inverse-kinematics/motors:o");
portEncoders.open("/assignment_inverse-kinematics/encoders:i");
portTarget.open("/assignment_inverse-kinematics/target:i");
// init the encoder values of the 3 joints
encoders=zeros(3);
// init the target
target=zeros(3);
return true;
}
bool close()override
{
portMotors.close();
portEncoders.close();
portTarget.close();
return true;
}
double getPeriod()override
{
return 0.01;
}
bool updateModule()override
{
// update the target from the net
if (Vector *tar=portTarget.read(false))
target=*tar;
// update the encoder readouts from the net
if (Vector *enc=portEncoders.read(false))
encoders=*enc;
// retrieve the current target position
Vector ee_d=target.subVector(0,1);
// retrieve the current target orientation
double phi_d=target[2];
Vector &vel=portMotors.prepare();
vel=zeros(3);
// FILL IN THE CODE
// deliver the computed velocities to the actuators
portMotors.writeStrict();
return true;
}
};
int main(int argc, char *argv[])
{
Network yarp;
if (!yarp.checkNetwork())
{
yError()<<"YARP doesn't seem to be available";
return EXIT_FAILURE;
}
ResourceFinder rf;
rf.configure(argc,argv);
Controller controller;
return controller.runModule(rf);
}