From 32049198dc2ed66a666a49524c1d8450b58fdaf0 Mon Sep 17 00:00:00 2001 From: Rousseau Vincent <vincent.rousseau@irstea.fr> Date: Mon, 30 Jul 2018 12:08:44 +0200 Subject: [PATCH] Use non blocking function with timer --- scripts/stream_node.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/stream_node.py b/scripts/stream_node.py index 1332a7b..b299ec6 100755 --- a/scripts/stream_node.py +++ b/scripts/stream_node.py @@ -36,7 +36,6 @@ class Labjack(object): self.d.streamStart() - # Anonymous topic ? self.pub = rospy.Publisher('chatter', Float32, queue_size=10) #timer_period = 0.01 # in second @@ -59,7 +58,30 @@ class Labjack(object): self.pub.publish(msg) +class LabjackAIN(object): + def __init__(self, channel, resolution=16): + self.channel_name = "AIN"+str(channel) + self.d = ue9.UE9() + self.d.getCalibrationData() + + self.pub = rospy.Publisher('chatter', Float32, queue_size=10) + + timer_period = 0.01 # in second + self.timer = rospy.Timer(rospy.Duration(timer_period), self.timer_callback) + rospy.spin() + + self.d.close() + + def timer_callback(self, event): + msg = Float32() + # Conversion in milli volt for gain 1 + data = self.d.getAIN(1) + if data is not None: + msg.data = data + rospy.loginfo('Publishing: "{0}"'.format(msg.data)) + self.pub.publish(msg) + if __name__ == '__main__': rospy.init_node('labjack', anonymous=True) - node = Labjack(1) \ No newline at end of file + node = LabjackAIN(1) \ No newline at end of file -- GitLab