Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #407563 > unrolled thread

PID Without a PhD, Finally

Started byTim Wescott <seemywebsite@myfooter.really>
First post2016-04-14 17:03 -0500
Last post2016-04-26 13:46 -0500
Articles 18 on this page of 98 — 31 participants

Back to article view | Back to sci.electronics.design


Contents

  PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-14 17:03 -0500
    Re: PID Without a PhD, Finally mrdarrett@gmail.com - 2016-04-14 15:09 -0700
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-14 17:47 -0500
    Re: PID Without a PhD, Finally mrdarrett@gmail.com - 2016-04-14 15:39 -0700
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-14 17:46 -0500
      Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-14 19:16 -0400
    Re: PID Without a PhD, Finally bitrex <bitrex@de.lete.earthlink.net> - 2016-04-14 19:00 -0400
    Re: PID Without a PhD, Finally DJ Delorie <dj@delorie.com> - 2016-04-14 19:09 -0400
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-14 18:25 -0500
      Re: PID Without a PhD, Finally DaveC <not@home.cow> - 2016-04-14 22:53 -0700
        Re: PID Without a PhD, Finally DJ Delorie <dj@delorie.com> - 2016-04-15 14:31 -0400
      Re: PID Without a PhD, Finally Tim Wescott <tim@seemywebsite.com> - 2016-04-15 15:02 -0500
        Re: PID Without a PhD, Finally Paul Rubin <no.email@nospam.invalid> - 2016-04-26 00:30 -0700
          Re: PID Without a PhD, Finally Andre Lodwig <lodwig@pathme.de> - 2016-04-26 09:45 +0200
          Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-26 12:08 -0500
            Re: PID Without a PhD, Finally George Herold <gherold@teachspin.com> - 2016-04-26 18:11 -0700
              Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-26 21:22 -0400
            Re: PID Without a PhD, Finally Les Cargill <lcargill99@comcast.com> - 2016-04-26 21:50 -0500
          Re: PID Without a PhD, Finally Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2016-04-26 19:34 -0400
          Re: PID Without a PhD, Finally Les Cargill <lcargill99@comcast.com> - 2016-04-26 21:39 -0500
      Re: PID Without a PhD, Finally John Larkin <jjlarkin@highlandtechnology.com> - 2016-04-26 17:07 -0700
        Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-26 20:50 -0400
          Re: PID Without a PhD, Finally Les Cargill <lcargill99@comcast.com> - 2016-04-26 21:57 -0500
        Re: PID Without a PhD, Finally Les Cargill <lcargill99@comcast.com> - 2016-04-26 21:45 -0500
          Re: PID Without a PhD, Finally John Larkin <jjlarkin@highlandtechnology.com> - 2016-04-27 10:16 -0700
            Re: PID Without a PhD, Finally Les Cargill <lcargill99@comcast.com> - 2016-04-28 22:02 -0500
    Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-14 19:11 -0400
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-14 18:41 -0500
        Re: PID Without a PhD, Finally mrdarrett@gmail.com - 2016-04-14 16:43 -0700
        Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-14 21:50 -0400
          Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-14 21:57 -0400
            Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-14 21:58 -0400
      Re: PID Without a PhD, Finally Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2016-04-15 12:28 +0300
        Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-15 11:29 -0400
          Re: PID Without a PhD, Finally Tim Wescott  <Tim@seemywebsite.com> - 2016-04-15 09:31 -0700
            Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:35 -0500
              Re: PID Without a PhD, Finally Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2016-04-15 14:04 -0400
                Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 13:11 -0500
                  Re: PID Without a PhD, Finally Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2016-04-15 14:32 -0400
            Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-15 13:51 -0400
              Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:57 -0500
                Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-15 18:12 -0400
    Re: PID Without a PhD, Finally Clifford Heath <no.spam@please.net> - 2016-04-15 03:37 +1000
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-14 19:12 -0500
        Re: PID Without a PhD, Finally Ralph Barone <ralph@invalid.com> - 2016-04-15 06:05 +0000
    Re: PID Without a PhD, Finally quiasmox@yahoo.com - 2016-04-14 20:10 -0500
      Re: PID Without a PhD, Finally Tim Wescott <tim@seemywebsite.com> - 2016-04-14 23:06 -0500
        Re: PID Without a PhD, Finally quiasmox@yahoo.com - 2016-04-14 23:46 -0500
        Re: PID Without a PhD, Finally Phil Hobbs <pcdhobbs@gmail.com> - 2016-04-15 00:42 -0700
    Re: PID Without a PhD, Finally o pere o <me@somewhere.net> - 2016-04-15 11:23 +0200
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:18 -0500
    Re: PID Without a PhD, Finally Peter Mairhofer <63832452@gmx.net> - 2016-04-15 03:46 -0700
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:19 -0500
    Re: PID Without a PhD, Finally Paul <paul@pcserviceselectronics.co.uk> - 2016-04-15 14:43 +0100
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:32 -0500
        Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-15 13:47 -0400
          Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 13:00 -0500
            Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-15 14:42 -0400
              Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 14:02 -0500
                Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-15 16:04 -0400
          Re: PID Without a PhD, Finally Jasen Betts <jasen@xnet.co.nz> - 2016-04-16 09:12 +0000
            Re: PID Without a PhD, Finally Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-04-16 13:35 +0200
            Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-16 12:34 -0400
              Re: PID Without a PhD, Finally Jasen Betts <jasen@xnet.co.nz> - 2016-04-17 08:12 +0000
        Re: PID Without a PhD, Finally Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-15 23:27 +0300
          Re: PID Without a PhD, Finally Clifford Heath <no.spam@please.net> - 2016-04-16 12:32 +1000
    Re: PID Without a PhD, Finally Paul <paul@pcserviceselectronics.co.uk> - 2016-04-15 14:31 +0100
      Re: PID Without a PhD, Finally Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2016-04-15 10:20 -0400
      Re: PID Without a PhD, Finally David Brown <david.brown@hesbynett.no> - 2016-04-15 17:25 +0200
        Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:30 -0500
          Re: PID Without a PhD, Finally rickman <gnuarm@gmail.com> - 2016-04-15 13:44 -0400
            Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:59 -0500
          Re: PID Without a PhD, Finally David Brown <david.brown@hesbynett.no> - 2016-04-15 20:37 +0200
            Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 13:53 -0500
              Re: PID Without a PhD, Finally Lasse Langwadt Christensen <langwadt@fonz.dk> - 2016-04-15 12:41 -0700
              Re: PID Without a PhD, Finally Dimiter_Popoff <dp@tgi-sci.com> - 2016-04-15 23:40 +0300
                Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 16:44 -0500
              Re: PID Without a PhD, Finally David Brown <david.brown@hesbynett.no> - 2016-04-16 18:16 +0200
          Re: PID Without a PhD, Finally Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2016-04-15 14:48 -0400
            Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 13:59 -0500
              Re: PID Without a PhD, Finally Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2016-04-15 16:23 -0400
              Re: PID Without a PhD, Finally Clifford Heath <no.spam@please.net> - 2016-04-16 12:41 +1000
              Re: PID Without a PhD, Finally David Brown <david.brown@hesbynett.no> - 2016-04-16 18:21 +0200
            Re: PID Without a PhD, Finally Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-04-15 21:19 +0200
              Re: PID Without a PhD, Finally Tim Wescott <tim@seemywebsite.com> - 2016-04-15 15:05 -0500
                Re: PID Without a PhD, Finally Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2016-04-15 16:18 -0400
                Re: PID Without a PhD, Finally Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-04-16 19:52 +0200
    Re: PID Without a PhD, Finally George Herold <gherold@teachspin.com> - 2016-04-15 10:18 -0700
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 12:41 -0500
        Re: PID Without a PhD, Finally Lasse Langwadt Christensen <langwadt@fonz.dk> - 2016-04-15 12:47 -0700
          Re: PID Without a PhD, Finally "Tim Williams" <tiwill@seventransistorlabs.com> - 2016-04-16 16:17 -0500
        Re: PID Without a PhD, Finally George Herold <gherold@teachspin.com> - 2016-04-15 17:55 -0700
    Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-15 19:38 -0500
    Re: PID Without a PhD, Finally John S <Sophi.2@invalid.org> - 2016-04-15 22:02 -0500
    Re: PID Without a PhD, Finally Christian Gollwitzer <auriocus@gmx.de> - 2016-04-16 09:25 +0200
    Re: PID Without a PhD, Finally OG <AIEO@AIOESPAM.COM> - 2016-04-17 10:12 -0700
    Re: PID Without a PhD, Finally John Larkin <jjlarkin@highlandtechnology.com> - 2016-04-26 11:12 -0700
      Re: PID Without a PhD, Finally Tim Wescott <seemywebsite@myfooter.really> - 2016-04-26 13:46 -0500

