-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharm_modeling.c
More file actions
32 lines (26 loc) · 1.22 KB
/
arm_modeling.c
File metadata and controls
32 lines (26 loc) · 1.22 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
#include <stdio.h>
#include <math.h>
#include "user_math.h"
#include "arm_modeling.h"
// [a, alpha, d]
Arm_State_t g_arm_state = { .joints[0].dh_params = {0, PI/2, 0.1, 0.0f},
.joints[1].dh_params = {0.3, 0, 0, PI/2, 0.0f},
.joints[2].dh_params = {0.3, 0, 0, 0},
.joints[3].dh_params = {0, PI/2, 0.1, 0.0f},
.joints[4].dh_params = {0, -1 * PI/2, 0.1, 0.0f},
.joints[5].dh_params = {0, 0, 0.1, 0.0f}
}; // could be #defined somewhere these are all constants
//Denavit-Hartenberg matrix calculations
Mat* joint_transform(joint_t joint) {
return dh_transform(joint.dh_params);
}
void forward_kinematics() {
dh_update_arm();
Mat* transform = mat_identity(4);
for (int i = 0; i < 6; i++) {
transform = mat_mult(transform, joint_transform(g_arm_state.joints[i]));
g_arm_state.joints[i].x_pos = MAT_IDX(transform, 0,3); // index [0, 3]
g_arm_state.joints[i].y_pos = MAT_IDX(transform, 1,3); // index [1, 3]
g_arm_state.joints[i].z_pos = MAT_IDX(transform, 2,3); // index [2, 3]
}
} // can make it return final pos of arm and roll, pitch, yaw if needed