-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServoServer.cpp
87 lines (73 loc) · 2.18 KB
/
ServoServer.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* ServoServer.cpp
*
* Created on: Mar 1, 2019
* Author: jmmckinney
*/
#include "ServoServer.h"
int servoPins[MAX_POSSIBLE_SERVOS] = {
FRONT_RIGHT_NECK, //0
FRONT_LEFT_NECK, //1
REAR_RIGHT_TAIL, //2
REAR_LEFT_TAIL, //3
FRONT_RIGHT_SHOULDER_TILT, //4
FRONT_RIGHT_SHOULDER_FORWARD_BACKWARD, //5
FRONT_RIGHT_ELBOW, //6
FRONT_LEFT_SHOULDER_TILT, //7
FRONT_LEFT_SHOULDER_FORWARD_BACKWARD, //8
FRONT_LEFT_ELBOW, //9
REAR_RIGHT_SHOULDER_TILT, //10
REAR_RIGHT_SHOULDER_FORWARD_BACKWARD, //11
REAR_RIGHT_ELBOW, //12
REAR_LEFT_SHOULDER_TILT, //13
REAR_LEFT_SHOULDER_FORWARD_BACKWARD, //14
REAR_LEFT_ELBOW, //15
PAN_NECK, //16
TILT_NECK, //17
PAN_TAIL, //18
TILT_TAIL //19
};
ServoServer::ServoServer()
: PacketEventAbstract(1962) {
for (int i = 0; i < MAX_POSSIBLE_SERVOS; i++) {
if (servoPins[i] < 0) {
servos[i] = NULL;
continue;
}
servos[i] = new Servo();
servos[i]->attach(servoPins[i],500,2500);
}
for (int i = 0; i < MAX_POSSIBLE_SERVOS; i++) {
if (servoPins[i] < 0) {
servos[i] = NULL;
continue;
}
servos[i]->write(90);
}
for (int i = 0; i < MAX_POSSIBLE_SERVOS; i++) {
if (servoPins[i] < 0) {
servos[i] = NULL;
continue;
}
servos[i]->write(90);
}
}
ServoServer::~ServoServer() {
// TODO Auto-generated destructor stub
}
//User function to be called when a packet comes in
// Buffer contains data from the packet coming in at the start of the function
// User data is written into the buffer to send it back
void ServoServer::event(float *buffer) {
uint8_t *bBuffer = (uint8_t *)buffer;
//Serial.print("\r\n Servo Packet ");
for (int i = 0; i < MAX_POSSIBLE_SERVOS; i++) {
if (servoPins[i] < 0) {
continue;
}
int value = bBuffer[i];
//Serial.print("[ "+String(i)+" , "+String(servoPins[i])+" , "+String(value)+" ]");
//if(value>0&& value<254)
servos[i]->write(constrain(value, 0, 180));
}
}