[Dprglist] Power vs Velocity for PID controllers

Jose Quinones avayanings at gmail.com
Tue Apr 21 04:20:58 PDT 2020


Hi Murray,

The way I do it is that I have two PI loop (I only use integral and
Proportional components) in the following cascade fashion. The Speed PI
Loop receives the reference from the speed measurement engine. I do not
have shaft encoders (SE), but since in 3 phase BLDC you need to commutate
electronically, the speed is derived from this. With a SE it should be way
easier. Anyway, the Speed PI gets this reference and then regulates against
the command which is whatever speed you want to go to. I use Hz in
electrical revolution, which is not the same as mechanical revolutions or
RPM's. But it is just simple math, so at the end of the day it can be
anything.

The trick is that the output of the Speed PI Loop is the Current PI
reference. That is, the Speed PI drives the Current PI and the Current PI
drives the motor. How so?

The Current PI regulates current. I measure current from the motor's tri
phase inverter's SENSE resistor network. This current is "compared" against
the current reference (which was generated by the Speed PI) and then the
Current PI Loop's output is the duty cycle. The duty cycle is what drives
the motor.

Seems like a good topic so I may write a blog posting with pictures to
illustrate better all of these mechanisms. I am intrigued as to why you
want to regulate power, as the only application where I have seen this
technique employed is in vacuum cleaners. I mean, I have no argument for
why you wouldn't want to use it on robots, but seems to me with robotics it
may make more sense to do position loops.

Anyway, just wanted to share my thoughts as a means to hopefully steer the
discussion in the right direction/directions ;-)

Best regards,

JIQ

On Tue, Apr 21, 2020 at 12:04 AM Murray Altheim via DPRGlist <
dprglist at lists.dprg.org> wrote:

> Hi all,
>
> Over the past week I've spent many an hour working on my Python-
> based PID controller, which is using a ThunderBorg motor controller
> under the hood to drive a quartet (left-right pairs) of OSEPP motors.
>
> I've kinda got something working, at least the PD part of it seems
> functional, but there's a big gaping hole where a certain part of
> the implementation is concerned: prior to PID I was "successfully"
> driving the robot based on an encoder-based velocity measurement,
> but there was no PID, and my recent attempts to create a PID
> controller using velocity have failed.
>
> I believe this is due to the fact that I was attempting to use the
> velocity measurement as the PID input to set the motor power. As I
> think David noted in his YouTube video, there isn't a direct relationship
> between motor power and velocity so this was bound to fail. I like
> fail as much as the next person, but success is nice too.
>
> So with that in mind I've gone back to a power-based PID controller,
> knowing I still have a certain mountain to climb.
>
> The question I now have is: how to add a velocity-based control to
> my robot? Do I come up with some mathematical relationship between
> velocity and motor power, or do I create a velocity-based PID
> controller **over top** of the power-based PID controller, i.e.,
> two layers of PID control?
>
> Much-simplified pseudo-code:
>
>    KP = some_constant
>    KI = some_constant
>    KD = some_constant
>
>    target_power = 0.5
>
>    while True:
>        current_power = motor.get_power()
>        error = target_power - current_power
>
>        k_diff = KP * error
>        i_diff = KI * sum_errors
>        d_diff = KD * last_error
>
>        output = k_diff + i_diff + d_diff
>        slewed_output = slew(output)
>        new_power = current_power + slewed_output
>        set_motor_power(new_power)
>
>        last_error = error
>        sum_errors += error
>
> So would I incorporate velocity into the above somehow, or build
> Yet Another PID controller for velocity (using roughly the same
> structure as above, but solely dealing with velocity) that calls
> the above power-based PID controller?
>
> I thought perhaps we could discuss this in tomorrow's Robot Builders
> Night Virtual get together... but an email discuss is also welcome,
> thanks!
>
> Cheers,
>
> Murray
>
> ...........................................................................
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dprg.org/pipermail/dprglist-dprg.org/attachments/20200421/52fb8fbf/attachment.html>


More information about the DPRGlist mailing list