A more capable PID library than PID_v1.h

Hi agian,

for a project I'm working on (a cruise control) I'm using the PID_v1 library. For smoothness sake I want to change the starting output of the PID. e.g. when I start the PID I want to have it calculate the output starting from the output I am applying myself. So: if I put 40 on the throttle I want to have it that the PID starts with that 40 and not with a previous output it had (like 80), which would jerk my motor.

Is there a library with this option? Am I overlooking something? I could write some functions myself if this isn't possible with any library.

thanks,
Jens

PID is driven by a target and determines an output to reach a target with limited overshoot. For example, the target might be a position and PID determines the speed.

what are you trying to control with PID? what is the input to your PID?

For my bachelorthesis in Electromechanical Engineering I am setting up a datacom system for a solar boat and one of the requirements is a cruise control. Since we can't test on the water due to the lockdown, I'm limiting myself to an rpm regulator. I've had several courses on the subject of PID and quite familiar with it now.
a
The input is the rpm, which is read from the controller via rs232. The output is a value between 1710 and 2200 via rs232 to the controller. The controller has a potentiometer input also and the rs232 is overriding that. I want to switch smoothly between the two so I want the PID algorithm to start computing from the value the potentiometer is inputting so we don't get a jerk on the motor etc.

hope this helps?

It may already take care of that for you. Take a look at this.

The link sends me to the library creators website but with 404 not found :slight_smile:

The PID library's author has written a detailed description of how it works and the options that are available. You should probably start with that: Improving the Beginner’s PID – Introduction « Project Blog

EDIT:
This link works. After getting there, click on "initialization".

Assuming that that link gets you there, the whole thing is worth reading, but the section I was trying to send you to was the part on Initialization which deals with changing modes between manual and automatic.

interesting article! I this implemented in a new version of the library or do I have to look at it as a tutorial to write my own PID?

IIRC, that is the "standard" Arduino library. i.e. the one you are using.

I’m limiting myself to an rpm regulator.

wouldn’t the rpm be set to whatever the controller (e.g. pot) is?

without considering the switch between a serial and pot inputs, are you just relying on PID to smooth the response?

you could use leaking integration to avoid a step change when switching between input value
A += (s - A) * K // K < 1

You could write your own PID algorithm , but the library is good .

I think it’s just a question of loading the correct terms into the algorithm at the point of switch over so the output doesn’t suddenly change .
Probably re setting ( zeroing) the integral
Term may do it ?

Btw using an Arduino for a Cruise Control system on a car is not the safest of plans

I think I see what I did wrong in my code: I stopped computing the PID, and thus updating the values, while not overriding the potentiometer. I'll fix that and report back!

hammy:
Btw using an Arduino for a Cruise Control system on a car is not the safest of plans

We are well aware of that :smiley: this is a proof of concept kind of deal and this program/system would be implemented in the on board PLC next year. And it's a boat btw haha. I've implemented some safety features (being able to sail without my arduino, deadman switch, extra fuses etc.) so nothing can really go wrong.