Page 5 of 5 — ← Prev page 1 2 3 4 [5]


#407730

FromPhil Hobbs <pcdhSpamMeSenseless@electrooptical.net>
Date2016-04-15 16:23 -0400
Message-ID<57114DAF.7050200@electrooptical.net>
In reply to#407706
On 04/15/2016 02:59 PM, Tim Wescott wrote:
> On Fri, 15 Apr 2016 14:48:03 -0400, Phil Hobbs wrote:
> 
>> On 04/15/2016 01:30 PM, Tim Wescott wrote:
>>> On Fri, 15 Apr 2016 17:25:58 +0200, David Brown wrote:
>>>
>>>> On 15/04/16 15:31, Paul wrote:
>>>>> In article <wpydnbi9wr9Ujo3KnZ2dnUU7-WXNnZ2d@giganews.com>,
>>>>> seemywebsite@myfooter.really says...
>>>>>>
>>>>>> Embedded Systems Design (or whatever they call themselves) kept
>>>>>> moving this around -- so I've revamped it, updated it, and posted it
>>>>>> on the web.
>>>>>>
>>>>>> Take a gander.  Please comment on anything you like/don't like.  I'm
>>>>>> not sure if the way that I'm setting off the math is a Really Good
>>>>>> Idea or a Really Bad Idea -- I'm trying to make it easy for the
>>>>>> math-averse to skip over it, without breaking up the flow too much
>>>>>> for folks who can read math without breaking stride.
>>>>>>
>>>>>> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf
>>>>>
>>>>> Well in general good other comments people have stated I would add
>>>>> these points -
>>>>>
>>>>> 1/ Code layout on page 14 of the integral state is UGLY, belongs in
>>>>>    obfuscated C better laid out out that is easier to read at a
>>>>>    glance is better for those trying to understand.
>>>>>
>>>>>
>>>> I would not have said it was obfuscated - but it certainly could be a
>>>> little better (as could the code on page 22).  So far, I have only
>>>> looked at the style of the code - I haven't actually looked at the
>>>> details to see what it does, nor have I had time to read the whole
>>>> paper.  Hopefully I will do so some time - but perhaps by then there
>>>> will be a second version from feedback from others in this thread!
>>>>
>>>> As this code is for embedded systems, it should be written in a manner
>>>> close to that used in common embedded coding standards such as MISRA.
>>>> Here are some points here that I think would make the code clearer, as
>>>> well as more compatible with things like MISRA, and more suitable for
>>>> flexible use in embedded systems:
>>>>
>>>> 1. MISRA does not approve of native types such as "double", because
>>>> the precision is implementation defined and can vary between C
>>>> compilers and targets.  I agree with that regarding integers (so use
>>>> <stdint.h> types rather than "int" or "short"), but the use of 32-bit
>>>> and 64-bit IEEE formats for "float" and "double" is so close to
>>>> universal that I think it is unnecessary.  However, many people using
>>>> code like this will want to use "float" for speed, while others will
>>>> want "double" for precision.
>>>>  I would recommend starting the code with:
>>>>
>>>> typedef double real_t;    // Use "float" or "double" as desired
>>>>
>>>> Then use "real_t" throughout, instead of "double".
>>>>
>>>> (It may be interesting to have a small section discussing the merits
>>>> of these options - on something like a Cortex-M4F with hardware
>>>> single-precision floating point, the speed difference could easily be
>>>> a factor of 100.  It may even be worth mentioning things like compiler
>>>> flags - while most people know about basic optimisation flags, they
>>>> may not know the huge difference "-ffast-math" can have on code like
>>>> this. You may also want to discuss using integers instead of floating
>>>> point, especially considering errors, scaling, rounding, and
>>>> overflows.)
>>>>
>>>>
>>>> 2. Do not give identifiers names such as "dState" and "iState".  There
>>>> are, unfortunately, a good many programmers who have totally
>>>> misunderstood the point of "Hungarian notation" and will think that
>>>> these mean a variable "state" with type "double", and another variable
>>>> "state" with type "int".
>>>>
>>>> 3. Do not give identifiers names that are almost the same.  Do not
>>>> abbreviate the important part of the name (the "differential" or
>>>> "integrator" part) to a single letter.  It's fine to have shorter
>>>> names for local variables within a function, but names that are
>>>> visible over a wider range (such as the struct fields) should be
>>>> self-explanatory.
>>>>
>>>> 4. If you need a comment to tell you what an identifier is, then the
>>>> identifier name is bad.  It is the identifier's name that says what it
>>>> is - a comment may be used to add extra information such as scaling,
>>>> or when it is used.
>>>>
>>>> 5. Always use the "one true brace" style.  Every "if" and "else"
>>>> should have brackets.
>>>>
>>>> 6. Do not declare more than one identifier in the same declaration.
>>>>
>>>> 7. Even the most conservative and backwards development companies have
>>>> heard of C99.  Declare your variables when you need them, in the
>>>> smallest reasonable scope.
>>>>
>>>> Full marks for good character spacing!
>>>>
>>>>
>>>> typedef double real_t;    // Use "float" or "double" as desired
>>>>
>>>> typedef struct {
>>>>     real_t lastPosition;
>>>>     real_t integrator;
>>>>     real_t integratorLimitMax;
>>>>     real_t integratorLimitMin;
>>>>     real_t integralGain;
>>>>     real_t proportionalGain;
>>>>     real_t derivativeGain;
>>>> } pid_s;
>>>>
>>>> real_t updatePID(pid_s * pid, real_t error, real_t position) {
>>>>     // The "P" part real_t pTerm = pid->proportionalGain * error;
>>>>
>>>>     // The "I" part pid->integrator += error;
>>>>     if (pid->integrator > pid->integratorLimitMax) {
>>>>         pid->integrator = pid->integratorLimitMax;
>>>>     } else if (pid->integrator < pid->integratorLimitMin) {
>>>>         pid->integrator = pid->integratorLimitMin;
>>>>     }
>>>>     real_t iTerm = pid->integratorGain * pid->integrator;
>>>>
>>>>     // The "D" part real_t dTerm = pid->derivativeGain *
>>>>     (pid->lastPosition - position);
>>>>     pid->lastPosition = position;
>>>>
>>>>     // Combined PID result return pTerm + iTerm + dTerm;
>>>> }
>>>>
>>>>
>>>> Note that almost no comments are needed - the functionality is clear
>>>> from the names used in the code.
>>>>
>>>>
>>>>
>>>> Regarding the typesetting, I recommend using the "listings" package
>>>> rather than just a verbatim environment:
>>>>
>>>> <https://www.ctan.org/pkg/listings>
>>>> <https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings>
>>>>
>>>> The setup I use for C code is something like this:
>>>>
>>>> \lstset{
>>>>   language=C,
>>>>   formfeed=\newpage,
>>>>   tabsize=4,
>>>>   basicstyle=\small,
>>>>   numbers=left,
>>>>   numberstyle=\tiny,
>>>>   firstnumber=1,
>>>>   numberfirstline=true,
>>>>   stepnumber=5,
>>>>   numbersep=5pt,
>>>>   extendedchars=true, showstringspaces=false, breakatwhitespace=false,
>>>>   identifierstyle=\color{Black}\itshape,
>>>>   commentstyle=\color{Gray}\itshape, stringstyle=\color{Green}
>>>> }
>>>>
>>>> (I vary it a little according to the document in question, but this is
>>>> probably fine to get you started.)
>>>
>>> Hi David:
>>>
>>> Thank you for your pertinent comments.  I think I'll apply most of
>>> them. The only scary part of your comments are the "if someone uses the
>>> code" -- I originally meant this code to be for illustrative purposes
>>> only, not for use in production systems.  My assumption was that people
>>> would read the article, grok the material, then go off and write code
>>> from scratch.
>>>
>>> Thus, the first time I got feedback along the lines of "we copied your
>>> code into our production software and it works GREAT!" my response was
>>>
>>> "WHAT!?!  NOOOO!"
>>>
>>> So I would be tempted to take your real_t and change it to
>>> do_not_use_this_for_real_t.
>>>
>>> I have a question, since you brought it up and since I'm lazy.  In many
>>> control systems, 32-bit IEEE floating point is inadequate, because a 24
>>> bit significand just doesn't cut it.  So the choice of double, with its
>>> bigger significand, is usually necessary.
>>>
>>> Is there a better way to express the "you damned well need 'double'
>>> here,
>>> bub" in code than just using "double", or a comment to that effect?
>>>
>>>
>> assert(sizeof(real_t) >= 8);
>>
>> Cheers
>>
>> Phil Hobbs
> 
> That would give a false alarm on some DSP chips, because sizeof returns 
> the number of characters your variable or type fits into, and if the 
> processor can't handle data in chunks as small as 8 bits a character is 
> bigger (usually 16 or 24, but I believe that it was 32 or 64 in some Cray 
> machines).
> 
> Fortunately, in a compliant compiler this is captured in CHAR_BIT:
> 
> assert(sizeof(real_t) * CHAR_BIT >= 64)
> 
> I oversaw the introduction of the TMS320F2812 into a product line where 
> we had code that had worked for YEARS, which broke because of the 
> implicit assumption that the number of bits in a character was 8.
> 

