def write_seatalk (xx, yy): # thanks to http://www.thomasknauf.de/seatalk.htm with serial.Serial() as ser: ser.baudrate = 4800 ser.port = '/dev/serial0' ser.stopbits=serial.STOPBITS_ONE ser.bytesize=serial.EIGHTBITS ser.open() ser.parity = serial.PARITY_MARK ser.write(b'\x86') ser.parity = serial.PARITY_SPACE ser.write(b'\x11' + chr(int(xx, 16)) + chr(int(yy, 16))) ser.close() angle = 0 previous_angle = 0 def send_command(command): global angle print "command="+str(command) if command == -10: write_seatalk("06", "F9") if command == -1: write_seatalk("05", "FA") if command == +1: write_seatalk("07", "F8") if command == +10: write_seatalk("08", "F7") angle = angle - command def steer_to_angle(angle_to_steer_to): global angle angle = angle_to_steer_to while angle != 0: if angle <= -10: send_command(-10) if angle > -10 and angle < 0: send_command(-1) if angle > 0 and angle < 10: send_command(+1) if angle >= 10: send_command(+10) def steer_into_wind(): global previous_angle try: with open('/tmp/AWA', 'r') as myfile: line = myfile.read().replace("\n", "") awa = int(line) except: awa = 0 angle=(awa+180) % 360-180 previous_angle = angle print "awa=" + str(awa) + "; angle=" + str(angle) steer_to_angle(angle) def steer_previous_angle(): global previous_angle steer_to_angle(-previous_angle)