Csound Csound-dev Csound-tekno Search About

PID control implementation in Csound?

Date2016-04-07 21:02
FromJason Conklin
SubjectPID control implementation in Csound?
Hello Csounders,

Has anyone experimented with implementing PID, PID-like, or perhaps
other feedback control systems within Csound? I've been playing around
with the idea a bit lately, primarily using the integ and diff opcodes
and global variables for feedback -- but haven't had much luck getting
results that look like those of classic control theory. Before delving
too much further, I wanted to see if I was trying to reinvent the
wheel, or whether a much different approach would be more fruitful.

My lack of success so far may stem from the fact that my formal study
of controls hasn't yet delved into the discrete systems, which is
obviously relevant in the Csound world. Also, I'm not really clear on
how diff and integ work internally; I've mostly just been playing
around, e.g. printk-ing variables to a file and seeing what happens.
That said, this is something I'd really like to work with more deeply
in future work.

Any thoughts or tips on how to proceed or what to read would be most
welcome! Thank you,

Jason Conklin

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-04-07 21:37
FromRichard
SubjectRe: PID control implementation in Csound?
Interesting idea. I wonder how you intend to use this?
I'm a process control engineer in my day job, BTW.
As you know, in a traditional PID controller the output tries to correct 
the difference between the actual (measured) value and the setpoint.
This process takes some time, usually in the order of seconds, depending 
on the p, i and d parameters...
Just brainstorming how and where this could be applied in Csound:
pitch detection,
FM synthesis,
filtering,
delay lines,
...

Richard


On 07/04/16 22:02, Jason Conklin wrote:
> Hello Csounders,
>
> Has anyone experimented with implementing PID, PID-like, or perhaps
> other feedback control systems within Csound? I've been playing around
> with the idea a bit lately, primarily using the integ and diff opcodes
> and global variables for feedback -- but haven't had much luck getting
> results that look like those of classic control theory. Before delving
> too much further, I wanted to see if I was trying to reinvent the
> wheel, or whether a much different approach would be more fruitful.
>
> My lack of success so far may stem from the fact that my formal study
> of controls hasn't yet delved into the discrete systems, which is
> obviously relevant in the Csound world. Also, I'm not really clear on
> how diff and integ work internally; I've mostly just been playing
> around, e.g. printk-ing variables to a file and seeing what happens.
> That said, this is something I'd really like to work with more deeply
> in future work.
>
> Any thoughts or tips on how to proceed or what to read would be most
> welcome! Thank you,
>
> Jason Conklin
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>          https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-04-07 23:46
FromOeyvind Brandtsegg
SubjectRe: PID control implementation in Csound?
I wonder if this is somehow related to the methods used in the plltrack opcode?

2016-04-07 22:37 GMT+02:00 Richard :
> Interesting idea. I wonder how you intend to use this?
> I'm a process control engineer in my day job, BTW.
> As you know, in a traditional PID controller the output tries to correct the
> difference between the actual (measured) value and the setpoint.
> This process takes some time, usually in the order of seconds, depending on
> the p, i and d parameters...
> Just brainstorming how and where this could be applied in Csound:
> pitch detection,
> FM synthesis,
> filtering,
> delay lines,
> ...
>
> Richard
>
>
>
> On 07/04/16 22:02, Jason Conklin wrote:
>>
>> Hello Csounders,
>>
>> Has anyone experimented with implementing PID, PID-like, or perhaps
>> other feedback control systems within Csound? I've been playing around
>> with the idea a bit lately, primarily using the integ and diff opcodes
>> and global variables for feedback -- but haven't had much luck getting
>> results that look like those of classic control theory. Before delving
>> too much further, I wanted to see if I was trying to reinvent the
>> wheel, or whether a much different approach would be more fruitful.
>>
>> My lack of success so far may stem from the fact that my formal study
>> of controls hasn't yet delved into the discrete systems, which is
>> obviously relevant in the Csound world. Also, I'm not really clear on
>> how diff and integ work internally; I've mostly just been playing
>> around, e.g. printk-ing variables to a file and seeing what happens.
>> That said, this is something I'd really like to work with more deeply
>> in future work.
>>
>> Any thoughts or tips on how to proceed or what to read would be most
>> welcome! Thank you,
>>
>> Jason Conklin
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>          https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here