http://tinyurl.com/gpyb3kh

;)

Cheers

Phil Hobbs

-- 
Dr Philip C D Hobbs
Principal Consultant
ElectroOptical Innovations LLC
Optics, Electro-optics, Photonics, Analog Electronics

160 North State Road #203
Briarcliff Manor NY 10510

hobbs at electrooptical dot net
http://electrooptical.net

[toc] | [prev] | [next] | [standalone]


#407774

FromClifford Heath <no.spam@please.net>
Date2016-04-16 12:41 +1000
Message-ID<5711a693$0$15700$c3e8da3$9deca2c3@news.astraweb.com>
In reply to#407706
On 16/04/16 04:59, Tim Wescott wrote:
> On Fri, 15 Apr 2016 14:48:03 -0400, Phil Hobbs wrote:
>> assert(sizeof(real_t) >= 8);
>> Phil Hobbs
> That would give a false alarm on some DSP chips, because sizeof returns
> the number of characters your variable or type fits into, and if the
> processor can't handle data in chunks as small as 8 bits a character is
> bigger (usually 16 or 24, but I believe that it was 32 or 64 in some Cray
> machines).

A port of C to the Control Data CDC Cyber used the entire 60-bit word
for a character. I thought it was terribly wasteful at the time, but
now it's obvious that if you were stupid enough to want to write a
word processor for one, you'd write code that packed 10 6-bit chars
into a word solely for bulk text.

