def talker(self):

		while not rospy.is_shutdown():
			if self.ser.in_waiting: 
				try:
					data= self.ser.readline() # Read data from serial port
					if data.startswith('_'):
						msg=String()
						msg.data=data
						rospy.loginfo(msg)
						self.pubRaw.publish(msg)

					else:
						try:	
							dataVec=data[0:-1].split("\t")
							msg=serial_data()
							msg.milliseconds=long(dataVec[0])
							msg.rate=long(dataVec[1])
							msg.data=map(float,dataVec[2:-1])
							
							rospy.loginfo(msg)
							self.pub.publish(msg)
						except ValueError:
							rospy.logerr('PRESSURE CONTROL: data was garbled...ignoring it')

				except serial.serialutil.SerialException:
					rospy.logerr('PRESSURE CONTROL: Serial read error...ignoring it')
					
			self.rate.sleep()
Exemple #2
0
def talker():
	ser = serial_coms.resume(devname,baud)
	serial_coms.initialize(ser)

	pub = rospy.Publisher('/object_return/location', serial_data, queue_size=10)
	pubRaw = rospy.Publisher('/object_return/raw', String, queue_size=10)
	rospy.init_node('talker',anonymous=True)
	while not rospy.is_shutdown():
		if ser.in_waiting:
			try:
				data= ser.readline() # Read data from serial port
				if data.startswith('_'):
					msg=String()
					msg.data=data
					rospy.loginfo(msg)
					pubRaw.publish(msg)

				else:
					try:	
						dataVec=data[0:-1].split("\t")
						msg=serial_data()
						msg.milliseconds=long(dataVec[0])
						msg.rate=long(dataVec[1])
						msg.data=map(float,dataVec[2:])
						
						rospy.loginfo(msg)
						pub.publish(msg)
					except ValueError:
						rospy.logerr('OBJECT RETURN: data was garbled...ignoring it')

			except serial.serialutil.SerialException:
				rospy.logerr('OBJECT RETURN: Serial read error...ignoring it')