# numerical methods for calculating PID equivalent functions

Started by March 2, 2015
```Hi,

Can a partial differential equation be numerically calculated to
give a function that is equivalent to a PID loop for controlling
a multivariable system (ie a lunar lander with yaw/pitch/thrust
to land on a given X/Y coordinate from a given altitude)?

Do partial differential equation solvers ie for the heat equation,
also work for large numbers of variables, ie 10?

Is this method useful for this:

http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method

Also does anyone know of existing code or a website that
can be used to generate these types of solutions?

cheers,
Jamie

```
```On Tuesday, 3 March 2015 14:29:56 UTC+11, Jamie M  wrote:
> Hi,
>
> Can a partial differential equation be numerically calculated to
> give a function that is equivalent to a PID loop for controlling
> a multivariable system (ie a lunar lander with yaw/pitch/thrust
> to land on a given X/Y coordinate from a given altitude)?

Numerical integration is routine, and can be pretty accurate (if you are careful to avoid pathological situations, like dividing by zero).

> Do partial differential equation solvers ie for the heat equation,
> also work for large numbers of variables, ie 10?

My Ph.D. work used the Fletcher-Powell multi-parameter non-linear curve fitting procedure to find the three paratetmeters (starting concentration, end-concentration and rate constant) that fitted a numerically integrated rate constant to a string of observed reagent concentrations.

You need more observation than parameters to get a unique solution, and the observations do have to constrain all the parameters - I could reliably extract three parameters from my strings of several hundred observations,but trying to extract a fourth - the thermal resistance of the reaction medium - left me with confidence limits rather larger than my parameter space.

> Is this method useful for this:
>
> http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method

That's kind of basic. The nice part of Fletcher-Powell least squares minimisation is that it documents the least squares surface around the best-fit parameter set, which allows you to extract confidence limits on how well your data defines your parameters.

Straight numerical methods can get you to the same solution, but they don't tell you how reliable/sensitive it is.

> Also does anyone know of existing code or a website that
> can be used to generate these types of solutions?

Mu Ph.D. thesis cites H.H Rosenbrook and C. Storey's "Computational Techniques for Chemical Engineers" Vol 7 in Pergamon's International Series Monographs in Chemical Engineering from 1964, but it wasn't the only, or the most useful reference I used (which was probably the M.Sc. Thesis written by one of the demonstrators in the Theory of Computation Course that I took at the time.

There should be lots of stuff around, but I'm way out of touch with that area.

--
Bill Sloman, Sydney
```
```On Mon, 02 Mar 2015 19:29:48 -0800, Jamie M wrote:

> Hi,
>
> Can a partial differential equation be numerically calculated to give a
> function that is equivalent to a PID loop for controlling a
> multivariable system (ie a lunar lander with yaw/pitch/thrust to land on
> a given X/Y coordinate from a given altitude)?
>
> Do partial differential equation solvers ie for the heat equation,
> also work for large numbers of variables, ie 10?
>
> Is this method useful for this:
>
> http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
>
> Also does anyone know of existing code or a website that can be used to
> generate these types of solutions?

Sounds an awful lot like a quadcopter navigation problem -- you may find
lots of current work there in the form of University senior projects.

For a lunar lander-ish problem it'd be yaw, pitch, _roll_ and thrust --
you need to control all three axes of rotation.  At some small loss of
optimality you could separate thrust in the direction of gravity from
side thrust, the one controlled primarily by throttling the main motor,
and the other controlled by pitch, roll, and (indirectly), yaw.

--
www.wescottdesign.com
```
```On 3/2/2015 11:13 PM, Tim Wescott wrote:
> On Mon, 02 Mar 2015 19:29:48 -0800, Jamie M wrote:
>
>> Hi,
>>
>> Can a partial differential equation be numerically calculated to give a
>> function that is equivalent to a PID loop for controlling a
>> multivariable system (ie a lunar lander with yaw/pitch/thrust to land on
>> a given X/Y coordinate from a given altitude)?
>>
>> Do partial differential equation solvers ie for the heat equation,
>> also work for large numbers of variables, ie 10?
>>
>> Is this method useful for this:
>>
>> http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
>>
>> Also does anyone know of existing code or a website that can be used to
>> generate these types of solutions?
>
> Sounds an awful lot like a quadcopter navigation problem -- you may find
> lots of current work there in the form of University senior projects.
>
> For a lunar lander-ish problem it'd be yaw, pitch, _roll_ and thrust --
> you need to control all three axes of rotation.  At some small loss of
> optimality you could separate thrust in the direction of gravity from
> side thrust, the one controlled primarily by throttling the main motor,
> and the other controlled by pitch, roll, and (indirectly), yaw.
>

Hi,

Maybe some software like this would work?

http://openopt.org/interalg

(also has specifiable accuracy)

cheers,
Jamie

```
```On 3/2/2015 11:13 PM, Tim Wescott wrote:
> On Mon, 02 Mar 2015 19:29:48 -0800, Jamie M wrote:
>
>> Hi,
>>
>> Can a partial differential equation be numerically calculated to give a
>> function that is equivalent to a PID loop for controlling a
>> multivariable system (ie a lunar lander with yaw/pitch/thrust to land on
>> a given X/Y coordinate from a given altitude)?
>>
>> Do partial differential equation solvers ie for the heat equation,
>> also work for large numbers of variables, ie 10?
>>
>> Is this method useful for this:
>>
>> http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
>>
>> Also does anyone know of existing code or a website that can be used to
>> generate these types of solutions?
>
> Sounds an awful lot like a quadcopter navigation problem -- you may find
> lots of current work there in the form of University senior projects.
>
> For a lunar lander-ish problem it'd be yaw, pitch, _roll_ and thrust --
> you need to control all three axes of rotation.  At some small loss of
> optimality you could separate thrust in the direction of gravity from
> side thrust, the one controlled primarily by throttling the main motor,
> and the other controlled by pitch, roll, and (indirectly), yaw.
>

Hi,

I was thinking that an N-dimensional matrix could be used maybe, where
each input variable is a dimension in the matrix and quantized to say
10 different values for each variable (or more if required for higher
resolution).  Once this matrix is built it will hold all the possible
quantized states of the system, including initial state, final state
and any intermediate state (the matrix could be very large if there
are many variables).  All that is required to finish the algorithm is
to find a good path through the matrix by moving one row/column at a
time from the initial state to the final state.  This could be
calculated real time with a path finding algorithm that tries to
maximize/minimize calculated values based on the variables, or else it
could be found via by exploring many possible paths and narrowing the
number of them down as they become impossible due to being a dead end,
ie not able to traverse to the end state, which may or may not require
pre-written rules to limit valid traversal paths.

Building up a big state matrix like this might start to be similar to
building a neural network, which makes sense as they are used for
control algorithms too, but to limit the matrix size, they use
techniques like this:

http://en.wikipedia.org/wiki/Convolutional_neural_network

(wild brainstorming mode off!)

cheers,
Jamie

```
```Jamie M <jmorken@shaw.ca> wrote:

> Hi,
>
> Can a partial differential equation be numerically calculated to
> give a function that is equivalent to a PID loop for controlling
> a multivariable system (ie a lunar lander with yaw/pitch/thrust
> to land on a given X/Y coordinate from a given altitude)?
>
> Do partial differential equation solvers ie for the heat equation,
> also work for large numbers of variables, ie 10?
>
> Is this method useful for this:
>
> http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
>
> Also does anyone know of existing code or a website that
> can be used to generate these types of solutions?
>
> cheers,
> Jamie

if you have a MIMO (multiple inputs, multiple outputs) system and you
can completely identify the system, the best is to use a "state control
system".

For example:
http://electrical4u.com/state-space-analysis-of-control-system/
http://en.wikibooks.org/wiki/Control_Systems/State-Space_Equations

Bye Jack
--
Yoda of Borg am I! Assimilated shall you be! Futile resistance is, hmm?
```
```On Tuesday, 3 March 2015 19:28:21 UTC+11, Jamie M  wrote:
> On 3/2/2015 11:13 PM, Tim Wescott wrote:
> > On Mon, 02 Mar 2015 19:29:48 -0800, Jamie M wrote:
> >
> >> Hi,
> >>
> >> Can a partial differential equation be numerically calculated to give a
> >> function that is equivalent to a PID loop for controlling a
> >> multivariable system (ie a lunar lander with yaw/pitch/thrust to land on
> >> a given X/Y coordinate from a given altitude)?
> >>
> >> Do partial differential equation solvers ie for the heat equation,
> >> also work for large numbers of variables, ie 10?
> >>
> >> Is this method useful for this:
> >>
> >> http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
> >>
> >> Also does anyone know of existing code or a website that can be used to
> >> generate these types of solutions?
> >
> > Sounds an awful lot like a quadcopter navigation problem -- you may find
> > lots of current work there in the form of University senior projects.
> >
> > For a lunar lander-ish problem it'd be yaw, pitch, _roll_ and thrust --
> > you need to control all three axes of rotation.  At some small loss of
> > optimality you could separate thrust in the direction of gravity from
> > side thrust, the one controlled primarily by throttling the main motor,
> > and the other controlled by pitch, roll, and (indirectly), yaw.
> >
>
> Hi,
>
> I was thinking that an N-dimensional matrix could be used maybe, where
> each input variable is a dimension in the matrix and quantized to say
> 10 different values for each variable (or more if required for higher
> resolution).

Not a good idea. "Hill climbing" methods go from plausible solutions to better solutions, and - for well-conditioned problems - can get to the best solution remarkably quickly.

Scatter-gun searching in multi-parameter space can use up a lot of time to get someplace that isn't all that interesting.

<snip>

--
Bill Sloman, Sydney

```
```On 3/3/2015 1:14 AM, Jack wrote:
> Jamie M <jmorken@shaw.ca> wrote:
>
>> Hi,
>>
>> Can a partial differential equation be numerically calculated to
>> give a function that is equivalent to a PID loop for controlling
>> a multivariable system (ie a lunar lander with yaw/pitch/thrust
>> to land on a given X/Y coordinate from a given altitude)?
>>
>> Do partial differential equation solvers ie for the heat equation,
>> also work for large numbers of variables, ie 10?
>>
>> Is this method useful for this:
>>
>> http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
>>
>> Also does anyone know of existing code or a website that
>> can be used to generate these types of solutions?
>>
>> cheers,
>> Jamie
>
> if you have a MIMO (multiple inputs, multiple outputs) system and you
> can completely identify the system, the best is to use a "state control
> system".
>
> For example:
> http://electrical4u.com/state-space-analysis-of-control-system/
> http://en.wikibooks.org/wiki/Control_Systems/State-Space_Equations
>
> Bye Jack
>

Hi,

Thanks, I recall Tim Wescott mentioning this a long time ago to me,
but I settled on a simple PID loop doh! :)

cheers,
Jamie

```
```Jamie M <jmorken@shaw.ca> wrote:

> Hi,
>
> Thanks, I recall Tim Wescott mentioning this a long time ago to me,
> but I settled on a simple PID loop doh! :)

yep, 95% of the time a PID is quite enough :)

Bye Jack
--
Yoda of Borg am I! Assimilated shall you be! Futile resistance is, hmm?
```
```On 3/3/2015 3:03 AM, Jack wrote:
> Jamie M <jmorken@shaw.ca> wrote:
>
>> Hi,
>>
>> Thanks, I recall Tim Wescott mentioning this a long time ago to me,
>> but I settled on a simple PID loop doh! :)
>
> yep, 95% of the time a PID is quite enough :)
>
> Bye Jack
>

Hi,

I am actually thinking of something more like the state space control
system, but with all the MIMO states in the matrix, and possibly
hierarchical matrices as well depending on if the system can be broken
down hierarchically.

So for a system with yaw/pitch/roll/throttle1,2,3,4 (total of seven
dimensions) for acrobatic quadcopter control for example, if each
variable is given 100 possible states, that is 10^14 elements in the 7
dimensional matrix corresponding to each of the possible state
configurations.

This matrix would be configured as a spare matrix, so that all
elements are empty and unallocated until filled to save space.

Now the next step is to fill "good" states, so to do that either a real
or simulated quadcopter flight (or large sets of flight data) are loaded
into the matrix for the specific quadcopter being used.  This will
generate a lot of data in the matrix, but still it will be 99.9%+ empty,
and the generated data will be valid flight data only.

Once the flight data is entered a data mining type algorithm can be used
to generate "traversal paths" within the 7 dimensional matrix that are
weighted based on how traveled the state space is from one area to
another, this would correspond to common maneuvers correlated to all the
other state space variables.

Once all these valid paths are identified, they can be used for actual
autonomous control of the craft.

For autonomous flight, by looking at the actual yaw/pitch/roll of the
quadcopter, this can be referenced to all the states in the 7
dimensional matrix that have similar yaw/pitch/rolls, and then based on
the desired outcome (ie stabilize the craft pitch/yaw/roll to zero
degrees) the set of traversal paths that can likely accomplish this
can be selected from, and the actual yaw/pitch/roll towards zero can
be recorded back into the state space table to reenforce this path (the
next time it is calculated from the "data mining" or "path fitness"
algorithm), ideally this would run in real time to update the state
space continuously.

This system can be paired with specific simplified "pre known" common
acrobatic maneuvers that can be mapped onto the larger state space
in a somewhat experimental way to aid in automatic learning of
maneuvers, like a training manual or dictionary of valid flight
maneuvers.

These state spaces can be built hierarchically, ie this
acrobatic/stabilization state space can exist somewhat independent of
a higher level state space that is used for higher level navigation or
specific mission goals etc.

The lower level state spaces are more concerned with craft survival in
this case, ie restricting the craft to allowable safe maneuvers, while
the higher level state spaces might be concerned with survival in
reference to the ground or max velocities/altitudes etc, and next
higher level state spaces would be for waypoint following or mission
goals, but the low level state spaces would always take priority,
but could have feedback from higher level state spaces to influence
the specific state space traversal path taken.

geez I thought I turned brainstorming mode off :D

cheers,
Jamie

```