Temperature Control

More
10 Feb 2018 11:54 #105699 by Hawkeye
Temperature Control was created by Hawkeye
Hello all,

I am currently struggeling to create a temperature controller for a 3D extruder head..

I already hooked an Arduino (with a 100K sensor) using python to my machine.
The customgui seems also be working and shows the temperature recorded by Arduino as a bar graph.
So far - so good..
But now I have to setup an PID (and I guess an pwm-) controller.
My expectation was to have a output bit-signal that can be used to switch on the heater if temperature is less than commanded.
The PID-Controller itself should control between upper 280°C and lower limit 0°C.
My hardware uses an SSR relay to switch heating on and off again.

Any thoughts on this? Here is what I have so far:
loadrt pwmgen output_type=0

addf pwmgen.make-pulses base-thread
addf pwmgen.update		servo-thread

setp t0-pid.enable			1
setp t0-pid.Pgain			1
setp t0-pid.Igain			1
setp t0-pid.Dgain			0
setp t0-pid.maxoutput		280
setp t0-pid.command			20
setp t0-pid.feedback		220
setp t0-pid.FF0           	0
setp t0-pid.FF1           	1
setp t0-pid.FF2           	0.1
setp pwmgen.0.enable		1
setp pwmgen.0.scale			1
setp pwmgen.0.pwm-freq		1000
setp pwmgen.0.dither-pwm	0
setp pwmgen.0.min-dc		0

net t0-pidout				t0-pid.output			=> pwmgen.0.value
net hotend-is-on									<= pwmgen.0.pwm


Thanks in advance,
Ben
More
26 Feb 2018 20:47 #106564 by andypugh
Replied by andypugh on topic Temperature Control
The pwm output needs to go somewhere.
Also, the PID needs to be added to the servo thread.

And the PID feedback needs to be the measured temperature, not a fixed value.
The following user(s) said Thank You: Hawkeye
More
11 Mar 2018 10:36 #107211 by Hawkeye
Replied by Hawkeye on topic Temperature Control
Hello Andy,

this was helpful thank you.

In the meantime I got this up and running, but the temperature is currently overshooting.
But this should be something that needs some fine tuning on a rainy day.

Thank you,
Ben
More
15 Mar 2018 13:43 #107372 by B9T
Replied by B9T on topic Temperature Control
I'm currently working on adding a printhead to a cnc machine as well and am similarly struggling to implement some temperature control. How did you manage to do this and how do you set the desired temperature?

Thanks in advance
More
18 Mar 2018 14:41 #107490 by Hawkeye
Replied by Hawkeye on topic Temperature Control
Hello B9T,

as you may already know, I use on my machine Beckhoff components.
For the temperature control, I am using an digital out connector that is hooked to an SSR-Relais (24VDC to 6A24VDC) from finder. The original 12V heater of the printerhead has been replaced by a 24V heater. The heater is connected to my SSR-Relais.

What I did so far within LinuxCNC:
- {machine_name}.ini
Here I added within the section [RS274NGC] a variable "SUBROUTINE_PATH" which is pointing to my custom *.ngc files.
Furthermore, defined an new section as below:
[TEMPERATURE_CONTROL]
P						= 0.000001
I						= 0.0001
D						= 0
MAX_OUTPUT				= 0.000001
FF0             		= 0
FF1             		= 0
FF2             		= 0

SCALE					= 0.000001
PWM_FREQ				= 1000
DITHER_PWM				= 0
MAX_DC					= 0.05
MIN_DC					= 0.0
- Within my previously defined custom folder, I created files named "M104", "M106", "M107", "M109" and marked them as executable.
Example of M104:
#!/bin/bash

