我将四轴飞行器的电机连接到 Raspberry Pi Zero。但是当我尝试旋转电机,即设置速度时,结果证明,电机开始旋转得非常快,它们也可以定期关闭,然后再次开始高速旋转。我怎样才能改变速度?为什么它们有时会关闭?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <wiringPi.h>
#define RIGHT_MOTOR 1
#define LEFT_MOTOR 4
void init_ESC(int num);
void set_speed(int num, int speed);
int main ()
{
int speed = 3320;
wiringPiSetup();
pinMode(RIGHT_MOTOR, PWM_OUTPUT);
pinMode(LEFT_MOTOR, OUTPUT);
//pwmSetMode(PWM_MODE_MS);
//pwmSetClock(50 * pow(10, 6) / 1920 / 1024);
init_ESC(RIGHT_MOTOR);
delay(1000);
while (1)
{
set_speed(RIGHT_MOTOR, speed);
//set_speed(LEFT_MOTOR, speed);
//printf("speed = %d\n", speed);
}
return 0;
}
void init_ESC(int num){
pwmWrite(num, 0);
delay(20);
pwmWrite(num, 1024);
delay(1);
}
void set_speed(int num, int speed){
pwmWrite(num, 0);
delay(20);
pwmWrite(num, 1024);
pwmWrite(num, 0);
delay(20);
pwmWrite(num, 1024);
delayMicroseconds(1100);
}