def __init__(self, args, test_timeout): self.powerup = args.powerup self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "R SERIAL> ") self.fastboot = "fastboot boot -s {ser} artifacts/fastboot.img".format( ser=args.fbserial) self.test_timeout = test_timeout
class CrosServoRun: def __init__(self, cpu, ec): self.ec_ser = SerialBuffer(ec, "artifacts/serial-ec.txt", "R SERIAL-EC> ") self.cpu_ser = SerialBuffer(cpu, "artifacts/serial.txt", "R SERIAL-CPU> ") def ec_write(self, s): print("W SERIAL-EC> %s" % s) self.ec_ser.serial.write(s.encode()) def cpu_write(self, s): print("W SERIAL-CPU> %s" % s) self.cpu_ser.serial.write(s.encode()) def run(self): # Flush any partial commands in the EC's prompt, then ask for a reboot. self.ec_write("\n") self.ec_write("reboot\n") # This is emitted right when the bootloader pauses to check for input. # Emit a ^N character to request network boot, because we don't have a # direct-to-netboot firmware on cheza. for line in self.cpu_ser.lines(): if re.match("load_archive: loading locale_en.bin", line): self.cpu_write("\016") break tftp_failures = 0 for line in self.cpu_ser.lines(): if re.match("---. end Kernel panic", line): return 1 # The Cheza boards have issues with failing to bring up power to # the system sometimes, possibly dependent on ambient temperature # in the farm. if re.match("POWER_GOOD not seen in time", line): return 2 # The Cheza firmware seems to occasionally get stuck looping in # this error state during TFTP booting, possibly based on amount of # network traffic around it, but it'll usually recover after a # reboot. if re.match("R8152: Bulk read error 0xffffffbf", line): tftp_failures += 1 if tftp_failures >= 100: return 2 result = re.match("bare-metal result: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 print("Reached the end of the CPU serial log without finding a result") return 1
class PoERun: def __init__(self, args, test_timeout): self.powerup = args.powerup self.powerdown = args.powerdown self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "") self.test_timeout = test_timeout def print_error(self, message): RED = '\033[0;31m' NO_COLOR = '\033[0m' print(RED + message + NO_COLOR) def logged_system(self, cmd): print("Running '{}'".format(cmd)) return os.system(cmd) def run(self): if self.logged_system(self.powerup) != 0: return 1 boot_detected = False for line in self.ser.lines(timeout=5 * 60, phase="bootloader"): if re.search("Booting Linux", line): boot_detected = True break if not boot_detected: self.print_error( "Something wrong; couldn't detect the boot start up sequence") return 2 for line in self.ser.lines(timeout=self.test_timeout, phase="test"): if re.search("---. end Kernel panic", line): return 1 # Binning memory problems if re.search("binner overflow mem", line): self.print_error("Memory overflow in the binner; GPU hang") return 1 if re.search( "nouveau 57000000.gpu: bus: MMIO read of 00000000 FAULT at 137000", line): self.print_error("nouveau jetson boot bug, retrying.") return 2 result = re.search("hwci: mesa: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 self.print_error( "Reached the end of the CPU serial log without finding a result") return 2
def __init__(self, device="/dev/ttyUSB0", baudrate=115200): self.sb = SerialBuffer(device, baudrate) if not self.sb.is_open(): print "Cannot open port" exit() self.reset_srv = rospy.Service('rtk_gps/reset', Trigger, self.reset_callback) self.pub = rospy.Publisher('/rtk_gps/gps', GPSFix) self.msg = GPSFix()
def __init__(self, args): self.powerup = args.powerup # We would like something like a 1 minute timeout, but the piglit traces # jobs stall out for long periods of time. self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "R SERIAL> ", timeout=600) self.fastboot = "fastboot boot -s {ser} artifacts/fastboot.img".format( ser=args.fbserial)
def __init__(self, cpu, ec, test_timeout): self.cpu_ser = SerialBuffer(cpu, "results/serial.txt", "R SERIAL-CPU> ") # Merge the EC serial into the cpu_ser's line stream so that we can # effectively poll on both at the same time and not have to worry about self.ec_ser = SerialBuffer(ec, "results/serial-ec.txt", "R SERIAL-EC> ", line_queue=self.cpu_ser.line_queue) self.test_timeout = test_timeout
class FastbootRun: def __init__(self, args): self.powerup = args.powerup self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "R SERIAL> ") self.fastboot = "fastboot boot -s {ser} artifacts/fastboot.img".format( ser=args.fbserial) def logged_system(self, cmd): print("Running '{}'".format(cmd)) return os.system(cmd) def run(self): if self.logged_system(self.powerup) != 0: return 1 fastboot_ready = False for line in self.ser.lines(): if re.search("fastboot: processing commands", line) or \ re.search("Listening for fastboot command on", line): fastboot_ready = True break if re.search("data abort", line): return 1 if not fastboot_ready: print("Failed to get to fastboot prompt") return 1 if self.logged_system(self.fastboot) != 0: return 1 for line in self.ser.lines(): if re.search("---. end Kernel panic", line): return 1 # The db820c boards intermittently reboot. Just restart the run # when if we see a reboot after we got past fastboot. if re.search("PON REASON", line): print("Detected spontaneous reboot, restarting run...") return 2 result = re.search("bare-metal result: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 print("Reached the end of the CPU serial log without finding a result") return 1
class PoERun: def __init__(self, args): self.powerup = args.powerup self.powerdown = args.powerdown self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "", args.timeout) def print_error(self, message): RED = '\033[0;31m' NO_COLOR = '\033[0m' print(RED + message + NO_COLOR) def logged_system(self, cmd): print("Running '{}'".format(cmd)) return os.system(cmd) def run(self): if self.logged_system(self.powerup) != 0: return 1 boot_detected = False for line in self.ser.lines(): if re.search("Booting Linux", line): boot_detected = True break if not boot_detected: self.print_error( "Something wrong; couldn't detect the boot start up sequence") self.logged_system(self.powerdown) return 2 for line in self.ser.lines(): if re.search("---. end Kernel panic", line): return 1 # Binning memory problems if re.search("binner overflow mem", line): self.print_error("Memory overflow in the binner; GPU hang") return 1 result = re.search("bare-metal result: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 self.print_error( "Reached the end of the CPU serial log without finding a result") return 2
class FastbootRun: def __init__(self, args, test_timeout): self.powerup = args.powerup self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "R SERIAL> ") self.fastboot = "fastboot boot -s {ser} artifacts/fastboot.img".format( ser=args.fbserial) self.test_timeout = test_timeout def close(self): self.ser.close() def print_error(self, message): RED = '\033[0;31m' NO_COLOR = '\033[0m' print(RED + message + NO_COLOR) def logged_system(self, cmd, timeout=60): print("Running '{}'".format(cmd)) try: return subprocess.call(cmd, shell=True, timeout=timeout) except subprocess.TimeoutExpired: self.print_error("timeout, restarting run...") return 2 def run(self): if ret := self.logged_system(self.powerup): return ret fastboot_ready = False for line in self.ser.lines(timeout=2 * 60, phase="bootloader"): if re.search("fastboot: processing commands", line) or \ re.search("Listening for fastboot command on", line): fastboot_ready = True break if re.search("data abort", line): self.print_error( "Detected crash during boot, restarting run...") return 2 if not fastboot_ready: self.print_error( "Failed to get to fastboot prompt, restarting run...") return 2 if ret := self.logged_system(self.fastboot): return ret
def __init__(self, cpu, ec): # Merged FIFO for the two serial buffers, fed by threads. self.serial_queue = queue.Queue() self.sentinel = object() self.threads_done = 0 self.ec_ser = SerialBuffer(ec, "results/serial-ec.txt", "R SERIAL-EC> ") self.cpu_ser = SerialBuffer(cpu, "results/serial.txt", "R SERIAL-CPU> ") self.iter_feed_ec = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.ec_ser.lines(), )) self.iter_feed_ec.start() self.iter_feed_cpu = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.cpu_ser.lines(), )) self.iter_feed_cpu.start()
def __init__(self): self.sb = SerialBuffer("/dev/ttyUSB0", 115200) if not self.sb.is_open(): print "Cannot open port" exit() self.position_pub = rospy.Publisher('/rtk_gps/position', Position, queue_size=10) self.orientation_pub = rospy.Publisher('/rtk_gps/orientation', Orientation, queue_size=10) self.pose_pub = rospy.Publisher('/rtk_gps/pose', Pose, queue_size=10) self.reset_srv = rospy.Service('rtk_gps/reset', Trigger, self.resetCallback) self.position_sub = message_filters.Subscriber('/rtk_gps/position', Position) self.orientation_sub = message_filters.Subscriber( '/rtk_gps/orientation', Orientation) self.sync = message_filters.ApproximateTimeSynchronizer( [self.position_sub, self.orientation_sub], 10, 0.1) self.sync.registerCallback(self.callback)
class FastbootRun: def __init__(self, args): self.powerup = args.powerup # We would like something like a 1 minute timeout, but the piglit traces # jobs stall out for long periods of time. self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "R SERIAL> ", timeout=600) self.fastboot = "fastboot boot -s {ser} artifacts/fastboot.img".format( ser=args.fbserial) def close(self): self.ser.close() def print_error(self, message): RED = '\033[0;31m' NO_COLOR = '\033[0m' print(RED + message + NO_COLOR) def logged_system(self, cmd): print("Running '{}'".format(cmd)) return os.system(cmd) def run(self): if self.logged_system(self.powerup) != 0: return 1 fastboot_ready = False for line in self.ser.lines(): if re.search("fastboot: processing commands", line) or \ re.search("Listening for fastboot command on", line): fastboot_ready = True break if re.search("data abort", line): self.print_error( "Detected crash during boot, restarting run...") return 2 if not fastboot_ready: self.print_error( "Failed to get to fastboot prompt, restarting run...") return 2 if self.logged_system(self.fastboot) != 0: return 1 print_more_lines = -1 for line in self.ser.lines(): if print_more_lines == 0: return 2 if print_more_lines > 0: print_more_lines -= 1 if re.search("---. end Kernel panic", line): return 1 # The db820c boards intermittently reboot. Just restart the run # when if we see a reboot after we got past fastboot. if re.search("PON REASON", line): self.print_error( "Detected spontaneous reboot, restarting run...") return 2 # db820c sometimes wedges around iommu fault recovery if re.search("watchdog: BUG: soft lockup - CPU.* stuck", line): self.print_error( "Detected kernel soft lockup, restarting run...") return 2 # If the network device dies, it's probably not graphics's fault, just try again. if re.search("NETDEV WATCHDOG", line): self.print_error( "Detected network device failure, restarting run...") return 2 # A3xx recovery doesn't quite work. Sometimes the GPU will get # wedged and recovery will fail (because power can't be reset?) # This assumes that the jobs are sufficiently well-tested that GPU # hangs aren't always triggered, so just try again. But print some # more lines first so that we get better information on the cause # of the hang. Once a hang happens, it's pretty chatty. if "[drm:adreno_recover] *ERROR* gpu hw init failed: -22" in line: self.print_error("Detected GPU hang, restarting run...") if print_more_lines == -1: print_more_lines = 30 result = re.search("hwci: mesa: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 self.print_error( "Reached the end of the CPU serial log without finding a result, restarting run..." ) return 2
def __init__(self, args): self.powerup = args.powerup self.powerdown = args.powerdown self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "", args.timeout)
class CrosServoRun: def __init__(self, cpu, ec): # Merged FIFO for the two serial buffers, fed by threads. self.serial_queue = queue.Queue() self.sentinel = object() self.threads_done = 0 self.ec_ser = SerialBuffer(ec, "results/serial-ec.txt", "R SERIAL-EC> ") self.cpu_ser = SerialBuffer(cpu, "results/serial.txt", "R SERIAL-CPU> ") self.iter_feed_ec = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.ec_ser.lines(), )) self.iter_feed_ec.start() self.iter_feed_cpu = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.cpu_ser.lines(), )) self.iter_feed_cpu.start() # Feed lines from our serial queues into the merged queue, marking when our # input is done. def iter_feed_queue(self, it): for i in it: self.serial_queue.put(i) self.serial_queue.put(sentinel) # Return the next line from the queue, counting how many threads have # terminated and joining when done def get_serial_queue_line(self): line = self.serial_queue.get() if line == self.sentinel: self.threads_done = self.threads_done + 1 if self.threads_done == 2: self.iter_feed_cpu.join() self.iter_feed_ec.join() return line # Returns an iterator for getting the next line. def serial_queue_lines(self): return iter(self.get_serial_queue_line, self.sentinel) def ec_write(self, s): print("W SERIAL-EC> %s" % s) self.ec_ser.serial.write(s.encode()) def cpu_write(self, s): print("W SERIAL-CPU> %s" % s) self.cpu_ser.serial.write(s.encode()) def run(self): # Flush any partial commands in the EC's prompt, then ask for a reboot. self.ec_write("\n") self.ec_write("reboot\n") # This is emitted right when the bootloader pauses to check for input. # Emit a ^N character to request network boot, because we don't have a # direct-to-netboot firmware on cheza. for line in self.serial_queue_lines(): if re.search("load_archive: loading locale_en.bin", line): self.cpu_write("\016") break # The Cheza boards have issues with failing to bring up power to # the system sometimes, possibly dependent on ambient temperature # in the farm. if re.search("POWER_GOOD not seen in time", line): print( "Detected intermittent poweron failure, restarting run...") return 2 tftp_failures = 0 for line in self.serial_queue_lines(): if re.search("---. end Kernel panic", line): return 1 # The Cheza firmware seems to occasionally get stuck looping in # this error state during TFTP booting, possibly based on amount of # network traffic around it, but it'll usually recover after a # reboot. if re.search("R8152: Bulk read error 0xffffffbf", line): tftp_failures += 1 if tftp_failures >= 100: print( "Detected intermittent tftp failure, restarting run..." ) return 2 result = re.search("bare-metal result: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 print("Reached the end of the CPU serial log without finding a result") return 1
class CrosServoRun: def __init__(self, cpu, ec): # Merged FIFO for the two serial buffers, fed by threads. self.serial_queue = queue.Queue() self.sentinel = object() self.threads_done = 0 self.ec_ser = SerialBuffer(ec, "results/serial-ec.txt", "R SERIAL-EC> ") self.cpu_ser = SerialBuffer(cpu, "results/serial.txt", "R SERIAL-CPU> ") self.iter_feed_ec = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.ec_ser.lines(), )) self.iter_feed_ec.start() self.iter_feed_cpu = threading.Thread(target=self.iter_feed_queue, daemon=True, args=(self.cpu_ser.lines(), )) self.iter_feed_cpu.start() # Feed lines from our serial queues into the merged queue, marking when our # input is done. def iter_feed_queue(self, it): for i in it: self.serial_queue.put(i) self.serial_queue.put(sentinel) # Return the next line from the queue, counting how many threads have # terminated and joining when done def get_serial_queue_line(self): line = self.serial_queue.get() if line == self.sentinel: self.threads_done = self.threads_done + 1 if self.threads_done == 2: self.iter_feed_cpu.join() self.iter_feed_ec.join() return line # Returns an iterator for getting the next line. def serial_queue_lines(self): return iter(self.get_serial_queue_line, self.sentinel) def ec_write(self, s): print("W SERIAL-EC> %s" % s) self.ec_ser.serial.write(s.encode()) def cpu_write(self, s): print("W SERIAL-CPU> %s" % s) self.cpu_ser.serial.write(s.encode()) def run(self): # Flush any partial commands in the EC's prompt, then ask for a reboot. self.ec_write("\n") self.ec_write("reboot\n") # This is emitted right when the bootloader pauses to check for input. # Emit a ^N character to request network boot, because we don't have a # direct-to-netboot firmware on cheza. for line in self.serial_queue_lines(): if re.search("load_archive: loading locale_en.bin", line): self.cpu_write("\016") break # The Cheza boards have issues with failing to bring up power to # the system sometimes, possibly dependent on ambient temperature # in the farm. if re.search("POWER_GOOD not seen in time", line): print( "Detected intermittent poweron failure, restarting run...") return 2 tftp_failures = 0 for line in self.serial_queue_lines(): if re.search("---. end Kernel panic", line): return 1 # The Cheza firmware seems to occasionally get stuck looping in # this error state during TFTP booting, possibly based on amount of # network traffic around it, but it'll usually recover after a # reboot. if re.search("R8152: Bulk read error 0xffffffbf", line): tftp_failures += 1 if tftp_failures >= 100: print( "Detected intermittent tftp failure, restarting run..." ) return 2 # There are very infrequent bus errors during power management transitions # on cheza, which we don't expect to be the case on future boards. if re.search( "Kernel panic - not syncing: Asynchronous SError Interrupt", line): print( "Detected cheza power management bus error, restarting run..." ) return 2 # These HFI response errors started appearing with the introduction # of piglit runs. CosmicPenguin says: # # "message ID 106 isn't a thing, so likely what happened is that we # got confused when parsing the HFI queue. If it happened on only # one run, then memory corruption could be a possible clue" # # Given that it seems to trigger randomly near a GPU fault and then # break many tests after that, just restart the whole run. if re.search( "a6xx_hfi_send_msg.*Unexpected message id .* on the response queue", line): print( "Detected cheza power management bus error, restarting run..." ) return 2 result = re.search("bare-metal result: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 print("Reached the end of the CPU serial log without finding a result") return 1
def __init__(self, cpu, ec): self.ec_ser = SerialBuffer(ec, "artifacts/serial-ec.txt", "R SERIAL-EC> ") self.cpu_ser = SerialBuffer(cpu, "artifacts/serial.txt", "R SERIAL-CPU> ")
class FastbootRun: def __init__(self, args): self.powerup = args.powerup # We would like something like a 1 minute timeout, but the piglit traces # jobs stall out for long periods of time. self.ser = SerialBuffer(args.dev, "results/serial-output.txt", "R SERIAL> ", timeout=600) self.fastboot = "fastboot boot -s {ser} artifacts/fastboot.img".format( ser=args.fbserial) def print_error(self, message): RED = '\033[0;31m' NO_COLOR = '\033[0m' print(RED + message + NO_COLOR) def logged_system(self, cmd): print("Running '{}'".format(cmd)) return os.system(cmd) def run(self): if self.logged_system(self.powerup) != 0: return 1 fastboot_ready = False for line in self.ser.lines(): if re.search("fastboot: processing commands", line) or \ re.search("Listening for fastboot command on", line): fastboot_ready = True break if re.search("data abort", line): self.print_error( "Detected crash during boot, restarting run...") return 2 if not fastboot_ready: self.print_error( "Failed to get to fastboot prompt, restarting run...") return 2 if self.logged_system(self.fastboot) != 0: return 1 for line in self.ser.lines(): if re.search("---. end Kernel panic", line): return 1 # The db820c boards intermittently reboot. Just restart the run # when if we see a reboot after we got past fastboot. if re.search("PON REASON", line): self.print_error( "Detected spontaneous reboot, restarting run...") return 2 # db820c sometimes wedges around iommu fault recovery if re.search("watchdog: BUG: soft lockup - CPU.* stuck", line): self.print_error( "Detected kernel soft lockup, restarting run...") return 2 result = re.search("hwci: mesa: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 self.print_error( "Reached the end of the CPU serial log without finding a result, restarting run..." ) return 2
class CrosServoRun: def __init__(self, cpu, ec, test_timeout): self.cpu_ser = SerialBuffer(cpu, "results/serial.txt", "R SERIAL-CPU> ") # Merge the EC serial into the cpu_ser's line stream so that we can # effectively poll on both at the same time and not have to worry about self.ec_ser = SerialBuffer(ec, "results/serial-ec.txt", "R SERIAL-EC> ", line_queue=self.cpu_ser.line_queue) self.test_timeout = test_timeout def close(self): self.ec_ser.close() self.cpu_ser.close() def ec_write(self, s): print("W SERIAL-EC> %s" % s) self.ec_ser.serial.write(s.encode()) def cpu_write(self, s): print("W SERIAL-CPU> %s" % s) self.cpu_ser.serial.write(s.encode()) def print_error(self, message): RED = '\033[0;31m' NO_COLOR = '\033[0m' print(RED + message + NO_COLOR) def run(self): # Flush any partial commands in the EC's prompt, then ask for a reboot. self.ec_write("\n") self.ec_write("reboot\n") bootloader_done = False # This is emitted right when the bootloader pauses to check for input. # Emit a ^N character to request network boot, because we don't have a # direct-to-netboot firmware on cheza. for line in self.cpu_ser.lines(timeout=120, phase="bootloader"): if re.search("load_archive: loading locale_en.bin", line): self.cpu_write("\016") bootloader_done = True break # If the board has a netboot firmware and we made it to booting the # kernel, proceed to processing of the test run. if re.search("Booting Linux", line): bootloader_done = True break # The Cheza boards have issues with failing to bring up power to # the system sometimes, possibly dependent on ambient temperature # in the farm. if re.search("POWER_GOOD not seen in time", line): self.print_error( "Detected intermittent poweron failure, restarting run...") return 2 if not bootloader_done: print("Failed to make it through bootloader, restarting run...") return 2 tftp_failures = 0 for line in self.cpu_ser.lines(timeout=self.test_timeout, phase="test"): if re.search("---. end Kernel panic", line): return 1 # The Cheza firmware seems to occasionally get stuck looping in # this error state during TFTP booting, possibly based on amount of # network traffic around it, but it'll usually recover after a # reboot. if re.search("R8152: Bulk read error 0xffffffbf", line): tftp_failures += 1 if tftp_failures >= 100: self.print_error( "Detected intermittent tftp failure, restarting run..." ) return 2 # There are very infrequent bus errors during power management transitions # on cheza, which we don't expect to be the case on future boards. if re.search( "Kernel panic - not syncing: Asynchronous SError Interrupt", line): self.print_error( "Detected cheza power management bus error, restarting run..." ) return 2 # If the network device dies, it's probably not graphics's fault, just try again. if re.search("NETDEV WATCHDOG", line): self.print_error( "Detected network device failure, restarting run...") return 2 # These HFI response errors started appearing with the introduction # of piglit runs. CosmicPenguin says: # # "message ID 106 isn't a thing, so likely what happened is that we # got confused when parsing the HFI queue. If it happened on only # one run, then memory corruption could be a possible clue" # # Given that it seems to trigger randomly near a GPU fault and then # break many tests after that, just restart the whole run. if re.search( "a6xx_hfi_send_msg.*Unexpected message id .* on the response queue", line): self.print_error( "Detected cheza power management bus error, restarting run..." ) return 2 if re.search("coreboot.*bootblock starting", line): self.print_error( "Detected spontaneous reboot, restarting run...") return 2 if re.search( "arm-smmu 5040000.iommu: TLB sync timed out -- SMMU may be deadlocked", line): self.print_error("Detected cheza MMU fail, restarting run...") return 2 result = re.search("hwci: mesa: (\S*)", line) if result: if result.group(1) == "pass": return 0 else: return 1 self.print_error( "Reached the end of the CPU serial log without finding a result") return 2
class GPSReader: def __init__(self): self.sb = SerialBuffer("/dev/ttyUSB0", 115200) if not self.sb.is_open(): print "Cannot open port" exit() self.position_pub = rospy.Publisher('/rtk_gps/position', Position, queue_size=10) self.orientation_pub = rospy.Publisher('/rtk_gps/orientation', Orientation, queue_size=10) self.pose_pub = rospy.Publisher('/rtk_gps/pose', Pose, queue_size=10) self.reset_srv = rospy.Service('rtk_gps/reset', Trigger, self.resetCallback) self.position_sub = message_filters.Subscriber('/rtk_gps/position', Position) self.orientation_sub = message_filters.Subscriber( '/rtk_gps/orientation', Orientation) self.sync = message_filters.ApproximateTimeSynchronizer( [self.position_sub, self.orientation_sub], 10, 0.1) self.sync.registerCallback(self.callback) # self.sb.write('JASC,GPGGA,5,PORTA') def spin_once(self): serial_msg = self.sb.spin_once() if serial_msg: self.process(serial_msg) def callback(self, position_msg, orientation_msg): # yaw(z), pitch(x), roll(y) msg = Pose() msg.position.x = position_msg.northing msg.position.y = -position_msg.easting quaternion = tf.transformations.quaternion_from_euler( orientation_msg.pitch, orientation_msg.roll, -orientation_msg.yaw) msg.orientation.x = quaternion[0] msg.orientation.y = quaternion[1] msg.orientation.z = quaternion[2] msg.orientation.w = quaternion[3] self.pose_pub.publish(msg) def resetCallback(self, req): print 'Reset' return TriggerResponse(True, 'Reset') def process(self, msg): if msg[0] == '$PTNL': if len(msg) == 13: mm = Position() try: mm.northing = float(msg[4]) mm.easting = float(msg[6]) mm.height = float(msg[11][3:]) mm.quality = int(msg[8]) mm.fixStatelliteNum = int(msg[9]) mm.fixDOP = float(msg[10]) self.position_pub.publish(mm) except: rospy.logerr('Failed to convert') return else: rospy.logerr( 'Wrong number of $PTNL message: 13 expected but %d given', len(msg)) return elif msg[0] == '$PSAT': if len(msg) != 7: rospy.logerr( 'Wrong number of $PSAT message: 7 expected but %d given', len(msg)) return try: mm = Orientation() mm.yaw = float(msg[3]) / 180.0 * math.pi mm.pitch = float(msg[4]) / 180.0 * math.pi mm.roll = float(msg[5]) / 180.0 * math.pi self.orientation_pub.publish(mm) except: rospy.logwarn('GPS orientation not ready') return
class GPSReader: def __init__(self): self.sb = SerialBuffer("/dev/ttyUSB0", 115200) if not self.sb.is_open(): print "Cannot open port" exit() self.reset_srv = rospy.Service('rtk_gps/reset', Trigger, self.reset_callback) self.pub = rospy.Publisher('/rtk_gps/gps', GPSFix) self.msg = GPSFix() def spin_once(self): serial_msg = self.sb.spin_once() if serial_msg: self.process(serial_msg) def reset_callback(self, req): print 'Reset' return TriggerResponse(True, 'Reset') def process(self, msg): if msg[0] == '$PTNL': if len(msg) == 13: # mm.northing = float(msg[4]) # mm.easting = float(msg[6]) self.msg.err_vert = to_float(msg[4]) self.msg.err_horz = to_float(msg[6]) self.msg.altitude = to_float(msg[11][3:]) quality = to_int(msg[8]) self.msg.status.status = { 0: GPSStatus.STATUS_NO_FIX, 1: GPSStatus.STATUS_FIX, 2: GPSStatus.STATUS_FIX, 3: GPSStatus.STATUS_DGPS_FIX }[quality] self.msg.status.satellites_used = to_int(msg[9]) self.msg.gdop = to_float(msg[10]) else: rospy.logerr( 'Wrong number of $PTNL message: 13 expected but %d given', len(msg)) return elif msg[0] == '$PSAT': if len(msg) != 7: rospy.logerr( 'Wrong number of $PSAT message: 7 expected but %d given', len(msg)) return self.msg.track = to_float(msg[3]) / 180.0 * math.pi self.msg.pitch = to_float(msg[4]) / 180.0 * math.pi self.msg.roll = to_float(msg[5]) / 180.0 * math.pi elif msg[0] == '$GPRMC': if len(msg) != 14: rospy.logerr( 'Wrong number of $GPRMC message: 14 expected but %d given', len(msg)) return if msg[2] == 'V': self.msg.status.status = GPSStatus.STATUS_NO_FIX else: self.msg.latitude = (to_float(msg[3]) if msg[4] == 'N' else -to_float(msg[3])) / 100 self.msg.longitude = (to_float(msg[5]) if msg[6] == 'E' else -to_float(msg[5])) / 100 self.msg.speed = to_float(msg[7]) self.msg.track = to_float(msg[8]) if msg[12] == 'D': self.msg.status.status = GPSStatus.STATUS_DGPS_FIX self.publish() else: rospy.logwarn('Unknown msg:' + str(msg)) return def publish(self): self.msg.header.stamp = rospy.Time.now() self.pub.publish(self.msg)