简体   繁体   English

伺服电机对其他东西做出反应

[英]Servo motor reacts to other things

I am working with Arduino, I connected a servo motor and a normal motor. 我正在和Arduino合作,我连接了伺服电机和普通电机。 They both work but when I start the normal motor script, the servo motor does small spastic stuff. 它们都工作但是当我启动正常的电机脚本时,伺服电机会产生小的痉挛物。 Could anyone help me with this? 任何人都可以帮我这个吗?

    // Includes
#include <Servo.h> 

// Aanmaken van de variabelen voor in de code

int ledPin = 13;
const int motorPin = 2;
int usbnumber = 0;
Servo stuurServo;   // create servo object to control a servo 
int pos = 90;        // variable to store the servo position 


// De eerste setup maken
void setup()
{
    pinMode(ledPin, OUTPUT);
    pinMode(motorPin, OUTPUT);
    stuurServo.attach(12);
    Serial.begin(9600);
    stuurServo.write(pos);
}

void loop()
{
    if (Serial.available() > 0) {
        usbnumber = Serial.read();

    }

    if (usbnumber > 0) {
        if (usbnumber == 1){ // Lampje knipperen
            digitalWrite(ledPin, HIGH);
            delay(1000);
            digitalWrite(ledPin, LOW);
            delay(500);
            digitalWrite(ledPin, HIGH);
            delay(1000);
            digitalWrite(ledPin, LOW);
            delay(500);
            digitalWrite(ledPin, HIGH);
            delay(1000);
            digitalWrite(ledPin, LOW);
            delay(500);
        }else if(usbnumber == 2){ // Motor aan voor 5 seconden
            digitalWrite(motorPin, HIGH);
            delay(20000);
            digitalWrite(motorPin, LOW);
        }else if(usbnumber == 3){ // stuur servo +10 graden
            if(pos != 180){
              pos + 10;
              stuurServo.write(pos);
            }
        }else if(usbnumber == 4){ // stuur servo -10 graden
            if(pos != 0){
              pos - 10;
             stuurServo.write(pos);
            }
        }else if(usbnumber == 5){ // stuur servo liks
             pos = 0;
             stuurServo.write(pos);
        }else if(usbnumber == 6){ // stuur servo rechts
             pos = 180;
             stuurServo.write(pos);
        }else{
            delay(500);
        }
        usbnumber = 0;
    }
 }

Most (hobby) servo motors will twitch or give a little jerk when they are powered up, especially if you power the motor before driving the servo (providing a position control signal). 大多数(业余爱好)伺服电机在通电时都会抽搐或发出一点急动,特别是在驱动伺服电机之前给电机供电(提供位置控制信号)。 The solution is to write to the control line to the servo before allowing power to it. 解决方案是在允许通电之前写入伺服控制线。 Some easy solutions include: 一些简单的解决方案包

  1. controlling power to the servo through something you can turn off/on (PWM, MOSFET someone else help here?) 通过你可以关闭/打开的东西控制伺服电源(PWM,MOSFET别人在这里有帮助吗?)
  2. having a secondary power manual switch you can toggle once your controller is up and running. 使用辅助电源手动开关,您可以在控制器启动并运行后切换。

There is basically nothing you can do in code without some way to have the circuit start up with no power to the Servo until you are driving the position control line. 在驱动位置控制线之前,没有任何方法可以让电路在没有伺服电源的情况下启动,代码基本上没什么可以做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM