-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboticArm.cpp
60 lines (41 loc) · 2.13 KB
/
RoboticArm.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
58
59
60
#include <Arduino.h>
#include <Servo.h>
#include "RoboticArm.h"
RoboticArm* RoboticArm::RoboticArmInstance;
void RoboticArm::Setup() {
delete RoboticArmInstance; //Much responsible. Wow.
RoboticArmInstance = new RoboticArm();
pinMode(SHOULDER_OUTPUT_PIN, OUTPUT);
RoboticArmInstance->BaseServo.attach(BASE_OUTPUT_PIN);
RoboticArmInstance->ShoulderServo.attach(SHOULDER_OUTPUT_PIN);
RoboticArmInstance->ElbowServo.attach(ELBOW_OUTPUT_PIN);
RoboticArmInstance->WristServo.attach(WRIST_OUTPUT_PIN);
RoboticArmInstance->ForearmServo.attach(FOREARM_OUTPUT_PIN);
RoboticArmInstance->ClawServo.attach(CLAW_OUTPUT_PIN);
}
void RoboticArm::SetBaseAngle(int baseAngle) {
RoboticArmInstance->BaseAngle = (long)(baseAngle - BASE_ANGLE_MIN) * 180 / (BASE_ANGLE_MAX - BASE_ANGLE_MIN);
}
void RoboticArm::SetShoulderAngle(int shoulderAngle) {
RoboticArmInstance->ShoulderAngle = (long)(shoulderAngle - BASE_ANGLE_MIN) * 180 / (BASE_ANGLE_MAX - BASE_ANGLE_MIN);
}
void RoboticArm::SetElbowAngle(int elbowAngle) {
RoboticArmInstance->ElbowAngle = (long)(elbowAngle - BASE_ANGLE_MIN) * 180 / (BASE_ANGLE_MAX - BASE_ANGLE_MIN);
}
void RoboticArm::SetWristAngle(int wristAngle) {
RoboticArmInstance->WristAngle = (long)(wristAngle - BASE_ANGLE_MIN) * 180 / (BASE_ANGLE_MAX - BASE_ANGLE_MIN);
}
void RoboticArm::SetForearmAngle(int forearmAngle) {
RoboticArmInstance->ForearmAngle = (long)(forearmAngle - BASE_ANGLE_MIN) * 180 / (BASE_ANGLE_MAX - BASE_ANGLE_MIN);
}
void RoboticArm::SetClawAngle(int clawAngle) {
RoboticArmInstance->ClawAngle = (long)(clawAngle - BASE_ANGLE_MIN) * 180 / (BASE_ANGLE_MAX - BASE_ANGLE_MIN);
}
void RoboticArm::UpdateArmPosition() {
RoboticArmInstance->BaseServo.write(RoboticArmInstance->BaseAngle);
RoboticArmInstance->ShoulderServo.write(RoboticArmInstance->ShoulderAngle);
RoboticArmInstance->ElbowServo.write(RoboticArmInstance->ElbowAngle);
RoboticArmInstance->WristServo.write(RoboticArmInstance->WristAngle);
RoboticArmInstance->ForearmServo.write(RoboticArmInstance->ForearmAngle);
RoboticArmInstance->ClawServo.write(RoboticArmInstance->ClawAngle);
}