# Change throttle direction when limit reached if self.throttle <= 0: self.throttledir = +1 elif self.throttle >= 1: self.throttledir = -1 else: self.offtime = time.time() - self.timestart self.c5prev = c5 port.write(self.request) getter = Getter() setter = SetterThread(getter) setter.start() while True: try: parser.parse(port.read(1)) except KeyboardInterrupt: break
request = serialize_STATE_Request() sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) sock.connect((BD_ADDR, BD_PORT)) print('connected to ' + BD_ADDR) def handler(altitude, variometer, positionX, positionY, heading, velocityForward, velocityRightward): print(altitude, variometer, positionX, positionY, heading, velocityForward, velocityRightward) sock.send(request) parser.set_STATE_Handler(handler) sock.send(request) while True: try: parser.parse(sock.recv(1)) except KeyboardInterrupt: sock.close() break
import serial from sys import argv def handler(pitch, roll, yaw): print(pitch, roll, yaw) port.write(request) if __name__ == '__main__': parser = Parser() request = serialize_ATTITUDE_RADIANS_Request() port = serial.Serial(PORT, BAUD) parser.set_ATTITUDE_RADIANS_Handler(handler) port.write(request) while True: try: parser.parse(port.read(1)) except KeyboardInterrupt: break
PORT = '/dev/ttyACM0' import serial from msppg import MSP_Parser def handler(agl, flowx, flowy): print(agl, flowx, flowy) port = serial.Serial(PORT, 115200) parser = MSP_Parser() parser.set_RANGE_AND_FLOW_Handler(handler) while True: c = None try: c = port.read() except KeyboardInterrupt: port.close() break parser.parse(c)