Throughout few days I'm fighting with ServoBlaster implementation for my quadcopter. My ESCs are being shipped right now so I connected servo to make some tests.
Firstly I see new gyro data in terminal, then I hear my servo working. But in my code I've got function calling servo and later on there is a printf to console. I'm quite sure that even if I put new values tens times a second servo refreshes it's position only once a second. It's ticking like a clock. I can't get responsive, smooth move. Servo was plugged to R/C receiver and worked fine.
Second test - echoing script:
Code: Select all
echo 0=701us > /dev/servoblaster
sleep 0.1
echo 0=711us > /dev/servoblaster
sleep 0.1
echo 0=721us > /dev/servoblaster
sleep 0.1
...Whats wrong with my C++ implementation?
Will Arduino (ATmega328 via I2C or SPI) PWM be faster either way and is it good to use it for hardware PWM for my ESCs?
C++
Code: Select all
void setMotors(int s0, int s1, int s2, int s3) {
motor_blaster=fopen("/dev/servoblaster","w");
if (motor_blaster==NULL){
printf("Opening /dev/servoblaster failed \n");
exit(2);
}
fprintf(motor_blaster, "%d=%dus\n",0,s0);
fflush(motor_blaster);
}