forked from madhephaestus/ESP32AnalogRead
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Limb.cpp
57 lines (49 loc) · 1.36 KB
/
Limb.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
/*
* Limb.cpp
*
* Created on: Apr 27, 2021
* Author: aksha
*/
#include <Limb.h>
Limb::Limb(int index, const char *Name, Matrix<4, 4> limbRoot,
hardwareManager *hwptr) {
limbIndex = index;
fiducialtoLimbRoot = limbRoot;
limbName = Name;
hwLocal = hwptr;
}
/*
* Adds a link pointer to the link pointer array
* @param linkPTR, pointer to the link to add
* @param index, the index that the pointer is at
*/
void Limb::addLinkPtr(Link *linkPTR) {
links[numberOfLinks++] = linkPTR;
Serial.println(String(numberOfLinks));
}
Matrix<4, 4>& Limb::FK(Matrix<4, 4> &GlobalTransform, float *currAngles) {
GlobalTransform *= fiducialtoLimbRoot;
for (int i = 0; i < numberOfLinks; i++) {
GlobalTransform = links[i]->computeStep(GlobalTransform, currAngles[i]);
}
return GlobalTransform;
}
IKResult Limb::IK(Matrix<4, 4> &Target, float *Result) {
if (ik == NULL) {
ik = new IKSolver();
}
Target = fiducialtoLimbRoot.Inverse() * Target;
IKResult IKof = ik->IK(Target, Result, links, numberOfLinks);
if (IKof == IKSuccess) {
for (int i = 0; i < numberOfLinks; i++) {
if ((Result[i] > links[i]->MaxLink)
|| (Result[i] < links[i]->MinLink))
return JointLimits;
}
}
return IKof;
}
IKResult Limb::cacheValue(float valueInDegrees, int linkIndex) {
return links[linkIndex]->cacheValue(valueInDegrees);
}
int Limb::GetNumberOfLinks(){return numberOfLinks;}