Welcome
Username or Email:

Password:


Missing Code




[ ]
[ ]
Online
  • Guests: 90
  • Members: 0
  • Newest Member: omjtest
  • Most ever online: 396
    Guests: 396, Members: 0 on 12 Jan : 12:51
Members Birthdays:
All today's birthdays', congrats!
dan (37)
rchydro (64)
CapRack (30)


Next birthdays
11/07 Dave Marshall (40)
11/07 Worms (46)
11/08 Bert (77)
Contact
If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.


Special Thanks To:
  • Aaron Holmes
  • Aaron Wheeler
  • Adam Horden
  • Alan Scrimgeour
  • Andre
  • Andrew Haynes
  • Anonymous000
  • asabase
  • Austin Weil
  • barney
  • Barry
  • Bert Hickman
  • Bill Kukowski
  • Blitzorn
  • Brandon Paradelas
  • Bruce Bowling
  • BubeeMike
  • Byong Park
  • Cesiumsponge
  • Chris F.
  • Chris Hooper
  • Corey Worthington
  • Derek Woodroffe
  • Dalus
  • Dan Strother
  • Daniel Davis
  • Daniel Uhrenholt
  • datasheetarchive
  • Dave Billington
  • Dave Marshall
  • David F.
  • Dennis Rogers
  • drelectrix
  • Dr. John Gudenas
  • Dr. Spark
  • E.TexasTesla
  • eastvoltresearch
  • Eirik Taylor
  • Erik Dyakov
  • Erlend^SE
  • Finn Hammer
  • Firebug24k
  • GalliumMan
  • Gary Peterson
  • George Slade
  • GhostNull
  • Gordon Mcknight
  • Graham Armitage
  • Grant
  • GreySoul
  • Henry H
  • IamSmooth
  • In memory of Leo Powning
  • Jacob Cash
  • James Howells
  • James Pawson
  • Jeff Greenfield
  • Jeff Thomas
  • Jesse Frost
  • Jim Mitchell
  • jlr134
  • Joe Mastroianni
  • John Forcina
  • John Oberg
  • John Willcutt
  • Jon Newcomb
  • klugesmith
  • Leslie Wright
  • Lutz Hoffman
  • Mads Barnkob
  • Martin King
  • Mats Karlsson
  • Matt Gibson
  • Matthew Guidry
  • mbd
  • Michael D'Angelo
  • Mikkel
  • mileswaldron
  • mister_rf
  • Neil Foster
  • Nick de Smith
  • Nick Soroka
  • nicklenorp
  • Nik
  • Norman Stanley
  • Patrick Coleman
  • Paul Brodie
  • Paul Jordan
  • Paul Montgomery
  • Ped
  • Peter Krogen
  • Peter Terren
  • PhilGood
  • Richard Feldman
  • Robert Bush
  • Royce Bailey
  • Scott Fusare
  • Scott Newman
  • smiffy
  • Stella
  • Steven Busic
  • Steve Conner
  • Steve Jones
  • Steve Ward
  • Sulaiman
  • Thomas Coyle
  • Thomas A. Wallace
  • Thomas W
  • Timo
  • Torch
  • Ulf Jonsson
  • vasil
  • Vaxian
  • vladi mazzilli
  • wastehl
  • Weston
  • William Kim
  • William N.
  • William Stehl
  • Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Forums
4hv.org :: Forums :: General Science and Electronics
« Previous topic | Next topic »   

PID loop implimentation and scaling

Move Thread LAN_403
Patrick
Mon Jun 03 2013, 07:09PM Print
Patrick Registered Member #2431 Joined: Tue Oct 13 2009, 09:47PM
Location: Chico, CA. USA
Posts: 5639
im needing help, soon to start on my first full PID loops, coding, motion control, feedback, and hardware all produced by my self.

My judgment, experience and previous skills are telling me to use the "PID without a PhD" pdf, and then the Brett beaureguard articles... seen here: Link2
this way im not inventing everything from scratch.

the final coded example looks excellent, from what I can figure out as of now.

the problem: I need to scale the PID output to match my control scheme of the drone. as stated in other threads, I have a IMU (gyro, acc, mag) to measure what is happening and the the PID, then the control device which uses RC servo format. So 1.0mS for 0%, 1.5mS for 50% and 2.0mS for 100% command.

