PID control library (in Python?)

Moderator: Steve

PID control library (in Python?)

Postby alanmcdonley » Wed Jul 29, 2015 7:31 pm

Does the Pi Droid Alpha (PiDA) have a PID control library, preferably in Python?

I have 5v LED and logic wheel encoders on my current chassis (repurposed Rug Warrior Pro) which can be used to implement PID (Proportional-Integrative-Derivative) control of the DC motors.

Proportional control yields slow start, then rapid acceleration toward the target velocity, then tapered acceleration approaching the target velocity.

The benefits are smooth starts and stops, with straight paths forward or backward, and more accurate rotations.

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

Re: PID control library (in Python?)

Postby mikronauts » Wed Jul 29, 2015 8:18 pm

Welcome to the forum Alan!

PiDroidAlpha does not natively implement PID, however there are plenty of PID control libraries on the net that could be used.

Here are a few links:

https://pypi.python.org/pypi/pypid/
http://code.activestate.com/recipes/577 ... ontroller/
http://cgkit.sourceforge.net/doc2/pidco ... Controller
http://examples.oreilly.com/9780596809577/CH09/PID.py

Here is a PID tuner:

http://sourceforge.net/projects/pypidtune/

I was working on the API earlier, and I should have the User Manual with some sample code posted by Monday.

The Build Manual is already available from the product page at

http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/

The motors are controlled as follows:

Servo7 / GPIO24 is Motor1PWM
Servo8 / GPIO24 is Motor2PWM

DIO B4 is Motor1DirA
DIO B5 is Motor1DirB
DIO B6 is Motor2DirA
DIO B7 is Motor2DirB

In Python, you would use

robot.digitalWrite(MOTOR1DIRA,0)
robot.digitalWrite(MOTOR1DIRB,0)

robot.digitalWrite(MOTOR2DIRA,0)
robot.digitalWrite(MOTOR2DIRB,0)

to set coast / forward / reverse / break for each motor (coasting is shown above)

then

robot.analogWrite(MOTOR1PWM,speed)
robot.analogWrite(MOTOR2PWM,speed)

So to use a PID loop to control the speed, just incorporate the appropriate analogWrite()

Best Regards,

Bill

alanmcdonley wrote:Does the Pi Droid Alpha (PiDA) have a PID control library, preferably in Python?

I have 5v LED and logic wheel encoders on my current chassis (repurposed Rug Warrior Pro) which can be used to implement PID (Proportional-Integrative-Derivative) control of the DC motors.

Proportional control yields slow start, then rapid acceleration toward the target velocity, then tapered acceleration approaching the target velocity.

The benefits are smooth starts and stops, with straight paths forward or backward, and more accurate rotations.

Alan
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 2 guests

cron