Skip to content

Commit 04b485a

Browse files
Added tool / payload to forward_kinematics
1 parent f488bd7 commit 04b485a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎blast/manipulator/manipulator.hpp‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ inline host_fn Matrix jacobian(const Manipulator& manip, const ManipulatorTempDa
6464
// }
6565

6666
inline host_fn void forward_kinematics(const Manipulator& manip, ManipulatorTempData& temp, const Array& joint_pos) {
67-
const auto n_joints = joint_pos.size;
67+
Assert(manip.n_joints == joint_pos.size);
6868

6969
// real s[MAX_JOINTS];
7070
// real c[MAX_JOINTS];
@@ -85,7 +85,7 @@ inline host_fn void forward_kinematics(const Manipulator& manip, ManipulatorTemp
8585
// }
8686
// #endif
8787

88-
for (u32 j = 0; j < n_joints; ++j) {
88+
for (u32 j = 0; j < manip.n_joints; ++j) {
8989
auto s = sin(joint_pos[j]);
9090
auto c = cos(joint_pos[j]);
9191
const Mat3 temp_Q = {c, s, 0, -s, c, 0, 0, 0, 1};
@@ -94,15 +94,20 @@ inline host_fn void forward_kinematics(const Manipulator& manip, ManipulatorTemp
9494

9595
temp.rotations_mult[0] = manip.base_rotation * temp.rotations[0];
9696
temp.p_j[0] = manip.base_position + manip.base_rotation * manip.first_joint_position;
97-
for (u32 j = 1; j < n_joints; j++) {
97+
for (u32 j = 1; j < manip.n_joints; j++) {
9898
temp.rotations_mult[j] = temp.rotations_mult[j - 1] * temp.rotations[j]; // note: add this to *= temp._rotations_mult ?
9999
temp.p_j[j] = temp.p_j[j - 1] + temp.rotations_mult[j - 1] * manip.joint_offsets[j - 1];
100100
}
101-
temp.p_j[n_joints] = temp.p_j[n_joints - 1] + temp.rotations_mult[n_joints - 1] * manip.joint_offsets[n_joints - 1];
101+
// originally for the tool (todo: remove when agreed)
102+
temp.p_j[manip.n_joints] = temp.p_j[manip.n_joints - 1] + temp.rotations_mult[manip.n_joints - 1] * manip.joint_offsets[manip.n_joints - 1];
102103

103104
if (manip.has_tool) {
105+
temp.tool_position = temp.p_j[manip.n_joints - 1] + temp.rotations_mult[manip.n_joints - 1] * manip.tool.position;
106+
temp.tool_rotation = temp.rotations_mult[manip.n_joints - 1] * manip.tool.rotation;
104107
}
105108
if (manip.has_payload) {
109+
temp.payload_position = temp.p_j[manip.n_joints - 1] + temp.rotations_mult[manip.n_joints - 1] * manip.payload.position;
110+
temp.payload_rotation = temp.rotations_mult[manip.n_joints - 1] * manip.payload.rotation;
106111
}
107112
}
108113

0 commit comments

Comments
 (0)