Date2016-04-07 23:58
FromJason Conklin
SubjectRe: PID control implementation in Csound?
On Thu, Apr 7, 2016 at 3:37 PM, Richard  wrote:
> Interesting idea. I wonder how you intend to use this?
> I'm a process control engineer in my day job, BTW.

Thanks for the response.

I'm an "aspiring" control engineer, but along the way I have dropped
my iron in a few fires (embedded systems, software/hardware testing,
systems engineering). :-)


> As you know, in a traditional PID controller the output tries to correct the
> difference between the actual (measured) value and the setpoint.
> This process takes some time, usually in the order of seconds, depending on
> the p, i and d parameters...

Right, this is exactly what we're studying/refining in my class. In
part I'm just curious what the parameters and possible performance
characteristics (settling time, etc.) might look like, and whether the
model applies (as I imagine it) to the digital audio domain.

As for what I intend to use this for, it's an open-ended, explorative
interest... at this stage I just want to be able to play with the
capability in whatever audio context may strike my fancy. Having
audio-based implementations of math models has been very helpful to my
general understanding in the past, and often gives me new things to
try in the composition/musical domain.

Indirectly, this is inspired somewhat by the cybernetic compositions
of Roland Kayn, which -- I assume, but don't know -- probably
implemented similar structures in analog synth hardware.

> Just brainstorming how and where this could be applied in Csound:
> pitch detection,
> FM synthesis,
> filtering,
> delay lines,

Just the kinds of things I have in mind. Controlling the parameters of
synthesis or a filter of any kind; or timing of reinit, delay, or
other timed events, etc. Also, if a physical transducer of some kind
were introduced to the feedback loop, things could get very
interesting/complex!

Initially I figured I'd just try to cobble something together to
control the pitch of an oscil, but then, as a proof-of-concept, I
decided to take a step back and just output arbitrary k- or a-rate
values to see how they looked. As I said, I haven't had great success
yet.

As I mentioned earlier, I'm not exactly clear on what the diff opcode
does under the hood, so maybe I need to dive into the csound source
and investigate that.

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-04-08 00:03
FromJason Conklin
SubjectRe: PID control implementation in Csound?
On Thu, Apr 7, 2016 at 5:46 PM, Oeyvind Brandtsegg
 wrote:
> I wonder if this is somehow related to the methods used in the plltrack opcode?
>

Ooh, I will be looking into that opcode, thanks for the tip. My
(meager) understanding of PLLs -- if the opcode name is any indication
of how it works -- is that the techniques are related, if not quite
the same as what I have been messing with. Something about lag-lead
compensators?

Jason

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-04-08 08:10
FromOeyvind Brandtsegg
SubjectRe: PID control implementation in Csound?
Yes; I was thinking in line of 'related' more than 'the same'. I don't
know all the details really, so you're probably better equipped to
know the differences.
I t will be interesting to see what you come up with. Maybe it can
also be generalized into a k-rate opcode for controlling various
processes?

2016-04-08 1:03 GMT+02:00 Jason Conklin :
> On Thu, Apr 7, 2016 at 5:46 PM, Oeyvind Brandtsegg
>  wrote:
>> I wonder if this is somehow related to the methods used in the plltrack opcode?
>>
>
> Ooh, I will be looking into that opcode, thanks for the tip. My
> (meager) understanding of PLLs -- if the opcode name is any indication
> of how it works -- is that the techniques are related, if not quite
> the same as what I have been messing with. Something about lag-lead
> compensators?
>
> Jason
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>         https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here