Clifford Heath.

[toc] | [prev] | [next] | [standalone]


#407827

FromDavid Brown <david.brown@hesbynett.no>
Date2016-04-16 18:21 +0200
Message-ID<netojl$v6p$1@dont-email.me>
In reply to#407706
On 15/04/16 20:59, Tim Wescott wrote:
> On Fri, 15 Apr 2016 14:48:03 -0400, Phil Hobbs wrote:
>
>> On 04/15/2016 01:30 PM, Tim Wescott wrote:

>>>
>>> Is there a better way to express the "you damned well need 'double'
>>> here,
>>> bub" in code than just using "double", or a comment to that effect?
>>>
>>>
>> assert(sizeof(real_t) >= 8);
>>
>> Cheers
>>
>> Phil Hobbs
>
> That would give a false alarm on some DSP chips, because sizeof returns
> the number of characters your variable or type fits into, and if the
> processor can't handle data in chunks as small as 8 bits a character is
> bigger (usually 16 or 24, but I believe that it was 32 or 64 in some Cray
> machines).
>
> Fortunately, in a compliant compiler this is captured in CHAR_BIT:
>
> assert(sizeof(real_t) * CHAR_BIT >= 64)
>
> I oversaw the introduction of the TMS320F2812 into a product line where
> we had code that had worked for YEARS, which broke because of the
> implicit assumption that the number of bits in a character was 8.
>

I'd still suggest that if 32-bit IEEE is not enough, then just use 
"double".  After all, how many systems are there where "float" is big 
enough (say, 32 bits of significand) but where "double" would not be 
suitable?

Anyway, if you want to do a check on something like this, you don't use 
"assert" - use a static assertion:

static_assert(sizeof(real_t) * CHAR_BIT >= 64);

(This is the main reason for using C11.  And if you don't have C11, a 
static assertion macro is easy to make, even if the error messages are 
ugly.)

[toc] | [prev] | [next] | [standalone]


#407712

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2016-04-15 21:19 +0200
Message-ID<dnct5tF9djgU1@mid.dfncis.de>
In reply to#407704
Am 15.04.2016 um 20:48 schrieb Phil Hobbs:

> assert(sizeof(real_t) >= 8);

That won't actually work reliably.  Remember that sizeof's result is in 
"bytes", as in: whatever size "unsigned char" is on the target platform. 
  Which might be bigger than the usual 8 bits, particularly on DSPs. 
Not all the world's a VAX, and a byte is not 8 bits everywhere.

So if your goal is to insist on a 64-bit floating-point 'real_t', you'll 
really have to say

	assert((sizeof(real_t) * CHAR_BIT) >= 64u);

and maybe, while at it, also make sure it's a floating-point type:

	assert(0 != (real_t)0.1);

