[Dprglist] PID

David Anderson davida at smu.edu
Sun Sep 27 14:29:19 PDT 2020


Murray,

I think you are right that the oscillations around Stopped at 0 are also 
probably happening around other set points as well.  So it appears that 
the tuning of the PID is not yet complete.  You could perhaps log the P 
and D errors and see who is contributing.  D terms are sometimes noisy.

But first things first.  Are you certain that when the robot is stopped 
the encoders don't change?   Can you disable the PID and watch the 
encoders and verify that?

If yes, then normally to reduce oscillations one would try to increase 
the Kdrv gain and perhaps reduce the KPro gain.  Without knowing more 
about your implementation it's hard to say.

And there are also other, subtle things that can cause delays in the 
control loop and which in turn introduce oscillations.  Delays bad.

As to steering you  might want to start with just a simple 
velocity/rotation command.  The joysticks I am familiar with are two 
axis devices with velocity on the fore-aft axis and rotation on the 
left/right axis.  Zero'd in the center, which is spring loaded.  Then on 
the robot end, feed to the PID controllers:
                            left_motor = left_pid(velocity+rotation);
                            right_motor = right_pid(velocity-rotation);

So you have a controller that when you push forward on the stick the 
robot goes in a straight line forward, and same with reverse.  If you 
add an offset with the left/right axis you can steer in a curve.  If the 
robot is stopped and you only move the left/right axis, the robot will 
rotate in place, and so on.

The only place I've used a third PID controller to link together the 
errors of the other two in order to steer the robot is on the two-wheel 
balancing robot, nBot.  It uses a different sort of PID controller that 
includes the tilt angle and angular velocity in addition to the wheel 
encoders.  I haven't found that necessary with the other robots.

onward!
dpa





On 9/26/20 8:23 PM, Murray Altheim via DPRGlist wrote:
> Hi David,
>
> I'm happy to say that I've managed to get my new PID controller working
> (thanks to everyone for all the help!) and with my GamePad have been
> running the robot around on the carpet for some preliminary testing. I
> thought about going out onto the front deck but the gales are pretty
> strong today (> 120km/hr gusts).
>
> I've relegated the slew, acceleration and deceleration (as you suggested)
> to upper level functions, so I've now got:
>
>    motors.py     establishes connections with the Thunderborg controller
>    motor.py      provides direct-power drive of a motor, with battery
>                  voltage sensing and safety limiting
>    pid.py        contains two classes:
>        PID class:     a simple PID controller for a single motor (I=0.0)
>        PIDController: provides system-level configuration, the 20Hz
>                       loop thread, set_velocity() and optional slew
>                       control over set_velocity()
>    behaviours.py  where I'm putting upper-level behaviours, callable
>                  from the GamePad (and eventually autonomous control)
>
> I'm currently working on roam() and drive_one_meter() behaviours, the
> latter with acceleration, cruise and deceleration to attempt to drive
> in a straight line and stop at precisely one meter from the starting
> point (with 2295 encoder steps per meter). Then eventually reverse and
> come back to the same spot. No 180 degree turns quite yet...
>
> As I think we've discussed, all of the coding and tuning contributes to
> what we think of as the robot's 'behaviour': e.g., how tightly it hews
> to motion commands, how abruptly it starts and stops, etc. The new PID
> controllers are trickier to drive (manually, via the GamePad) but seem
> much more accurate in terms of "feel". The robot also seems to drive
> better at slower speeds, not surprisingly. I'm beginning to put together
> a blog post and a video describing the overall effort.
>
> I do have several questions.
>
> I believe at this point I've found the best tuning in terms of the
> overall balance, but the robot now has a new behaviour: when "at rest"
> (velocity = 0) after having been in motion, it doesn't sit still but
> hunts back and forth very slightly, maybe about a quarter of a wheel
> revolution. This is clearly the PID oscillating around the zero mark.
> Is this where I might dial in some I term, or adjust the P or D in a
> different direction? I'm a bit loath to change P or D since the current
> performance is, apart from this hunting behaviour, relatively good.
>
> Using each joystick to directly control the motor is a bit trickier
> than before so maybe it's time to learn how to steer properly.
>
> Your robots use velocity and theta. I guess I'm getting close enough
> to being able to consider that now, so I'm keen to understand (as
> we've all discussed in the previous video conference) how to use the
> integral between the two PID controllers for steering. What I'd be
> doing is taking the GamePad's two joysticks (which each return from
> 0 to 255, or -127 to 127) and use the differential between those two
> values as theta to steer the robot, with I suppose the average as the
> overall velocity.  OTOH, I'm wondering if the result wouldn't in
> effect be the same (i.e., left and right joysticks as direct motor
> velocities vs. the difference between as theta and the average as
> velocity).
>
> I'll have to give that last paragraph some further thought, clearly,
> as the answer to that isn't immediately clear to me, suggesting I
> don't yet understand the problem correctly.
>
> I currently blame the distractions of the howling wind...
>
> Cheers,
>
> Murray
>
> On 25/09/20 8:40 am, David Anderson via DPRGlist wrote:
>> Howdy DPRG,
>>
>> As per our discussion at RBNO Tuesday evening on PID tuning, check out:
>>
>> https://en.wikipedia.org/wiki/PID_controller
>>
>> and particularly the cool animation of adjusting P,I,D values in the 
>> "Manual tuning" section about half way down.
>>
>> There's also a useful "for dummies" page at:
>>
>> https://www.csimn.com/CSI_pages/PIDforDummies.html
>
> I've tried documenting my PID journey and have collected quite a few PID
> links (maybe too many) at:
>
>   https://service.robots.org.nz/wiki/Wiki.jsp?page=PIDController
>
> ........................................................................... 
>
> Murray Altheim <murray18 at altheim dot com>                       = 
> =  ===
> http://www.altheim.com/murray/ ===  ===
> = =  ===
>     In the evening
>     The rice leaves in the garden
>     Rustle in the autumn wind
>     That blows through my reed hut.
>            -- Minamoto no Tsunenobu
>
> _______________________________________________
> DPRGlist mailing list
> DPRGlist at lists.dprg.org
> http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org




More information about the DPRGlist mailing list