Virus
Posts: 2
Joined: Fri Jul 11, 2014 9:58 pm

ServoBlaster problem

Tue Jul 15, 2014 6:20 pm

Hello,
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
...
Servo slowly and smoothly went from left to the right.
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);
}
Thank You for help!
Last edited by Virus on Tue Jul 15, 2014 9:55 pm, edited 1 time in total.

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: ServoBlaster problem

Tue Jul 15, 2014 9:09 pm

You may need to post more of the code. The snippet looks odd. You'd expect that function to be called multiple times but you wouldn't expect the pipe to be opened each time. Normally you'd open the pipe just the once during initialisation.

Return to “Automation, sensing and robotics”