All pastes #1475213 Raw Edit

reprap_temp.py

public python v1 · immutable
#1475213 ·published 2009-06-26 08:20 UTC
rendered paste body
#!/usr/bin/python#    HAL userspace component to calculate corrected temperature values for reprap#    ntc thermistors#    Copyright (C) 2009 Joachim Steiger <reprap@hyte.de>##    This program is free software; you can redistribute it and/or modify#    it under the terms of the GNU General Public License as published by#    the Free Software Foundation; either version 2 of the License, or#    (at your option) any later version.##    This program is distributed in the hope that it will be useful,#    but WITHOUT ANY WARRANTY; without even the implied warranty of#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the#    GNU General Public License for more details.##    You should have received a copy of the GNU General Public License#    along with this program; if not, write to the Free Software#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USAfrom math import *import sysimport timeimport halif len(sys.argv) > 1:    num = int(sys.argv[1])else:    num = 1c = hal.component("repraptemp") for foo in range(0, num):    c.newpin("repraptemp.%02d.in" % foo, hal.HAL_FLOAT, hal.HAL_IN)    c.newpin("repraptemp.%02d.out" % foo, hal.HAL_FLOAT, hal.HAL_OUT)    c.newparam("repraptemp.%02d.r0" % foo, hal.HAL_U32, hal.HAL_RW)    c.newparam("repraptemp.%02d.t0" % foo, hal.HAL_S32, hal.HAL_RW)    c.newparam("repraptemp.%02d.beta" % foo, hal.HAL_U32, hal.HAL_RW)    c.newparam("repraptemp.%02d.v" % foo, hal.HAL_FLOAT, hal.HAL_RW)    c.newparam("repraptemp.%02d.r2" % foo, hal.HAL_U32, hal.HAL_RW)    c['repraptemp.%02d.r0' % foo] = 100000    c['repraptemp.%02d.t0' % foo] = 25    c['repraptemp.%02d.beta' % foo] = 4066    c['repraptemp.%02d.v' % foo] = 5.0    c['repraptemp.%02d.r2' % foo] = 4700c.ready()try:    while 1:#        select.select(fds, [], [], .01)	for foo in range(0, num):	    k = c['repraptemp.%02d.r0' % foo] * exp(-(c['repraptemp.%02d.beta' % foo]) / (c['repraptemp.%02d.t0' % foo] + 273.15))	    r = c['repraptemp.%02d.r2' % foo] * c['repraptemp.%02d.in' % foo] / (c['repraptemp.%02d.v' % foo] - c['repraptemp.%02d.in' % foo])	    c['repraptemp.%02d.out' % foo] = (c['repraptemp.%02d.beta' % foo] / log (r / k)) - 273.15        time.sleep(.001)except (KeyboardInterrupt,):    raise SystemExit, 0