-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharm.cpp
More file actions
49 lines (38 loc) · 1.4 KB
/
arm.cpp
File metadata and controls
49 lines (38 loc) · 1.4 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
#include "Mandatory.h"
#include "subsystems/arm/arm.h"
#include <numbers>
Point ArmSubsystem::getElbowPos(float angShoulder) {
Point pt(
k_bicepLenInches * std::cos(angShoulder),
k_bicepLenInches * std::sin(angShoulder)
);
return pt;
}
Point ArmSubsystem::getWristPos(float shoulderAng, float elbowAng) {
Point elbowPos = getElbowPos(shoulderAng);
Point pt(
k_forearmLenInches * std::cos(shoulderAng + elbowAng),
k_forearmLenInches * std::sin(shoulderAng + elbowAng)
);
return Point(elbowPos.x + pt.x, elbowPos.y + pt.y);
}
ArmPose ArmSubsystem::getIKJointPoses(Point pt) {
float targetLen = std::sqrt((pt.x * pt.x + pt.y * pt.y)); // Line from shoulder to target
float targetToXAxisAng = std::atan2(pt.y, pt.x);
float targetToBicepAng = std::acos(
(k_forearmLenInches * k_forearmLenInches
- k_bicepLenInches * k_bicepLenInches
+ targetLen * targetLen)
/ (2.0 * k_forearmLenInches * targetLen)
);
// Solve IK:
float bicepToXAxisAng = targetToBicepAng + targetToXAxisAng;
float bicepToForearmAng =
(std::numbers::pi / 2.0)
- std::acos(
(k_forearmLenInches * k_forearmLenInches
- k_bicepLenInches * k_bicepLenInches
+ targetLen * targetLen)
/ (2.0 * k_forearmLenInches * targetLen));
return ArmPose(bicepToXAxisAng, bicepToForearmAng);
}