And for good measure, better make those static_assert()s so they trigger 
at compile time, instead of trying to abort at run time with a 
message--- which in an embedded system often has nowhere to go.

[toc] | [prev] | [next] | [standalone]


#407724

FromTim Wescott <tim@seemywebsite.com>
Date2016-04-15 15:05 -0500
Message-ID<KOqdnfwqBb_h1IzKnZ2dnUU7-UWdnZ2d@giganews.com>
In reply to#407712
On Fri, 15 Apr 2016 21:19:50 +0200, Hans-Bernhard Bröker wrote:

> Am 15.04.2016 um 20:48 schrieb Phil Hobbs:
> 
>> assert(sizeof(real_t) >= 8);
> 
> That won't actually work reliably.  Remember that sizeof's result is in
> "bytes", as in: whatever size "unsigned char" is on the target platform.
>   Which might be bigger than the usual 8 bits, particularly on DSPs.
> Not all the world's a VAX, and a byte is not 8 bits everywhere.
> 
> So if your goal is to insist on a 64-bit floating-point 'real_t', you'll
> really have to say
> 
> 	assert((sizeof(real_t) * CHAR_BIT) >= 64u);
> 
> and maybe, while at it, also make sure it's a floating-point type:
> 
> 	assert(0 != (real_t)0.1);
> 
> And for good measure, better make those static_assert()s so they trigger
> at compile time, instead of trying to abort at run time with a
> message--- which in an embedded system often has nowhere to go.

Most of my embedded systems will at least make a light blink oddly when 
you hit an assert -- but that's not a Good Thing normally.

-- 
www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#407727

FromPhil Hobbs <pcdhSpamMeSenseless@electrooptical.net>
Date2016-04-15 16:18 -0400
Message-ID<laOdneOmguAH0YzKnZ2dnUU7-eGdnZ2d@supernews.com>
In reply to#407724
On 04/15/2016 04:05 PM, Tim Wescott wrote:
> On Fri, 15 Apr 2016 21:19:50 +0200, Hans-Bernhard Bröker wrote:
> 
>> Am 15.04.2016 um 20:48 schrieb Phil Hobbs:
>>
>>> assert(sizeof(real_t) >= 8);
>>
>> That won't actually work reliably.  Remember that sizeof's result is in
>> "bytes", as in: whatever size "unsigned char" is on the target platform.
>>   Which might be bigger than the usual 8 bits, particularly on DSPs.
>> Not all the world's a VAX, and a byte is not 8 bits everywhere.
>>
>> So if your goal is to insist on a 64-bit floating-point 'real_t', you'll
>> really have to say
>>
>> 	assert((sizeof(real_t) * CHAR_BIT) >= 64u);
>>
>> and maybe, while at it, also make sure it's a floating-point type:
>>
>> 	assert(0 != (real_t)0.1);
>>
>> And for good measure, better make those static_assert()s so they trigger
>> at compile time, instead of trying to abort at run time with a
>> message--- which in an embedded system often has nowhere to go.
> 
> Most of my embedded systems will at least make a light blink oddly when 
> you hit an assert -- but that's not a Good Thing normally.
> 

Well, I'm of the old school, where you define NDEBUG in your production
code, rather than using assert() as a shorthand for fatal runtime errors.

Cheers

Phil Hobbs

-- 
Dr Philip C D Hobbs
Principal Consultant
ElectroOptical Innovations LLC
Optics, Electro-optics, Photonics, Analog Electronics

160 North State Road #203
Briarcliff Manor NY 10510

hobbs at electrooptical dot net
http://electrooptical.net

[toc] | [prev] | [next] | [standalone]


#407835

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2016-04-16 19:52 +0200
Message-ID<dnfcdoFs3msU1@mid.dfncis.de>
In reply to#407724
Am 15.04.2016 um 22:05 schrieb Tim Wescott:
> On Fri, 15 Apr 2016 21:19:50 +0200, Hans-Bernhard Bröker wrote:

>> And for good measure, better make those static_assert()s so they trigger
>> at compile time, instead of trying to abort at run time with a
>> message--- which in an embedded system often has nowhere to go.

> Most of my embedded systems will at least make a light blink oddly when
> you hit an assert -- but that's not a Good Thing normally.

Which is why a static_assert() is so strongly preferable over assert(), 
wherever applicable: instead of trying to figure out which of your 
assert()s might have triggered the panic LED at run time (invariably at 
a customer site, 9 time zones away through heavy weather), you get a 
message at compile time, right there in the coziness of your place of work.

static_assert() solves most of the perceived problems that drive people 
to demand the C preprocessor should know about things like sizeof().

[toc] | [prev] | [next] | [standalone]


#407673

FromGeorge Herold <gherold@teachspin.com>
Date2016-04-15 10:18 -0700
Message-ID<fc659bae-1e59-468a-a7e7-87bc95eb3edb@googlegroups.com>
In reply to#407563
On Thursday, April 14, 2016 at 6:04:00 PM UTC-4, Tim Wescott wrote:
> Embedded Systems Design (or whatever they call themselves) kept moving 
> this around -- so I've revamped it, updated it, and posted it on the web.
> 
> Take a gander.  Please comment on anything you like/don't like.  I'm not 
> sure if the way that I'm setting off the math is a Really Good Idea or a 
> Really Bad Idea -- I'm trying to make it easy for the math-averse to skip 
> over it, without breaking up the flow too much for folks who can read 
> math without breaking stride.
> 
> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf

I haven't read it all, yet.  (I think I've seen this before?  on your website?) 

