Skip to content

Commit 04603de

Browse files
Update and rename armdoid.cpp to armdoid.hpp
1 parent b725258 commit 04603de

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

code/armdroid-class/armdoid.cpp renamed to code/armdroid-class/armdoid.hpp

+25-24
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,35 @@ const uint8_t PHASETAB[8] = {
1212
};
1313

1414
// 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
2323

2424
class Armdroid {
2525
private:
2626
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];
3030
uint8_t dividers[8];
3131
uint8_t counters[8];
3232
public:
3333
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;
4141
this->port[7] = k;
4242
for (uint8_t i = 0; i < 8; i++) pinMode(this->port[i], OUTPUT);
43+
digitalWrite(this->port[7], HIGH);
4344
}
4445
void motorGoto(uint8_t m, long pos) {
4546
this->target_positions[m] = pos;
@@ -84,15 +85,15 @@ class Armdroid {
8485
}
8586
}
8687
void writeToPort(uint8_t address, uint8_t data) {
87-
uint8_t seven = data << 3 | address;
88+
uint8_t bits = data << 3 | address;
8889
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);
9091
}
91-
delayMicroseconds(10);
92-
digitalWrite(this->port[7], HIGH);
93-
delayMicroseconds(10);
92+
delayMicroseconds(20);
9493
digitalWrite(this->port[7], LOW);
95-
delayMicroseconds(10);
94+
delayMicroseconds(20);
95+
digitalWrite(this->port[7], HIGH);
96+
delayMicroseconds(20);
9697
}
9798
void torqueOff() {
9899
for (uint8_t i = 0; i < 8; i++) {

0 commit comments

Comments
 (0)