brycesub / silvia-pi

A Raspberry Pi modification to the Rancilio Silvia Espresso Machine implementing PID temperature control.
MIT License
140 stars 42 forks source link

Explanation #19

Open therealjohn opened 6 years ago

therealjohn commented 6 years ago

Would you be able to explain this logic?

https://github.com/brycesub/silvia-pi/blob/master/silvia-pi.py#L30-L44

What's unclear:

Thank you!

brycesub commented 6 years ago

Each loop is 1 second long. When the avgpid is >100 then that means the heating element should be on for 100% of the next second. When it's between 0-100 the heating element should be on for that fraction of the next second, e.g. 70 means the heating element should be on for 7/10 of the next second.

therealjohn commented 6 years ago

Thanks for the response! What’s the significance of 100?

brycesub commented 6 years ago

That's how a PID algorithm works, you give it a goal, some inputs, and then it calculates an output that we use to drive the heating element. It's a versatile algorithm used in other applications besides temperature control, for example the amount of power delivered to a motor to achieve a given RPM goal.

This link helped me the most when researching this project: http://m.eet.com/media/1112634/f-wescot.pdf

therealjohn commented 6 years ago

@brycesub Thanks for the link! It is helpful! What I don't understand is exactly how it's used here. I don't see any clamping on the output of the PID or what the significance of 100 is in this context. Is it some arbitrary threshold of the PID output that you tested? I'm confused as to why the range of 1-99 is when the temperature is "stable".

I've assumed this is the source for the PID being used. I see it clamps the integral term to -20/20 by default. But the output is not clamped.

I've been playing with this and porting it to work with a Netduino but there are some differences I am experiencing. I noticed that if the temperature is above my set point, and hit this > 0 < 100 code, the sleep times are not sufficient to let the temperature cool down to the set point. Instead, it continues to heat slowly.

Before I tweaked that, I wanted to understand it. Thanks for your help!

therealjohn commented 6 years ago

I think I've figured it out now. It's clearer now how to correctly time-proportion the PID output to something that can be used to determine the on/off signals to the SSR. I don't see where that's done here but I did manage to solve my issue.

I'd still be curious if you could explain exactly how your PID output is normalized between 0-100.

Thanks!