-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkinematics.cpp
More file actions
55 lines (39 loc) · 1.62 KB
/
kinematics.cpp
File metadata and controls
55 lines (39 loc) · 1.62 KB
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
//kinematics.cpp - a library for performing forward and inverse kinematics
#include "kinematics.h"
/*The kinematics class constructor
* paramaters is an array of the DH parameters for each joint as an array
*/
Kinematcis::Kinematics(int dof_in, double ** paramaters) {
dof = dof_in;
params = parameters;
for (int i = 0; i < dof; ++i) {
DH_matrices.push_back(Matrix(4, 4));
}
}
/* Performs forward kinematics and stores the tool tip location into position.
* position must be an array of length 3. angles must be of length dof
*/
void Kinematics::forward(double * angles, double * position) {
for (int i = 0; i < dof; ++i ) {
DH_matrices[i][0][0] = cos(angles[i]);
DH_matrices[i][0][1] = -sin(angles[i]) * cos(params[i][ALPHA]);
DH_matrices[i][0][2] = sin(angles[i]) * sin(params[i][ALPHA]);
DH_matrices[i][0][3] = params[i][A] * cos(angles[i]);
DH_matrices[i][1][0] = sin(angles[i]);
DH_matrices[i][1][1] = cos(anlges[i]) * cos(params[i][ALPHA]);
DH_matrices[i][1][2] = -cos(angles[i]) * sin(params[i][ALPHA]);
DH_matrices[i][1][3] = params[i][A] * sin(angles[i]);
DH_matrices[i][2][0] = 0;
DH_matrices[i][2][1] = sin(params[i][ALPHA]);
DH_matrices[i][2][2] = cos(params[i][ALPHA]);
DH_matrices[i][2][3] = params[i][D];
DH_matrices[i][3][0] = 0;
DH_matrices[i][3][1] = 0;
DH_matrices[i][3][2] = 0;
DH_matrices[i][3][3] = 1;
}
Matrix res = DH_matrices[0] * DH_matrices[1];
res *= DH_matrices[2];
res *= DH_matrices[3];
position = {res[0][3], res[1][3], res [2][3]};
}