简体   繁体   English

伺服电机一直试图达到134°以下,出了什么问题?

[英]Servo motor keeps trying to reach beneath 134°, what is wrong?

I am trying to get the Arduino Uno board to control a gripper driven by a servo motor. 我试图让Arduino Uno板控制由伺服电机驱动的夹具。 The servo tries to go beneath 134° which is mechanically impossible. 伺服试图低于134°,这在机械上是不可能的。 What can I do to fix this? 我该怎么做才能解决这个问题?

I tried to limit the motor to 180°, when it was not a reading of wanted buttons it would keep main position (closed, 180) 我试图将电机限制在180°,当它不是想要按钮的读数时它将保持主要位置(关闭,180)

#include <Servo.h>

Servo myservo;

char reading;
int pos;

void setup() {
  // put your setup code here, to run once:
  myservo.attach(9);
  Serial.begin(9600);
}

void loop() {

  if (Serial.available() > 0) {

    reading = Serial.read();
    Serial.print(reading);
    if (reading == 'W' || reading == 'w') {
      pos = 134;
      myservo.write(pos);
      Serial.println("Open");
    }
    else if (reading == 'C' || reading == 'c') {
      pos = 180;
      myservo.write(pos);
      Serial.println("Close");
    }
    else if (reading != 'W' || reading != 'C') {
      myservo.write(180);
    }
  }
}

In your code, you only call attach() passing in the pin number. 在您的代码中,您只需调用传递引脚号的attach()

The servo library requires you to specify the minimum and maximal position of the servo shaft when calling attach() . 伺服库要求您在调用attach()时指定伺服轴的最小和最大位置。 If you don't, you could end up in a situation where you're calling valid positions, but the servo either won't go far enough or tries to go further than mechanically possible. 如果你不这样做,你可能最终会遇到一个你正在调用有效位置的情况,但是伺服要么不够远,要么试图超越机械可能性。

The library needs to the know the minimum and maximum signal pulse widths so that when you call Servo.write() passing in the shaft angle, it can work out the corresponding duty cycle. Servo.write()库需要知道最小和最大信号脉冲宽度,这样当你调用Servo.write()传递轴角时,它可以计算出相应的占空比。

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

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