2 # -*- coding: iso-8859-15 -*-
9 from datetime import datetime
10 from time import sleep
12 from pyshared.i2c import i2c
13 from pyshared.humidity import *
14 from wild_thumper.msg import Sensor
16 # Board warming offset
17 TEMP_ERROR = -3.0 # -5 # degree celsius
22 val = [1023, 396.8, 110.75, 28.1]
23 lux = [0, 13.8, 164.9, 1341]
26 logger = logging.getLogger(__name__)
30 dev.write(struct.pack(">BB", 0x00, 0x0f))
35 msg = dev.read(11) # for unknown reason need to read one more byte
42 ldr, temp_mess, humidity_mess, pressure, co = struct.unpack(">hhhhh", msg)
46 lux = exp(-8.1065e-08*ldr**3 +8.8678e-05*ldr**2 -0.03636*ldr +8.1547)
47 pressure_v = pressure*2.56/1024
48 pressure_kpa = P = (pressure_v/5 + 0.04) / 0.004 + PRESSURE_ERROR # datasheet
50 # fix temperature/humidity
52 temp_real = temp_mess + TEMP_ERROR
53 humidity_abs = calc_humidity_abs(temp_mess, humidity_mess)
54 humidity_real = calc_humidity_rel(temp_real, humidity_abs)
57 humidity_real = humidity_mess
59 return lux, temp_real, humidity_real, pressure_kpa, co
63 rospy.init_node('sensor_board')
64 prctl.set_name("sensor_board")
68 print >>sys.stderr, "No sensor board, shutting down"
70 self.pub = rospy.Publisher("sensors", Sensor, queue_size=16)
74 rate = rospy.Rate(1.0)
75 t_last_check = datetime.min
77 while not rospy.is_shutdown():
78 if self.pub.get_num_connections() > 0:
79 ldr, temp, humidity, pressure, co = get()
82 if (datetime.now() - t_last_check).seconds > 900:
83 ventilate = check_ventilate(temp, humidity)
84 t_last_check = datetime.now()
85 except Exception as e:
89 msg.header.stamp = rospy.Time.now()
92 msg.humidity = humidity
93 msg.pressure = pressure
95 msg.ventilate = True if ventilate > 1.10 else False
101 if __name__ == "__main__":