Anyway I just wanted to ask about figure 2.  
I've always put the D block in parallel with the P and I block... all after 
you generate the error signal.  (and gain that up.)  Is there a reason/ advantage 
etc. for putting it where you've drawn it?  

Do you talk at all in the paper (or your book) about the P-term in dotted outline
that you've got as "negative feedback around the plant".  (Well I don't see a 
sign designation for where that goes into the summing block.  I assume
it's negative.) 

I'm going to try that on my next PID thermal project.  (Hopefully next week.. assuming no more new fires to put out.) 

George H.  
> 
> -- 
> 
> Tim Wescott
> Wescott Design Services
> http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#407678

FromTim Wescott <seemywebsite@myfooter.really>
Date2016-04-15 12:41 -0500
Message-ID<xdGdnT4xP7BYuozKnZ2dnUU7-X-dnZ2d@giganews.com>
In reply to#407673
On Fri, 15 Apr 2016 10:18:51 -0700, George Herold wrote:

> On Thursday, April 14, 2016 at 6:04:00 PM UTC-4, Tim Wescott wrote:
>> Embedded Systems Design (or whatever they call themselves) kept moving
>> this around -- so I've revamped it, updated it, and posted it on the
>> web.
>> 
>> Take a gander.  Please comment on anything you like/don't like.  I'm
>> not sure if the way that I'm setting off the math is a Really Good Idea
>> or a Really Bad Idea -- I'm trying to make it easy for the math-averse
>> to skip over it, without breaking up the flow too much for folks who
>> can read math without breaking stride.
>> 
>> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf
> 
> I haven't read it all, yet.  (I think I've seen this before?  on your
> website?)

Yes.  It's posted somewhere on the CMP (Embedded Systems Design) website, 
but they keep moving it around.  I decided I needed to bring it home.

> Anyway I just wanted to ask about figure 2.
> I've always put the D block in parallel with the P and I block... all
> after you generate the error signal.  (and gain that up.)  Is there a
> reason/ advantage etc. for putting it where you've drawn it?
> 
> Do you talk at all in the paper (or your book) about the P-term in
> dotted outline that you've got as "negative feedback around the plant". 
> (Well I don't see a sign designation for where that goes into the
> summing block.  I assume it's negative.)
> 
> I'm going to try that on my next PID thermal project.  (Hopefully next
> week.. assuming no more new fires to put out.)

Yes, I talk about it in my book.  I _hope_ I mention it in the paper 
beyond what I said in the title.

Moving the blocks around changes how the thing responds to input, without 
changing how it responds to disturbances.  If having the absolute fastest 
response to a step input isn't important, but having less overshoot, or 
driving the plant less hard, etc., _is_ important, then moving the 
derivative (and maybe the proportional) blocks out of the feed-forward 
path is a Good Thing.

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#407718

FromLasse Langwadt Christensen <langwadt@fonz.dk>
Date2016-04-15 12:47 -0700
Message-ID<2938cd8f-4b80-40be-bc17-db670c9f5f1f@googlegroups.com>
In reply to#407678
Den fredag den 15. april 2016 kl. 19.41.29 UTC+2 skrev Tim Wescott:
> On Fri, 15 Apr 2016 10:18:51 -0700, George Herold wrote:
> 
> > On Thursday, April 14, 2016 at 6:04:00 PM UTC-4, Tim Wescott wrote:
> >> Embedded Systems Design (or whatever they call themselves) kept moving
> >> this around -- so I've revamped it, updated it, and posted it on the
> >> web.
> >> 
> >> Take a gander.  Please comment on anything you like/don't like.  I'm
> >> not sure if the way that I'm setting off the math is a Really Good Idea
> >> or a Really Bad Idea -- I'm trying to make it easy for the math-averse
> >> to skip over it, without breaking up the flow too much for folks who
> >> can read math without breaking stride.
> >> 
> >> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf
> > 
> > I haven't read it all, yet.  (I think I've seen this before?  on your
> > website?)
> 
> Yes.  It's posted somewhere on the CMP (Embedded Systems Design) website, 
> but they keep moving it around.  I decided I needed to bring it home.
> 
> > Anyway I just wanted to ask about figure 2.
> > I've always put the D block in parallel with the P and I block... all
> > after you generate the error signal.  (and gain that up.)  Is there a
> > reason/ advantage etc. for putting it where you've drawn it?
> > 
> > Do you talk at all in the paper (or your book) about the P-term in
> > dotted outline that you've got as "negative feedback around the plant". 
> > (Well I don't see a sign designation for where that goes into the
> > summing block.  I assume it's negative.)
> > 
> > I'm going to try that on my next PID thermal project.  (Hopefully next
> > week.. assuming no more new fires to put out.)
> 
> Yes, I talk about it in my book.  I _hope_ I mention it in the paper 
> beyond what I said in the title.
> 
> Moving the blocks around changes how the thing responds to input, without 
> changing how it responds to disturbances.  If having the absolute fastest 
> response to a step input isn't important, but having less overshoot, or 
> driving the plant less hard, etc., _is_ important, then moving the 
> derivative (and maybe the proportional) blocks out of the feed-forward 
> path is a Good Thing.
> 

a friend of mine builds aftermarket ECUs, when throttle by wire came 
along adding a cruise control came natural and it worked perfectly. 
but, hitting resume at low speed in a low gear was "interesting" :)

was fixed by adding a slew rate limit on the set point

-Lasse 



-Lasse

[toc] | [prev] | [next] | [standalone]


#407861

