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.
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: 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.)
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: )
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 )
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.
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.
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.
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).
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.