Shop OBEX P1 Docs P2 Docs Learn Events
PID Controller to tune an engine — Parallax Forums

PID Controller to tune an engine

blackhawk0042blackhawk0042 Posts: 1
edited 2013-01-27 06:11 in Propeller 1
Hey everyone,

I just want to start out by giving you all a little background about myself. I am a team member on my senior design team that is working on our project called STEFI. This is our Self-Tuning Electronic Fuel Injection system. We are currently using the Propeller 1 as our micro-controller. The part that I am working on is the PID Controller loop. Basically I am to take the value of the current AFR (Air/Fuel Ratio) and try to get it to a specific value by controlling the amount of time the fuel injectors are open putting fuel into the engine.

Basically I want to know if there are any good examples of PID controller codes out there that I can take a look at. I have never really coded for the Propeller so this is a first for me. Consider me a Noob on all levels when talking to me about this. Thanks for your time and patience!

Tom

Comments

  • MicksterMickster Posts: 2,694
    edited 2013-01-24 02:17
    There are a few. Look in the OBEX under Math or Motor Control. "PID" is too short for the search engine, apparently.


    Also this:
    http://forums.parallax.com/showthread.php/105978-PID-Enhanced-is-finally-done!?highlight=Enhanced+PID

    Mickster
  • max72max72 Posts: 1,155
    edited 2013-01-24 02:24
    You can also use the google search engine limiting the domain.
    in google searh type:
    PID site:obex.parallax.com
    
    

    If you look for a topic in the forum limit the search with
    site:forums.parallax.com
    

    Massimo
  • T ChapT Chap Posts: 4,223
    edited 2013-01-25 08:49
    My experience is that getting a PID loop running is a lot of trial and error, and having a stock object off of the obex will at best be a starting point to your problem. I attempted to start with an object and got nowhere with it, because there are multiple ways to produce an error and have the loop correct the error. A simple PID loop found on the web may not have critical components to manage your errors. For example, you may likely need a method to limit the "integral wind up" so that there is a finite maximum to the output of the loop. It is also not often important to worry about the Derivative, often just the Proportional and Integral + Integral Max values are the first things to get working. After that, if the Derivative is required then add it in. Other factors to consider include a range of Deadband, this is a preset range of allowable error, I like to have the Deadband kick in only after the initial point as been reached, then is can slack off X amount to avoid some oscillation. In a PID loop controlling a motor, I like to have a method included in the PID that determines if the motor is actually moving based on an encoder on the motor, and if it is not moving then the PID loop shuts down and sends out an error message to the main program that there is a problem. There are other things to consider but this gives you some things to consider. Most likely, as you start getting the bare bones aspects running, you will discover what other components are required.

    The first thing to start with is, what is the source of your error in terms of how you are going to present the error to the loop. What are the ranges of the error min to max. Is there a requirement for a maximum output, or maximum Integral value. Does the output need to be scaled to your device, and what is the method of controlling your device. Do the values inside the loop need to be constrained to positive values only, or is there a need for signed values( I always keep the error as a positive as in error := ||(encoder position - desired position). Is there any feedback (sensor) from the device to track?

    Hope this helps.
  • thebigmacdthebigmacd Posts: 9
    edited 2013-01-25 18:05
    I build ECUs and tune engines as a hobby (Megasquirt). I am also a Control Engineering Technologist so I have plenty of experience with PIDs.

    To do automatic mixture tuning with a PID loop you have to first get the mixture "close enough". A gasoline engine can't just run with an arbitrary amount of injected fuel that slowly gets adjusted to the optimum range; it must be within a specific mixture range to ignite the fuel successfully in the first place. Also, wideband air-fuel meters are slow within the context of a running engine (approximately 100ms step response at the absolute fastest, and that's claimed numbers, not real-world), so they can't react fast enough to do per-cycle adjustment even at idle. Then there are issues of lean- and rich-misfire that trick the sensor into reading the wrong mixture.

    At the very least what you need is a feed-forward component to your PID loop, from a fuel table that references rpm on one axis and load on the other. Then you have to limit the maximum PID authority so that it doesn't deviate the injection amounts beyond a safe range.

    In the Megasquirt world we run the engine parameters through a formula to get a base fuel table to work from before starting the tuning process, this is the feed-forward component.
  • evanhevanh Posts: 15,944
    edited 2013-01-26 18:51
    thebigmacd wrote: »
    At the very least what you need is a feed-forward component to your PID loop, from a fuel table that references rpm on one axis and load on the other. Then you have to limit the maximum PID authority so that it doesn't deviate the injection amounts beyond a safe range.

    In the Megasquirt world we run the engine parameters through a formula to get a base fuel table to work from before starting the tuning process, this is the feed-forward component.

    That's some good advice. Do you have any Prop/Prop2 plans?
  • thebigmacdthebigmacd Posts: 9
    edited 2013-01-27 06:11
    I did have a Prop project kind of started, but I don't have enough time to get a project going from scratch. With Megasquirt the hardware and codebase is off-the-shelf, we just change parameters to tune the engines.
Sign In or Register to comment.