简体   繁体   English

在同一程序中将电机伺服的角度发送到另一个电机伺服

[英]Send angles of a motor servo to an other motor servo in the same program

The goal of our project is to follow a person with a emitter IR, we have also one receiver and 2 motor servo.我们项目的目标是用发射器 IR 跟踪一个人,我们还有一个接收器和 2 个电机伺服。 The first one is use to save the angle of the person and the second to follow the person.第一个用于保存人的角度,第二个用于跟随人。 It is necessary to know that we have an other program for the emitter.有必要知道我们还有一个用于发射器的程序。 However, the save of the angle is still false and our second motor servo does not work.但是,角度的保存仍然是错误的,我们的第二个电机伺服不工作。 We want the 2nd motor to go to the last angle saved when our receiver has results.我们希望第二个电机到 go 到我们的接收器有结果时保存的最后一个角度。

#include <Servo.h> 
#include <IRLibRecvPCI.h>
IRrecvPCI myReceiver(2);//pin number for the receiver
Servo monServo;
Servo monServo1;

void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial); 
    myReceiver.enableIRIn(); // Start the receiver
  Serial.println(F("Ready to receive IR signals"));
    monServo.attach(9);
    monServo1.attach(7);// relier le servomoteur au port 9 
  monServo.write(0);  // positionner le servomoteur à l'angle absolu 0°
}
int angle = 0;
int increment = 1;
 
void loop() {
 
       monServo.write(angle);
   angle = angle + increment;
   if (angle == 0); increment = 1;
   if (angle == 180); increment = -1;

   if (myReceiver.getResults()) {
   monServo1.write(angle);

   Serial.print("detection");
   myReceiver.enableIRIn();
   Serial.println(monServo.read());
;

   
      }
   
     } 
 if (angle == 0); increment = 1;
   if (angle == 180); increment = -1;

Is equivalent to increment = -1;相当于increment = -1;

You have two empty if statements here.这里有两个空的 if 语句。 Remove the first semicolon in each line if you want to change the increment value conditionally.如果要有条件地更改增量值,请删除每行中的第一个分号。

You should also add some delay as your servo won't be able to move 1° in a few milliseconds.您还应该添加一些延迟,因为您的伺服将无法在几毫秒内移动 1°。

There is also one superfluous semicolon at the end of your code代码末尾还有一个多余的分号

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

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