
Wheel Arc movement with continous servos
2025.09.21 22:36
#include <ESP32Servo.h>
const int leftServoPin = 6;
const int rightServoPin = 5;
const int leftServoNeutralPoint = 1480;
const int rightServoNeutralPoint = 1500; // Assuming this is correct
Servo servoLW;
Servo servoRW;
// Function to convert a speed (-100 to 100) to a PWM value for each servo
int convertToLeftPWM(int speed) {
// Map speed from [-100, 100] to a PWM range, e.g., [1200, 1760]
return map(speed, -100, 100, 1760, 1200); // Note the inverted mapping for the left servo
}
int convertToRightPWM(int speed) {
// Map speed from [-100, 100] to a PWM range, e.g., [1240, 1760]
return map(speed, -100, 100, 1240, 1760);
}
// Function to control an arc turn
void arcTurn(int baseSpeed, float turnFactor, bool turnRight) {
int leftSpeed;
int rightSpeed;
if (turnRight) {
leftSpeed = baseSpeed * (1 + turnFactor);
rightSpeed = baseSpeed;
} else {
leftSpeed = baseSpeed;
rightSpeed = baseSpeed * (1 + turnFactor);
}
leftSpeed = constrain(leftSpeed, -100, 100);
rightSpeed = constrain(rightSpeed, -100, 100);
servoLW.writeMicroseconds(convertToLeftPWM(leftSpeed));
servoRW.writeMicroseconds(convertToRightPWM(rightSpeed));
}
void setup() {
Serial.begin(115200);
servoLW.attach(leftServoPin);
servoRW.attach(rightServoPin);
}
void loop() {
Serial.println("Performing a right arc turn...");
arcTurn(50, 1.5, true); // Increased turnFactor
delay(3000);
Serial.println("Stopping robot...");
arcTurn(0, 0, true);
delay(2000);
Serial.println("Performing a left arc turn...");
arcTurn(50, 1.5, false); // Increased turnFactor
delay(3000);
Serial.println("Stopping robot...");
arcTurn(0, 0, false);
delay(2000);
}
Comment 0
| No. | Subject | Author | Date | Views |
|---|---|---|---|---|
| Notice | For the first time user of ESP32-S3 super mini users. | me | 2025.04.25 | 806 |
| 16 | Other Approach proposed by Gemini | me | 2025.10.02 | 96 |
| 15 | Data Route | me | 2025.10.02 | 100 |
| 14 |
Extra Hardware Serial + JSON servo control
| me | 2025.09.22 | 139 |
| » |
Wheel Arc movement with continous servos
| me | 2025.09.21 | 154 |
| 12 |
3 Servo Test
| me | 2025.09.21 | 131 |
| 11 |
Object Pascal App getting data from ESP32-S3 (Parsing)
| me | 2025.04.29 | 592 |
| 10 |
Sound Sensor Test
| me | 2025.04.27 | 603 |
| 9 |
Laser distance sensor VL53L0X
| me | 2025.04.27 | 626 |
| 8 |
9DOF : Getting Pitch & Roll with ICM20948 v2
| me | 2025.04.27 | 604 |
| 7 |
Formating output
| me | 2025.04.27 | 592 |
| 6 | Blinking Built-in RGB without delay() | me | 2025.04.25 | 3802 |
| 5 | Built-in RGB led Demo | me | 2025.04.25 | 683 |
| 4 | Servo Demo | me | 2025.04.25 | 585 |
| 3 |
HMC5883L Compass demo
| me | 2025.04.25 | 648 |
| 2 |
I2C Address Search
| me | 2025.04.25 | 632 |
| 1 |
Serial Sample (ASCII Table)
| me | 2025.04.25 | 673 |