-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontrol.cpp
executable file
·134 lines (94 loc) · 3.56 KB
/
control.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <ecn_manip/robot_init.h>
using namespace std;
using namespace ecn;
int main(int argc, char ** argv)
{
// initialize robot class and get DOF's
const auto robot{initRobot(argc, argv, 100)};
const unsigned n{robot->getDofs()};
// robot properties - max velocity and acceleration
const auto vMax{robot->vMax()};
const auto aMax{robot->aMax()};
// main variables
vpColVector q(n); // joint position
vpPoseVector p; // operational pose
vpColVector qCommand(n); // joint position setpoint
vpColVector vCommand(n); // joint velocity setpoint
vpMatrix J;
vpHomogeneousMatrix M; // current pose
vpHomogeneousMatrix M0, Md, Mi; // previous, final and current desired poses
vpPoseVector pd; // desired pose
vpColVector v; // desired operational velocity
// TODO declare other variables if needed
vpColVector q0(n), qf(n); // joint position setpoint for initial and final poses
double t0, tf;
// main control loop
while(robot->ok())
{
// current time [s]
const auto t{robot->time()};
// update desired pose if has changed
if(robot->newRef())
{
Md = robot->Md();
M0 = robot->M0();
pd.buildFrom(Md);
// starting time of this motion [s]
t0 = t;
}
// get current joint positions
q = robot->jointPosition();
cout << "Current joint position : " << q.t() << endl;
// Direct Geometry for end-effector
M = robot->fMe(q); // matrix form
p.buildFrom(M); // translation + angle-axis form
if(robot->mode() == ControlMode::POSITION_MANUAL)
{
// just check the Direct Geometric Model
// TODO: fill the fMw function
robot->checkPose(M);
}
else if(robot->mode() == ControlMode::VELOCITY_MANUAL)
{
// follow a given operational velocity
v = robot->guiVelocityScrew();
// TODO: fill the fJw function
// TODO: compute vCommand
robot->setJointVelocity(vCommand);
}
else if(robot->mode() == ControlMode::DIRECT_P2P)
{
// find the Inverse Geometry to reach Md
// TODO: fill the inverseGeometry function
qf = robot->inverseGeometry(Md, q);
robot->setJointPosition(qf);
}
else if(robot->mode() == ControlMode::POLYNOM_P2P)
{
// reach Md with polynomial joint trajectory
// use q0 (initial position), qf (final), aMax and vMax
// if reference has changed, compute new tf
if(robot->newRef())
{
q0 = robot->inverseGeometry(M0, q);
qf = robot->inverseGeometry(Md, q);
}
// TODO: compute qCommand from q0, qf, t, t0 and tf
robot->setJointPosition(qCommand);
}
else if(robot->mode() == ControlMode::STRAIGHT_LINE_P2P)
{
// go from M0 to Md in 1 sec
tf = 1;
// TODO: compute qCommand from M0, Md, t, t0 and tf
// use robot->intermediaryPose to build poses between M0 and Md
robot->setJointPosition(qCommand);
}
else if(robot->mode() == ControlMode::VELOCITY_P2P)
{
// go to Md using operational velocity
// TODO: compute joint velocity command
robot->setJointVelocity(vCommand);
}
}
}