From"Tim Williams" <tiwill@seventransistorlabs.com>
Date2016-04-16 16:17 -0500
Message-ID<neu9v7$8ll$1@dont-email.me>
In reply to#407718
"Lasse Langwadt Christensen" <langwadt@fonz.dk> wrote in message 
news:2938cd8f-4b80-40be-bc17-db670c9f5f1f@googlegroups.com...
> a friend of mine builds aftermarket ECUs, when throttle by wire came
> along adding a cruise control came natural and it worked perfectly.
> but, hitting resume at low speed in a low gear was "interesting" :)
>
> was fixed by adding a slew rate limit on the set point

IIRC my car disables cruise below 30 MPH or so, anyway.

Tim

-- 
Seven Transistor Labs, LLC
Electrical Engineering Consultation and Contract Design
Website: http://seventransistorlabs.com 

[toc] | [prev] | [next] | [standalone]


#407761

FromGeorge Herold <gherold@teachspin.com>
Date2016-04-15 17:55 -0700
Message-ID<e8f4e550-f5ce-444a-8eda-d49b4a008ae8@googlegroups.com>
In reply to#407678
On Friday, April 15, 2016 at 1:41:29 PM UTC-4, Tim Wescott wrote:
> On Fri, 15 Apr 2016 10:18:51 -0700, George Herold wrote:
> 
> > On Thursday, April 14, 2016 at 6:04:00 PM UTC-4, Tim Wescott wrote:
> >> Embedded Systems Design (or whatever they call themselves) kept moving
> >> this around -- so I've revamped it, updated it, and posted it on the
> >> web.
> >> 
> >> Take a gander.  Please comment on anything you like/don't like.  I'm
> >> not sure if the way that I'm setting off the math is a Really Good Idea
> >> or a Really Bad Idea -- I'm trying to make it easy for the math-averse
> >> to skip over it, without breaking up the flow too much for folks who
> >> can read math without breaking stride.
> >> 
> >> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf
> > 
> > I haven't read it all, yet.  (I think I've seen this before?  on your
> > website?)
> 
> Yes.  It's posted somewhere on the CMP (Embedded Systems Design) website, 
> but they keep moving it around.  I decided I needed to bring it home.
> 
> > Anyway I just wanted to ask about figure 2.
> > I've always put the D block in parallel with the P and I block... all
> > after you generate the error signal.  (and gain that up.)  Is there a
> > reason/ advantage etc. for putting it where you've drawn it?
> > 
> > Do you talk at all in the paper (or your book) about the P-term in
> > dotted outline that you've got as "negative feedback around the plant". 
> > (Well I don't see a sign designation for where that goes into the
> > summing block.  I assume it's negative.)
> > 
> > I'm going to try that on my next PID thermal project.  (Hopefully next
> > week.. assuming no more new fires to put out.)
> 
> Yes, I talk about it in my book.  I _hope_ I mention it in the paper 
> beyond what I said in the title.
> 
> Moving the blocks around changes how the thing responds to input, without 
> changing how it responds to disturbances.  If having the absolute fastest 
> response to a step input isn't important, but having less overshoot, or 
> driving the plant less hard, etc., _is_ important, then moving the 
> derivative (and maybe the proportional) blocks out of the feed-forward 
> path is a Good Thing.

When I tried moving the proportional block (in analog land) I found 
I had to move the gain till after the P mixing stage,
rather than right into the error signal.
(and think more about noise in the integrator.)

George H. 


> 
> -- 
> 
> Tim Wescott
> Wescott Design Services
> http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#407759

FromTim Wescott <seemywebsite@myfooter.really>
Date2016-04-15 19:38 -0500
Message-ID<Jfudnc6Tw4EbFIzKnZ2dnUU7-W-dnZ2d@giganews.com>
In reply to#407563
On Thu, 14 Apr 2016 17:03:53 -0500, Tim Wescott wrote:

> Embedded Systems Design (or whatever they call themselves) kept moving
> this around -- so I've revamped it, updated it, and posted it on the
> web.
> 
> Take a gander.  Please comment on anything you like/don't like.  I'm not
> sure if the way that I'm setting off the math is a Really Good Idea or a
> Really Bad Idea -- I'm trying to make it easy for the math-averse to
> skip over it, without breaking up the flow too much for folks who can
> read math without breaking stride.
> 
> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf

I want to thank all who have commented.  I've incorporated some of your 
suggestions, allowed other suggestions to color what I've done, and 
chosen not to implement others.

But all of your suggestions were considered, and I'm grateful for your 
help.

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#407779

FromJohn S <Sophi.2@invalid.org>
Date2016-04-15 22:02 -0500
Message-ID<nes9o4$4bc$1@dont-email.me>
In reply to#407563
On 4/14/2016 5:03 PM, Tim Wescott wrote:
> Embedded Systems Design (or whatever they call themselves) kept moving
> this around -- so I've revamped it, updated it, and posted it on the web.
>
> Take a gander.  Please comment on anything you like/don't like.  I'm not
> sure if the way that I'm setting off the math is a Really Good Idea or a
> Really Bad Idea -- I'm trying to make it easy for the math-averse to skip
> over it, without breaking up the flow too much for folks who can read
> math without breaking stride.
>
> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf
>

A very tiny nit in the opening sentences:

"I both consult and teach in the area of digital control. Through both 
of these efforts..."

May I suggest:

I consult and teach in the area of digital control. Through these efforts...

[toc] | [prev] | [next] | [standalone]


#407786

