Skip to content

Commit 16e0b92

Browse files
Update main.ino
1 parent 5e34a3d commit 16e0b92

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

main.ino

+34-35
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#include <Wire.h>
22
#include <Adafruit_PWMServoDriver.h>
33

4+
// Initialize the PCA9685 servo driver
45
Adafruit_PWMServoDriver pca9685 = Adafruit_PWMServoDriver();
56

7+
// Standard positions for the servos when the robot is in a neutral position
68
#define STANDARD_y 325
79
#define STANDARD_xA 315
810
#define STANDARD_xB 295
911
#define STANDARD_xC 305
1012
#define STANDARD_xD 345
1113

14+
// Servo pin assignments
1215
#define SERVO_yD 12
1316
#define SERVO_yC 13
1417
#define SERVO_yB 14
@@ -18,12 +21,14 @@ Adafruit_PWMServoDriver pca9685 = Adafruit_PWMServoDriver();
1821
#define SERVO_xB 6
1922
#define SERVO_xD 7
2023

24+
// Struct to define servo configurations
2125
struct ServoConfig {
22-
uint8_t pin;
23-
int standard;
24-
bool increasesUp;
26+
uint8_t pin; // Servo pin number
27+
int standard; // Standard (neutral) position
28+
bool increasesUp; // Defines whether an increase in value moves the servo up or down
2529
};
2630

31+
// Array storing the configurations for each servo
2732
ServoConfig servos[] = {
2833
{SERVO_yA, STANDARD_y, true},
2934
{SERVO_yB, STANDARD_y, false},
@@ -35,6 +40,7 @@ ServoConfig servos[] = {
3540
{SERVO_xD, STANDARD_xD, false}
3641
};
3742

43+
// Function to move a specific servo with an offset from its standard position
3844
void moveServo(uint8_t servoPin, int offset) {
3945
for (ServoConfig &s : servos) {
4046
if (s.pin == servoPin) {
@@ -51,82 +57,75 @@ void setup() {
5157
pca9685.setPWMFreq(50);
5258
delay(1000);
5359

54-
sit();
60+
sit(); // Start in the sitting position
5561
delay(3000);
56-
stand();
62+
stand(); // Move to the standing position
5763
delay(3000);
58-
sit();
59-
delay(3000);
60-
stand();
61-
delay(3000);
62-
sit();
63-
delay(3000);
64-
stand();
65-
delay(1500);
66-
6764
}
6865

6966
void loop() {
70-
// walk();
67+
// walk(); // Uncomment to enable walking in the main loop
7168
}
7269

70+
// Function to move the robot into a sitting position
7371
void sit() {
7472
for (ServoConfig &s : servos) {
7573
moveServo(s.pin, 0);
7674
}
7775
}
7876

77+
// Function to make the robot stand up
7978
void stand() {
8079
moveServo(SERVO_yA, -120);
8180
moveServo(SERVO_yB, -120);
8281
moveServo(SERVO_yC, -120);
8382
moveServo(SERVO_yD, -120);
8483
}
8584

85+
// Function to move all legs forward in the x-axis
8686
void forward_x() {
8787
moveServo(SERVO_xA, 40);
8888
moveServo(SERVO_xB, 40);
8989
moveServo(SERVO_xC, 40);
9090
moveServo(SERVO_xD, 40);
9191
}
92-
92+
93+
// Function to simulate walking movement
9394
void walk(){
94-
// fase 1
95-
// B e C si abbassano mentre A e D si alzano
96-
// B e C si abbassano
95+
// Phase 1
96+
// B and C lower while A and D lift
97+
// B and C lower
9798
moveServo(SERVO_yB, -120);
9899
moveServo(SERVO_yC, -120);
99-
// forse inserire delay qua
100-
// A e D si alzano
100+
// A and D lift
101101
moveServo(SERVO_yA, -85);
102102
moveServo(SERVO_yD, -85);
103103
delay(250);
104-
// B e C spingono indietro mentre A e D vanno avanti
105-
// B e C spingono indietro
104+
// B and C push backward while A and D move forward
105+
// B and C push backward
106106
moveServo(SERVO_xB, -50);
107107
moveServo(SERVO_xC, -50);
108-
// A e D vanno avanti
108+
// A and D move forward
109109
moveServo(SERVO_xA, 50);
110110
moveServo(SERVO_xD, 50);
111111
delay(500);
112-
// fase 2
113-
// A e D si abbassano mentre B e C si alzano
114-
// A e D si abbassano
112+
113+
// Phase 2
114+
// A and D lower while B and C lift
115+
// A and D lower
115116
moveServo(SERVO_yA, -120);
116117
moveServo(SERVO_yD, -120);
117-
// forse inserire delay qua
118-
// B e C si alzano
118+
// B and C lift
119119
moveServo(SERVO_yB, -85);
120120
moveServo(SERVO_yC, -85);
121121
delay(250);
122-
// B e C vanno avanti mentre A e D spingono indietro
123-
// A e D spingono indietro
122+
// B and C move forward while A and D push backward
123+
// A and D push backward
124124
moveServo(SERVO_xA, -50);
125125
moveServo(SERVO_xD, -50);
126-
// B e C vanno avanti
126+
// B and C move forward
127127
moveServo(SERVO_xB, 50);
128128
moveServo(SERVO_xC, 50);
129-
130129
delay(500);
131-
132-
}
130+
131+
}

0 commit comments

Comments
 (0)