#!/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("%02d.in" % foo, hal.HAL_FLOAT, hal.HAL_IN) c.newpin("%02d.out" % foo, hal.HAL_FLOAT, hal.HAL_OUT) c.newparam("%02d.r0" % foo, hal.HAL_U32, hal.HAL_RW) c.newparam("%02d.t0" % foo, hal.HAL_S32, hal.HAL_RW) c.newparam("%02d.beta" % foo, hal.HAL_U32, hal.HAL_RW) c.newparam("%02d.v" % foo, hal.HAL_FLOAT, hal.HAL_RW) c.newparam("%02d.r2" % foo, hal.HAL_U32, hal.HAL_RW) c['%02d.r0' % foo] = 100000 c['%02d.t0' % foo] = 25 c['%02d.beta' % foo] = 4066 c['%02d.v' % foo] = 5.0 c['%02d.r2' % foo] = 4700c.ready()try: while 1:# select.select(fds, [], [], .01) for foo in range(0, num): k = c['%02d.r0' % foo] * exp(-(c['%02d.beta' % foo]) / (c['%02d.t0' % foo] + 273.15))# print("in = %s\nk = %s" % (c['%02d.in' % foo] ,k)) if ((c['%02d.v' % foo] - c['%02d.in' % foo]) > 0 ): r = c['%02d.r2' % foo] * c['%02d.in' % foo] / (c['%02d.v' % foo] - c['%02d.in' % foo])# print("r = %s" % r) if (r != 0): c['%02d.out' % foo] = (c['%02d.beta' % foo] / log (r / k)) - 273.15# print("out = %s" % c['%02d.out' % foo]) time.sleep(.01)except (KeyboardInterrupt,): raise SystemExit, 0