# Extruder temperature
if [ $# -gt 0 ];
then
	halcmd sets hotend-temp-tgt $1
fi

exit 0
- post_gui.hal
I decided not to define seperate hal-file for heater control yet, as I don't have planty of time for this project at the moment.
#############################################################################################
#	Hotend Temperature Control																#
#############################################################################################
# load module
loadrt pwmgen output_type=0

addf pwmgen.make-pulses 	base-thread
addf pwmgen.update			servo-thread
addf t0-pid.do-pid-calcs	servo-thread

# parameters
setp t0-pid.Pgain			[TEMPERATURE_CONTROL]P
setp t0-pid.Igain			[TEMPERATURE_CONTROL]I
setp t0-pid.Dgain			[TEMPERATURE_CONTROL]D
setp t0-pid.maxoutput		[TEMPERATURE_CONTROL]MAX_OUTPUT
setp t0-pid.FF0				[TEMPERATURE_CONTROL]FF0
setp t0-pid.FF1				[TEMPERATURE_CONTROL]FF1
setp t0-pid.FF2				[TEMPERATURE_CONTROL]FF2

setp pwmgen.0.scale			[TEMPERATURE_CONTROL]SCALE
setp pwmgen.0.pwm-freq		[TEMPERATURE_CONTROL]PWM_FREQ
setp pwmgen.0.dither-pwm	[TEMPERATURE_CONTROL]DITHER_PWM
setp pwmgen.0.max-dc		[TEMPERATURE_CONTROL]MAX_DC
setp pwmgen.0.min-dc		[TEMPERATURE_CONTROL]MIN_DC

#Machine in printing mode?
net machine-mode-is-printer										=> pwmgen.0.enable
net machine-mode-is-printer										=> t0-pid.enable

#
net hotend-temp-tgt 											=> t0-pid.command 
net hotend-temp-act												=> t0-pid.feedback
net hotend-t0-pid-out-value	t0-pid.output						=> pwmgen.0.value
net hotend-is-on												<= pwmgen.0.pwm

As heating is still overshooting (which needs fine tuning of parameters within ini-file, I don't give any guarantee on anything here.
My next steps should be fine tuning PID and PWM.

If you have better values for the ini-file, please add them to this post.
I guess others may take advantage of this post too.

Best Regards,
Ben
More
18 Mar 2018 14:48 #107491 by andypugh
Replied by andypugh on topic Temperature Control
I think 1000Hz PWM is possibly too high for a heater.
It might not matter with an SSR.
The following user(s) said Thank You: Hawkeye
More
18 Mar 2018 14:53 #107492 by Hawkeye
Replied by Hawkeye on topic Temperature Control
Hello Andy,

which frequency would you propose?

What do you think about the PID values, I guess they are totally rubbish.
Any suggestion on that? At the moment, the heating overshoots with more than 10% of the target temperature.
While 3D printing, temperature control seems to be crucial.

Regards,
Ben
More
18 Mar 2018 15:10 #107493 by Hawkeye
Replied by Hawkeye on topic Temperature Control
What I missed so far:
For reading the temperature, I am using an Arduino UNO board which was on already on my electronic scrap bin.
This working better than expected.

Wiring and temperature-read-routine:
www.derpade.de/tutorial-arduino-cactus-n...k-temperatur-sensor/

Configuration on operationg system level (run as user "root"):
adduser {YOUR_USERNAME_HERE} dialout
apt-get install gcc-avr avr-libc avrdude
apt-get install python-pip python python-serial
python -c 'import serial'

Merge this to your {machine-name}.ini:
[RS274NGC]
PARAMETER_FILE = linuxcnc.var
SUBROUTINE_PATH = {FOLDERNAME_HERE}/SUBROUTINES/
USER_M_PATH = {FOLDERNAME_HERE}/CUSTOM/

HAL-Code (not very nice yet! Filename="USB-Thermometer.py" define script as executable:
LinuxCNC HAL:
#!/usr/bin/python
import serial
import hal
import sys
import time

PORT = "/dev/ttyACM0"
ser = serial.Serial(PORT, 115200, timeout=15)

c = hal.component("usb-thermometer")
c.newpin("t0-cmd", hal.HAL_FLOAT, hal.HAL_IN)
c.newpin("t0", hal.HAL_FLOAT, hal.HAL_OUT)

time.sleep(1)
c.ready()

t0cmd = c['t0-cmd']
t0cmdOld = 0;


try:
  while 1:
    time.sleep(0.25)

    t0cmd = c['t0-cmd']
    if t0cmd != t0cmdOld:
        t0cmdOld = t0cmd;
        ser.write("T0");

    while ser.inWaiting():
      line = ser.readline();
    
      if(line[:3] == "T0="):
          c['t0'] = float(line[3:])

except KeyboardInterrupt:
    ser.write("-P;");
    raise SystemExit

Try to activate Arduino-Module now within {MACHINE_NAME}.ini :
###########################################################
# Arduino Temperature
###########################################################
loadusr -i ./USB-Thermometer.py
More
18 Mar 2018 19:37 #107508 by andypugh
Replied by andypugh on topic Temperature Control

Hawkeye wrote: which frequency would you propose?

I would kind-of expect to be turning a heater on and off about 10x per second.
Which isn't to say that 1000Hz won't work. But (for example) furnace controllers seem to cycle between full-on and full-off every few seconds.

What do you think about the PID values, I guess they are totally rubbish.


A little odd. I am not sure why you have a 0.0001 max output and a 0.0001 scale. Why not let both run from 0 to 1 or even 0 to 100(%)?

You might be seeing I-term wind-up, I would try seeing how close you can get with just P.

Also, why such a tiny max duty cycle?
More
20 Mar 2018 15:49 - 20 Mar 2018 15:50 #107618 by B9T
Replied by B9T on topic Temperature Control
That looks good and is kind of what I was thinking of, thank you. One option I was thinking of was loading any one of the 3d printer firmwares (probably Marlin) onto an Arduino and let it directly control the heater and temperature sensor. Marlin does ~8Hz control on the heaters if I remember that correctly and does offer PID tuning for the heaters.

Is there a straight forward way to pause the gcode interpretation in linuxcnc in order to implement a behavior similar to M109, i.e. setting the temperature and then waiting for it to be reached?
Last edit: 20 Mar 2018 15:50 by B9T.
Time to create page: 0.102 seconds
Powered by Kunena Forum