Shop OBEX P1 Docs P2 Docs Learn Events
trying to write a PID Loop for a BS2P — Parallax Forums

trying to write a PID Loop for a BS2P

Danny22Danny22 Posts: 29
edited 2006-05-11 17:10 in Robotics
I'm trying to write a PID Loop for a BS2P and I'm having trouble multiplying certain constants that are less than one(1). I know and understand the "**" and "*/" functions but they are ineffective for small errors. A Tech at Pololu Robotics told me that the BS2P was just fine for PID loops, just multiply everything by ten(10)! I'm not exactly sure what he means, and in all due respect to him, he had an accent and I couldn't catch his entire explanation. My drive motors are configured as dual-differential(tank style) and I'm most interested in slaving the wheels together in the forward and reverse functions. I have chosen, therefore, to emulate a loop that appeared in "Mobile Robots: Inspiration to Implementation" by Jones, Seiger & Flynn and reinterated in"Building Robot Drive Trains"
by Clark & Owings. The pseudocode for the algorithm is as follows:

Kprop CON 1
Kint CON .1

DO
Gosub Get_setSpeed
Gosub Read L_Encoder
Gosub Read R_Encoder
Isum = Isum + (L_Encoder - R_Encoder)
leftErr = setSpeed - L_Encoder
rgtErr = setSpeed - R_Encoder
leftSpeed = (Kprop * leftErr) - (Kint * Isum)
rgtSpeed = (Kprop * rgtErr) + (Kint * Isum)
Gosub set_rgtPWM
Gosub set_leftPWM
Pause LoopRate
LOOP

Can this algorithm be converted to PBasic successfully or do I have to give up on Parallax Stamps and try another Micon? I'd hate to do that because I have thousands of dollars and hundreds of hours invested in Stamps and Stamp friendly devices. Can anyone help?

Thanks,
Danny22

Post Edited By Moderator (Chris Savage (Parallax)) : 5/11/2006 5:17:21 PM GMT
Sign In or Register to comment.