简体   繁体   English

伺服电机旋转

[英]Servo motor rotation

I am working on a quadcopter flight controller using Arduino. 我正在使用Arduino的四轴飞行器控制器。 I have been having a lot of trouble trying to figure out how to get my motors to rotate in an Anti-clockwise direction. 我一直在努力弄清楚如何让电机逆时针方向旋转,我遇到了很多麻烦。 I currently have the quad-copter motors rotating clockwise but this causes the quad-copter to spin uncontrollably during flight. 我目前有四轮直升机电机顺时针旋转,但这导致四轮直升机在飞行过程中无法控制地旋转。 The code that I am using is displayed below and any help with the problem above would be very much appreciated. 我正在使用的代码如下所示,我们非常感谢您对上述问题的任何帮助。 Thanks in advance. 提前致谢。

The library I am using is: 我正在使用的库是:

#include <Servo.h>

The pins are attached to the Arduino Uno like this. 这些引脚像这样连接到Arduino Uno。

  m1.attach(4);
  m2.attach(6);
  m3.attach(8);
  m4.attach(9);

I call the arm function shown here: 我调用这里显示的arm函数:

arm();

Which invokes this code: 哪个调用此代码:

void arm() {
    // arm the speed controller, modify as necessary for your ESC
    setSpeed(0);
    delay(1000); //delay 1 second,  some speed controllers may need longer
  }

This is the code here then starts up the motors: 这是代码,然后启动电机:

 void startMotors()
  {
     speed = 40; 
     setSpeed(speed);

    Serial.println("Motor Speed: " + speed); 
    motorsOn = true;
  }

As shown the SetSpeed method is invoked in both arm and startmotors function. 如图所示,在arm和startmotors函数中调用SetSpeed方法。

void setSpeed(int speed) {
    // speed is from 0 to 100 where 0 is off and 100 is maximum speed
    //the following maps speed values of 0-100 to angles from 0-180,
    // some speed controllers may need different values, see the ESC instructions
    int angle = map(speed, 0, 100, 0, 180);
    m1.write(angle);
    m2.write(angle);
    m3.write(angle);
    m4.write(angle);
  }

Now, the arm function I am not worried about because it is just used for arming and no rotation is need but, its in the start motors function where I need to figure out how to get motors m2 and m3 to rotate Anti - clockwise. 现在,我不担心的手臂功能,因为它只是用于布防,不需要旋转,但是,它在启动电机功能,我需要弄清楚如何让电机m2和m3逆时针旋转。 Otherwise, the quadcopter will spin in flight, this problem when solved will help to keep the quadcopter stable on left off. 否则,四轴飞行器将在飞行中旋转,这个问题在解决时将有助于使四轴飞行器保持稳定在左侧。 I Hope this modification is enough for you to Understand and again thank you in advance. 我希望这个修改足以让你理解并再次感谢你。

Your problem is not in the arduino side of things, it's in how you have your motors connected. 你的问题不在于arduino方面,而在于你如何连接电机。 Your motors will have 3 wires going between them and your ESCs, you need to flip two of those wires. 您的电机将在它们与您的ESC之间连接3根电线,您需要翻转其中两根电线。 Doesn't matter which ones you switch. 你切换哪个都没关系。 After you do that, make sure that the propellers are on the correct way. 执行此操作后,请确保螺旋桨处于正确的位置。 (Tell me if you have an uncommon setup and I will help you from there.) (告诉我,如果你有一个不常见的设置,我会从那里帮助你。)

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

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