@@ -12,34 +12,35 @@ const uint8_t PHASETAB[8] = {
12
12
};
13
13
14
14
// use an enum here ??
15
- #define BASE 0
16
- #define SHOULDER 1
17
- #define ELBOW 2
18
- #define WRIST_LEFT 3
19
- #define WRIST_RIGHT 4
20
- #define GRIPPER 5
21
- #define ACCESSORY 6
22
- #define JACKS 7
15
+ #define BASE 6
16
+ #define SHOULDER 5
17
+ #define ELBOW 4
18
+ #define WRIST_LEFT 2
19
+ #define WRIST_RIGHT 3
20
+ #define GRIPPER 1
21
+ #define ACCESSORY 7
22
+ #define JACKS 8
23
23
24
24
class Armdroid {
25
25
private:
26
26
uint8_t port[8 ];
27
- long current_positions[8 ];
28
- long target_positions[8 ];
29
- long phases[8 ];
27
+ int64_t current_positions[8 ];
28
+ int64_t target_positions[8 ];
29
+ uint8_t phases[8 ];
30
30
uint8_t dividers[8 ];
31
31
uint8_t counters[8 ];
32
32
public:
33
33
Armdroid (uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t x, uint8_t y, uint8_t z, uint8_t k) {
34
- this ->port [0 ] = a ;
35
- this ->port [1 ] = b ;
36
- this ->port [2 ] = c ;
37
- this ->port [3 ] = d ;
38
- this ->port [4 ] = x ;
39
- this ->port [5 ] = y ;
40
- this ->port [6 ] = z ;
34
+ this ->port [0 ] = x ;
35
+ this ->port [1 ] = y ;
36
+ this ->port [2 ] = z ;
37
+ this ->port [3 ] = a ;
38
+ this ->port [4 ] = b ;
39
+ this ->port [5 ] = c ;
40
+ this ->port [6 ] = d ;
41
41
this ->port [7 ] = k;
42
42
for (uint8_t i = 0 ; i < 8 ; i++) pinMode (this ->port [i], OUTPUT);
43
+ digitalWrite (this ->port [7 ], HIGH);
43
44
}
44
45
void motorGoto (uint8_t m, long pos) {
45
46
this ->target_positions [m] = pos;
@@ -84,15 +85,15 @@ class Armdroid {
84
85
}
85
86
}
86
87
void writeToPort (uint8_t address, uint8_t data) {
87
- uint8_t seven = data << 3 | address;
88
+ uint8_t bits = data << 3 | address;
88
89
for (uint8_t i = 0 ; i < 7 ; i++) {
89
- digitalWrite (this ->port [i], seven & (128 >> i) ? HIGH : LOW);
90
+ digitalWrite (this ->port [i], bits & (1 << i) ? HIGH : LOW);
90
91
}
91
- delayMicroseconds (10 );
92
- digitalWrite (this ->port [7 ], HIGH);
93
- delayMicroseconds (10 );
92
+ delayMicroseconds (20 );
94
93
digitalWrite (this ->port [7 ], LOW);
95
- delayMicroseconds (10 );
94
+ delayMicroseconds (20 );
95
+ digitalWrite (this ->port [7 ], HIGH);
96
+ delayMicroseconds (20 );
96
97
}
97
98
void torqueOff () {
98
99
for (uint8_t i = 0 ; i < 8 ; i++) {
0 commit comments