FromChristian Gollwitzer <auriocus@gmx.de>
Date2016-04-16 09:25 +0200
Message-ID<nesp6e$qvo$1@dont-email.me>
In reply to#407563
Am 15.04.16 um 00:03 schrieb Tim Wescott:
> Embedded Systems Design (or whatever they call themselves) kept moving
> this around -- so I've revamped it, updated it, and posted it on the web.
>
> Take a gander.  Please comment on anything you like/don't like.  I'm not
> sure if the way that I'm setting off the math is a Really Good Idea or a
> Really Bad Idea -- I'm trying to make it easy for the math-averse to skip
> over it, without breaking up the flow too much for folks who can read
> math without breaking stride.
>
> http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf
>


I've had a cursory look. I'm a physicist myself with only basic 
knowledge of PID control, so for me the math boxes were helpful. You did 
not define all variables there, particularly the dependent variables. In 
equation (1), I wondered whether theta_m is the angle or angular 
velocity of the motor. That t is time seems fairly obvious, but I'd put 
both in for clarification. Same for equation (2).

Your plots need some typographical adjustment. The lines are too thin 
and the fonts are too small. I would also put the variables  on the 
axis, i.e. "Time t in seconds" etc.

The complete controller is a short function which fits in one page. 
Maybe it is better to put it at the beginning, giving different colours 
to the proportinal, integral and derivative term, and then explain it. 
While reading the code snippets, I was wondering what are the fields in 
the pid structure etc.

For some reason, I find the code on paper quite hard to read. Maybe it's 
the syntax highlighting that I'm used to when reading on the screen. You 
can do some basic highlighting using the listings package to improve on 
that.

	Christian

[toc] | [prev] | [next] | [standalone]


#407901

FromOG <AIEO@AIOESPAM.COM>
Date2016-04-17 10:12 -0700
Message-ID<nf0g71$1au8$1@gioia.aioe.org>
In reply to#407563
Thank you so much.  I will learn something I never knew much about.

Back in 1966 when I was finishing up my BSEE I missed the servo class.
Never needed it as my career had me doing analog, digital and software 
design.  Design from the component, module subsystem and system design.
I loved following my designs from drawing through manufacturing and 
integration, test and installation.
I have multi-million dollar systems in the field right now.
But now retired (in 2008) and listening to the scuttlebutt.

My college change my degree a few years back from BSEE to BS Electronics 
and Computers which is actually more accurate.

I was in on the beginnings of the microprocessor, had an Altair and 
designed hardware interfaces for it and wrote software in C and assembly 
including modifying CP/M OS for the hardware interfaces.

Thanks for bringing back great memories!

[toc] | [prev] | [next] | [standalone]


#409340

FromJohn Larkin <jjlarkin@highlandtechnology.com>
Date2016-04-26 11:12 -0700
Message-ID<4gbvhbteprj07ftj30jcqaodp900jv7kr6@4ax.com>
In reply to#407563


On Thu, 14 Apr 2016 17:03:53 -0500, Tim Wescott
<seemywebsite@myfooter.really> wrote:

>Embedded Systems Design (or whatever they call themselves) kept moving 
>this around -- so I've revamped it, updated it, and posted it on the web.
>
>Take a gander.  Please comment on anything you like/don't like.  I'm not 
>sure if the way that I'm setting off the math is a Really Good Idea or a 
>Really Bad Idea -- I'm trying to make it easy for the math-averse to skip 
>over it, without breaking up the flow too much for folks who can read 
>math without breaking stride.
>
>http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf

I think that PID control originated in the pneumatic controller days,
before there were many (or any) PhDs in control theory. One story that
I read suggests that the derivative term was discovered accidentally,
the result of a leaky bellows or something.

I designed a state-of-the-art digital boiler/throttle control system
for the Navy's LHA helicopter assault ships. The Navy couldn't
maintain it so they ripped it out and substituted pneumatics.


-- 

John Larkin         Highland Technology, Inc
picosecond timing   precision measurement 

jlarkin att highlandtechnology dott com
http://www.highlandtechnology.com

[toc] | [prev] | [next] | [standalone]


#409343

FromTim Wescott <seemywebsite@myfooter.really>
Date2016-04-26 13:46 -0500
Message-ID<-cydnXJuLrPwKoLKnZ2dnUU7-c-dnZ2d@giganews.com>
In reply to#409340
On Tue, 26 Apr 2016 11:12:45 -0700, John Larkin wrote:

> On Thu, 14 Apr 2016 17:03:53 -0500, Tim Wescott
> <seemywebsite@myfooter.really> wrote:
> 
>>Embedded Systems Design (or whatever they call themselves) kept moving
>>this around -- so I've revamped it, updated it, and posted it on the
>>web.
>>
>>Take a gander.  Please comment on anything you like/don't like.  I'm not
>>sure if the way that I'm setting off the math is a Really Good Idea or a
>>Really Bad Idea -- I'm trying to make it easy for the math-averse to
>>skip over it, without breaking up the flow too much for folks who can
>>read math without breaking stride.
>>
>>http://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf
> 
> I think that PID control originated in the pneumatic controller days,
> before there were many (or any) PhDs in control theory. One story that I
> read suggests that the derivative term was discovered accidentally, the
> result of a leaky bellows or something.
> 
> I designed a state-of-the-art digital boiler/throttle control system for
> the Navy's LHA helicopter assault ships. The Navy couldn't maintain it
> so they ripped it out and substituted pneumatics.

PID -- or at least PI -- control has been around longer than that: 
http://rspl.royalsocietypublishing.org/content/16/270.full.pdf+html

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [prev] | [standalone]


Page 5 of 5 — ← Prev page 1 2 3 4 [5]

Back to top | Article view | sci.electronics.design


csiph-web