Choosing pigpiod sample rate? Pi PWM vs pigpiod PWM?

Moderator: Steve

Choosing pigpiod sample rate? Pi PWM vs pigpiod PWM?

Postby alanmcdonley » Sun Aug 09, 2015 8:06 pm

I set up pigpiod to start at boot via the crontab entry:
@reboot /usr/local/bin/pigpiod
This runs the pigpiod at the default sample rate of 5 uSeconds.

With no events and no clients, pigpiod loads my Raspberry Pi B+ at roughly 9% CPU.

The pigpiod docs show possible sample rate options of 1,2,5,8,10 for pigpiod -s <sample_rate>.

Are these the only values possible, and how do I choose a sample rate?

My time critical events:
1) Wheel Encoders:
Each Wheel Encoder has 32 edges per revolution at 1.019 rev/sec at max speed, is approximately 33 events per second or roughly 30 millisecond events.
The maximum out of sync the wheel encoders could be is just short of one edge which should result in about a half inch in 10 feet,(I think), (0.24" difference in translation at 5.4" wheelbase)
It would seem that if I can detect a 333 uSec difference in the encoder events (100 times/second), I should get very straight travel. There are so many variables, wheel wobble, diameter difference, actual turning wheelbase, and probably more.
If there are control delays, and motor response delays, and detection delays, the jitter in the system is bound to be fairly high also.
So if the only choices of sample rate are 1-10, then 10 uSeconds is clearly the rate even though it would seem to be overkill by a factor of 30

2) PWM for servos
The SG90 has a deadband of 7-10 uSeconds and requires a pulse width of 500-2400 uSeconds or 800-3000 uS.
(one place said 800uS = 0 deg. and 3000uS = 180 deg)
I think that means that the servo will not notice differences of less than 10 uSeconds.
1900 to 2200 uSeconds of pulse width range divided by the dead band probably means I can request 190 to 220 different servo positions.
Something like 85-110 left of center and 85-110 right of center, so I can point my range sensor with one to two degree precision.
I read that the maximum beam width for my Sharp IR sensor is about 16cm at midrange of 30" or 5 degrees wide.
I think that means I should take readings about 2.5 degrees apart, which would seem to match the pointing precision with a 10uSec dead band servo.

If the PWM for the servos comes from pigpiod bit-banging the GPIO lines, what sample rate do I need to get this 10uS precision?

3) PWM for DC motors
Maintaining a straight path with the 32 event encoders would seem to mean I want a speed error controllable to the precision of the encoders.
I assume the motor control should count a few wheel encoder events to get a speed for each wheel, and then modify the input to the motor.
I don't know what the motors' angular velocity "dead band" is. I think most people run their bots with 8bit velocity commands,
and some at the low value are useless because the bot doesn't start moving until some minimum power/"velocity" command.
This seems like it is a slow process compared to the wheel encoders which are 30 times slower than the servo demands.

BUT - I read that the PI has a built in PWM on two pins. I had planned these for the DC motors, but if the DC motors are the less demanding, perhaps the Pi should control the tilt/pan servos and the pigpiod should bit-bang the motor PWM which would reduce the event load on the pigpiod by a factor of 30.

I'm so confused now.
alanmcdonley
 
Posts: 91
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Choosing pigpiod sample rate? Pi PWM vs pigpiod PWM?

Postby mikronauts » Mon Aug 10, 2015 6:24 am

You will be fine, just set the timing grain to 10us.

See http://abyz.co.uk/rpi/pigpio/pigpiod.html

The -s option when starting pigpiod allows you to set the timing grain to 10us

pigpiod -s 10

That grain is more than fast enough for your motors, servos and encoder.

Frankly, there are few analog servos precise enough for <10us pulse width grain.
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

Re: Choosing pigpiod sample rate? Pi PWM vs pigpiod PWM?

Postby alanmcdonley » Mon Aug 10, 2015 9:38 am

mikronauts wrote:You will be fine, just set the timing grain to 10us.

See http://abyz.co.uk/rpi/pigpio/pigpiod.html

The -s option when starting pigpiod allows you to set the timing grain to 10us

pigpiod -s 10

That grain is more than fast enough for your motors, servos and encoder.

Frankly, there are few analog servos precise enough for <10us pulse width grain.


Thanks, I'll set it for 10us.

Any thoughts choosing Pi Hardware PWM vs pigpiod PWM?

Does it make a difference in processor load?
alanmcdonley
 
Posts: 91
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Choosing pigpiod sample rate? Pi PWM vs pigpiod PWM?

Postby mikronauts » Mon Aug 10, 2015 11:00 am

You are welcome.

If you are running pigpiod at all, there will not be a difference in processor load if you use one or two hardware PWM's, so there is no point in using the hardware PWM.

10us resolution should be more than good enough for servos and pwm motor control, and should use something less than half the cpu load that 5s resolution uses.

If you use a Pi2, the load will be much reduced as well.

If at a later point in time you need 5us (or better with future firmware) servo/pwm resolution, with zero Pi cpu load, RoboPi is your friend :)

RoboPi off-loads all servo/pwm pulse generation to the eight core risc chip on it.

alanmcdonley wrote:Thanks, I'll set it for 10us.

Any thoughts choosing Pi Hardware PWM vs pigpiod PWM?

Does it make a difference in processor load?
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

Re: Choosing pigpiod sample rate? Pi PWM vs pigpiod PWM?

Postby alanmcdonley » Thu Aug 13, 2015 4:17 am

Anecdotal Datum for pigpiod: (A base layer for the PiDroidAlpha/RoboPi lib PWM if I am reading everything correctly. )

I clocked the processor load of pigpiod default (equivalent to -s 5) on my Pi B+ with top. The CPU% varied from 8.2 to 8.5 with 8.2% the most often seen reading. (This is with no pwm, no callbacks, and no clients.)

Joan, (the pigpiod creator), suggested the default sample rate to be the best choice for me. "mikronauts" (Bill or Steve?) suggested that the 10us sample rate will still allow stable tilt/pan servo control.

I repeated my top test after starting pigpiod -s 10 for 10us sample rate. The CPU load seemed to vacillate between 6.2% and 6.6%; At this point my robot is not hurting to find an extra 2% CPU but I want it to run as "relaxed" as possible until it needs to "sweat".

Running a python client that ramped a 100Hz PWM pin up and down 2%, between 0 and 100%, pulse width every 0.1 sec had no visible effect on the pigpiod CPU%.

I have the tilt/pan servo platform ready for testing when my PiDA kit arrives (and is assembled).

(It also seems that the Pi "hardware" PWM is only one pin or audio, so it is going to be busy doing my robot's text-to-speech audio output.)

Alan
alanmcdonley
 
Posts: 91
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Choosing pigpiod sample rate? Pi PWM vs pigpiod PWM?

Postby mikronauts » Thu Aug 13, 2015 8:02 am

Nice to have some actual numbers!

When you need more CPU power, a Pi 2 will reduce the CPU load by 4x-6x, so 1%-2%

mikronauts = Bill :)
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm


Return to Pi Droid Alpha

Who is online

Users browsing this forum: No registered users and 1 guest

cron