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


Groups > sci.electronics.design > #407716

Re: PID Without a PhD, Finally

Newsgroups sci.electronics.design
Date 2016-04-15 12:41 -0700
References (1 earlier) <MPG.317afdaaa5058629897ee@172.16.0.1> <ner0vt$87l$1@dont-email.me> <xdGdnT0xP7CouIzKnZ2dnUU7-X-dnZ2d@giganews.com> <nerc75$lss$1@dont-email.me> <_p6dnZP74PYCpYzKnZ2dnUU7-QPNnZ2d@giganews.com>
Message-ID <5cbbd00a-15a3-4d89-bc54-fef5e7dbffc0@googlegroups.com> (permalink)
Subject Re: PID Without a PhD, Finally
From Lasse Langwadt Christensen <langwadt@fonz.dk>

Show all headers | View raw


Den fredag den 15. april 2016 kl. 20.53.25 UTC+2 skrev Tim Wescott:
> On Fri, 15 Apr 2016 20:37:34 +0200, David Brown wrote:
> 
> > On 15/04/16 19:30, Tim Wescott wrote:
> > <snip>
> >> 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!"
> > 
> > You might want to give that section a better title than "The Complete
> > Controller", with the program description "Here is the full text of the
> > PID controller code" :-)  Perhaps a big warning in red that this is
> > example code to get started.
> > 
> > 
> >> 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?
> >> 
> >> 
> > In a good many systems, double is not good enough either - it will be
> > too slow.  The developer needs to use some sort of scaled integers to
> > get 32 bits of precision (especially in the integrator), and may even
> > need to use 64-bit integer arithmetic for intermediary results.
> >
> > It would be nice if there were some equivalent to <stdint.h> that
> > defined types like float32_t and float64_t, but there isn't one.  There
> > are some macros in <float.h> defining aspects of floating point types,
> > but they are a bit ugly - and since you are always going to have 32-bit
> > IEEE floats and 64-bit IEEE doubles (unless your compiler cheats by
> > using 32-bit doubles, as you sometimes see on small micros), there is
> > nothing there worth checking.  If 32-bit IEEE is not good enough, just
> > write "double" - and make a note that it has to be a /real/ double, not
> > a non-standard 32-bit version.
> 
> I should make sure that the speed problems with double are pointed out -- 
> I think I mention it, but I may have been so totally focused on just 
> showing the implementation in the simplest way possible that I forget.
> 
> 32 bit fixed-point is more than adequate for nearly anything, although 
> you do sometimes have to take care with the integrator to make sure that 
> this holds up with real code.  If you need more, and you're not building 
> LIGO-III, then you may well be sampling horrendously faster than you need 
> to.
> 
> My preference if I'm doing a complicated control system is to use a 
> fractional arithmetic type, where the underlying storage is twos 
> compliment integers but the functional type has values that range from 
> almost -1 to almost +1.  You grab integer data, scale it to a fractional, 
> do all the control calculations in fractional, and then convert back to 
> integer to apply to a DAC or PWM generator or whatever.  Implementation 
> can be in either C or C++, although you can make more readable code with C
> ++.
> 
> I cover various data types (including ints, fractional, and the pitfalls 
> of floating point) in my book.  There's enough to fill a chapter.  You do 
> need to have a good understanding of what's happening to the data under 
> the hood if you're going to do controls or signal processing.
> 
> Which reminds me -- at some point I remember seeing that fractional 
> arithmetic was a suggested type for C, but I never kept track of whether 
> it went someplace useful or is a dead end.
> 

the ARM CMSIS DSP lib has Q15,Q31,Q63 formats

I'd think most fixed point DSPs uses a 1.xx format and the MUL-ACC handles 
the extra shift need for the muliplication 

-Lasse

Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web