so my question: how do I scale the numeric output from the PID code module, so that its useful to my servo format microcontroller? (by the way I will limit the max deviations and max commands to less than what the PID and Microcontroller can command, so they don't get lost.)

any help would be appreciated.
Back to top
tobias
Tue Jun 04 2013, 04:48PM
tobias Registered Member #1956 Joined: Wed Feb 04 2009, 01:22PM
Location: Jersey City
Posts: 172
Using the map command if coding arduino?
Back to top
Patrick
Tue Jun 04 2013, 04:52PM
Patrick Registered Member #2431 Joined: Tue Oct 13 2009, 09:47PM
Location: Chico, CA. USA
Posts: 5639
perhaps im not realizing, that the PID is dimensionless and/or unit-less for feedback and output. Even though definite units input are, the relative magnitudes returned have none per se?

A quote from the great all-knowing wiki:
"Dimensionless quantities are often defined as products or ratios of quantities that are not dimensionless, but whose dimensions cancel out when their powers are multiplied. This is the case, for instance, with the engineering strain, a measure of deformation. It is defined as change in length over initial length but, since these quantities both have dimensions L (length), the result is a dimensionless quantity."


EDIT1:
ok but upon further research, i find:
"The error is multiplied by a negative (for reverse action) proportional constant P, and added to the current output. P represents the band over which a controller's output is proportional to the error of the system. E.g. for a heater, a controller with a proportional band of 10 deg C and a setpoint of 100 deg C would have an output of 100% up to 90 deg C, 50% at 95 Deg C and 10% at 99 deg C. If the temperature overshoots the setpoint value, the heating power would be cut back further. Proportional only control can provide a stable process temperature but there will always be an error between the required setpoint and the actual process temperature."( source: Link2 )

EDIT2:
tobias wrote ...

Using the map command if coding arduino?
im using common C, for the STM32F4. i refuse to use arduino for this purpose, though the code looks like normal C, i just dont want to learn special and properitary magic commands in arduino. i need to learn the real reasons PIDs work, then ill apply system specific stuff later in each case, years from now across my career. But i am learning a whole lot from arduino examples. (my drone flight controller is Arduino entirely amazed )


EDIT3:
sources and examples:

explanation, Link2
PID wiki, Link2


Back to top
Uspring
Wed Jun 05 2013, 10:35AM
Uspring Registered Member #3988 Joined: Thu Jul 07 2011, 03:25PM
Location:
Posts: 711
Patrick wrote:
Proportional only control can provide a stable process temperature but there will always be an error between the required setpoint and the actual process.
The input of the controller is the difference between the current value and the value you want to be at. To make it as small as possible and the reaction as fast as possible, you'd want a large as possible loop gain.
The system will begin oscillating at some value of the loop gain, i.e. when the loop gain is larger than one and the total phase shift of the system reaches 360 degrees at some frequency (180 degrees from the inverted feedback of the controller and 180 from your drone).
The max loop gain depends much on the frequency response of the drone and the time constants in the PID.

Back to top
Steve Conner
Wed Jun 05 2013, 11:36AM
Steve Conner Registered Member #30 Joined: Fri Feb 03 2006, 10:52AM
Location: Glasgow, Scotland
Posts: 6706
If you're using floating point arithmetic (and there's no reason not to as the STM32F4 has a nice floating point unit) you could do worse than to scale the PID controller so the input and output are in the range -1.0 to +1.0.

Then to drive your servo you would map this to an integer. Say you're using a PWM module where a timer setting of 1000 corresponds to a 2.0ms pulse. (And 0 corresponds to a 0ms pulse, and 500 to a 1ms pulse.)

Then you want to do a linear mapping such that -1.0 -> 500, +1.0 -> 1000. So you multiply by 250 and add 750.

Nyquist stability considerations are a separate issue. They depend on the scaling to be sure. But typically you would set the scaling once at the design stage and forget it. Stability would be managed by tuning the values of the P, I and D coefficients. With floating point arithmetic, you can tune the coefficients over a huge range without having to worry about rescaling.
Back to top
Patrick
Wed Jun 05 2013, 04:01PM
Patrick Registered Member #2431 Joined: Tue Oct 13 2009, 09:47PM
Location: Chico, CA. USA
Posts: 5639
Steve Conner wrote ...

If you're using floating point arithmetic (and there's no reason not to as the STM32F4 has a nice floating point unit) you could do worse than to scale the PID controller so the input and output are in the range -1.0 to +1.0.

Then to drive your servo you would map this to an integer. Say you're using a PWM module where a timer setting of 1000 corresponds to a 2.0ms pulse. (And 0 corresponds to a 0ms pulse, and 500 to a 1ms pulse.)

Then you want to do a linear mapping such that -1.0 -> 500, +1.0 -> 1000. So you multiply by 250 and add 750.

... With floating point arithmetic, you can tune the coefficients over a huge range without having to worry about rescaling.

ok so your suggesting using a floating point in code, (which i get) but also making it equally span above and below zero.

and the STM32F4 has counters, timers and all kinds of capability that still allows for fast iterations - even with floats.
compared to the PICs and other common microcontrollers of the early 2000's the STM32's are dam near magical.

Back to top
Patrick
Thu Jun 06 2013, 06:13PM
Patrick Registered Member #2431 Joined: Tue Oct 13 2009, 09:47PM
Location: Chico, CA. USA
Posts: 5639
ok so ive spent a full day considering what steve has suggested ad believe his idea does solve both my problems, however do i scale the input too, to floats at + and - 1.0 ?

mostly id be doing G-laod, inches and degrees, with position and velocity PIDs. (possibly an acceleration PID too)

I just want to remind everyone, the drone itself flies on the internal PIDs and IMU just fine (MWC 2.2, arduino), but i need the autonomous pilot to fly like a mouse in a maze without human pilot intervention, thats what these PIDs and the STM32F4 will be for, running off a second IMU (at a slower freq to avoid feedback oscillations with the first IMU).

flowchart :

1370544719 2431 FT1630 Droneflow








Back to top

Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob

Go to:

Powered by e107 Forum System
 
Legal Information
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.