I am a novice and would like to create a brushless servo system using RC PWM signals。
Do you have any similar experiences ?
A regular hobby servo requires a 50-300HZ PWM signal with duty cycle of 1ms-2ms to move beween 0-180°.
In the past I’ve used multiWii multicopter FW which was able to read RC-signals, but the receiver had an i2c interface, so IDK, if the arduino measured the duty cycle.
Some camera gimbals (BruGi aka. martinez brushless gimbal) also use RC-signals to control tilt/pan positions.
Both projects were on github, so you might snoop there to find the way they dealt with RC-signals.
To use a BLDC motor as hobby servo you’d have to run simpleFOC in angle mode and translate the received duty cycle to an angle.
Here’s my code:
volatile uint16_t servoPulse = 1500;
void ServoPulseUpdate() {
static uint32_t startTime = 0;
uint32_t curTime = micros();
if (digitalRead(SERVO_PULSE_PIN)) // Pin transitioned from low to high
startTime = curTime; // Start counting pulse time
else // Pin transitioned from high to low
servoPulse = (uint16_t)(curTime - startTime);
}
void setup() {
pinMode(SERVO_PULSE_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(SERVO_PULSE_PIN), ServoPulseUpdate, CHANGE);
servoPulse should range from around 1000 to 2000, although most RC transmitters and servo testers don’t output a precise range so it may go a little outside that or not quite make it to the extremes. And the value is usually pretty noisy, so your motor will never be fully at rest unless you add something like servo deadband to ignore small changes, like if (abs(targetPulse - servoPulse) >= DEADBAND) targetPulse = servoPulse;
My servo tester needs deadband around 5 I think.