hola necesito regular la velocidad de un servo 360 entre 15 y 30 rpm.
podrían sugerirme cómo hacerlo, gracias!
walter
He trasladado su tema de una categoría de idioma inglés del foro a la categoría International > Español @anon33678531.
En adelante por favor usar la categoría apropiada a la lengua en que queráis publicar. Esto es importante para el uso responsable del foro, y esta explicado aquí la guía "How to get the best out of this forum".
Este guía contiene mucha información útil. Por favor leer.
De antemano, muchas gracias por cooperar.
La forma de variarle la velocidad es introduciendo un delay mas o menos largo entre comandos enviados al servo.
@anon33678531 Hola, Walter.
Haga que el brazo del servo presione un interruptor de límite (botón).
Use un boceto de "rebote de botón" para leer el interruptor.
Cuente las pulsaciones de "botón".
Presione el botón de grabación 1.
Presione el botón de grabación 2.
La diferencia es el TIEMPO por REVOLUCIÓN.
15RPM = 0.00025 rev/ms = 4000ms/rev
30RPM = 0.00050 rev/ms = 2000ms/rev
si (msPerRev > 4000)
disminuya la velocidad del servo.
si (msPerRev < 2000)
aumente la velocidad del servo
Usando Servo.h, puedes comandar un servo continuo de 360° como este:
myservo.write(0); // velocidad máxima en sentido contrario a las agujas del reloj
myservo.write(45); // media velocidad en sentido contrario a las agujas del reloj
myservo.write(90); // parar
myservo.write(135); // media velocidad en el sentido de las agujas del reloj
myservo.write(180); // velocidad máxima en el sentido de las agujas del reloj
Files for WOKWI.COM
sketch.ino
/*
Auto correct servo between 15RPM and 30RPM for Walter
https://wokwi.com/projects/396018983767404545
https://forum.arduino.cc/t/control-velocidad-de-servo-5-5kg-giro-360-entre-15-y-30-rpm/1251242
Continuous servo have different and imperfect values.
These values are approximate:
myservo.write(0); // full-speed counter-clockwise
myservo.write(45); // half-speed counter-clockwise
myservo.write(90); // stop
myservo.write(135); // half-speed clockwise
myservo.write(180); // full-speed clockwise
15RPM = 0.00025 = 4000ms/rev (msPerRev)
30RPM = 0.00050 = 2000ms/rev (msPerRev)
ADJUSTING SERVO SPEED
if (msPerRev > 4000) ( < 15RPM) increase servo speed
if (msPerRev < 2000) ( > 30RPM) decrease servo speed
*/
#include "Servo.h" // add servo library
Servo myservo; // Create a servo object
byte servoPin = 3; // servo signal pin
byte buttonPin = 2; // limit switch
bool lastButtonReading, // old button reading LOW/pressed or HIGH/not pressed
newButtonReading, // new button reading
currentButtonState, // new button state
count; // where to store next time reading
int speed = 90; // start at "stop" speed
unsigned long timer, // when the button was pressed
timeout = 50, // debounce time for a ringing button
time0, // first rotation
time1, // second and subsequent rotations
msPerRev; // difference between first and second rotation is ms-per-revolution
void setup() {
Serial.begin(115200); // start Serial Monitor debugging
myservo.attach(servoPin); // attach servo to servo object
myservo.write(90); // stop the motor
pinMode(buttonPin, INPUT_PULLUP); // microswitch
}
void loop() {
buttonRead();
}
void buttonRead() {
newButtonReading = digitalRead(buttonPin); // read button pin
if (newButtonReading != lastButtonReading) { // if button pin reading changes...
timer = millis(); // ...start a timer
lastButtonReading = newButtonReading; // ... and store current state
}
if ((millis() - timer) > timeout) { // if button state change was longer than timeout
if (currentButtonState == HIGH && // ... while STATE is NOT pressed
newButtonReading == LOW) { // ... and button IS pressed
if (!time0 && !count) { // if time0 is empty
time0 = millis(); // store the time
Serial.print(" time0:");
Serial.println(time0);
}
if (!time1 && count) { // if time1 is empty
time1 = millis(); // store the time
Serial.print(" time1:");
Serial.print(time1);
Serial.print(" ");
}
if (time0 && time1) { // two time stamps have readings
msPerRev = time1 - time0; // difference in times is the RPM
Serial.print(" msPerRev:");
Serial.print(msPerRev);
servoWrite(); // change servo speed
// After the first two rotations, make every rotation calibrate the RPM
time0 = time1; // move second timer to first timer
time1 = 0; // clear second timer
}
count = 1; // force millis() into time1 only
}
currentButtonState = newButtonReading; // change the button state
}
}
void servoWrite() {
if (msPerRev > 4000) { // < 15RPM
speed++; // increase RP<
if (speed > 180) // maximum clockwise speed is 90 + 90 = 180
speed = 180;
}
if (msPerRev < 2000) { // > 30RPM
speed--; // decrease RP<
if (speed < 91) // minimum clockwise speed 90 + 1 = 91
speed = 91;
}
myservo.write(speed); // change clockwise servo rpm
Serial.print(" speed:");
Serial.println(speed);
}
diagram.json
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
{ "type": "wokwi-servo", "id": "servo1", "top": -117.2, "left": 182.4, "attrs": {} },
{
"type": "wokwi-pushbutton-6mm",
"id": "btn1",
"top": -31,
"left": 182.4,
"attrs": { "color": "green" }
}
],
"connections": [
[ "servo1:PWM", "nano:3", "green", [ "h0" ] ],
[ "nano:2", "btn1:1.l", "green", [ "v0" ] ],
[ "nano:5V", "servo1:V+", "red", [ "v0" ] ],
[ "nano:GND.1", "btn1:2.l", "black", [ "v0" ] ],
[ "nano:GND.1", "servo1:GND", "black", [ "v0" ] ]
],
"dependencies": {}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.