def mainSailAngle(): windAngle = analogTest.readadc(potentiometer_adc, SPICLK, SPIMOSI, SPIMISO, SPICS) print("Wind Dir: " + str(windAngle)) angle = (0.0068 * windAngle - (0.6428 + (math.pi / 2))) if angle < 0: angle = (2 * math.pi) + angle # equation abs(-180*sin(radians)+150) calulates main sail angle from wind angle radians #mainSail = abs(-180*math.sin(angle) + 150) mainSail = angle moveservo.main(mainsail_channel, int((mainSail * 180) / math.pi)) print("Wind Angle: " + str((angle * 180) / math.pi)) print("Mainsail Angle: " + str((mainSail * 180) / math.pi))
def turnBoat(dir): if dir == 'left': moveservo.main(rudder_channel, 437) if dir == 'right': moveservo.main(rudder_channel, 337) if dir == 'straight': moveservo.main(rudder_channel, 387)
def main(): global command servo_one_sig = 387 servo_two_sig = 387 servo_three_sig = 400 threading1 = threading.Thread(target=getCommand) threading1.start() mainsail_channel = 4 aftsail_channel = 5 rudder_channel = 3 move_by = 30 # moveservo.main(mainsail_channel, 387) # moveservo.main(aftsail_channel, 387) # moveservo.main(rudder_channel, 400) while True: if not command: print "main: empty" else: print "main: " + command #Commands to move servos if command == "1" and servo_three_sig > 225: servo_three_sig -= move_by moveservo.main(mainsail_channel, servo_three_sig) if command == "2" and servo_three_sig > 225: servo_three_sig = 400 moveservo.main(mainsail_channel, servo_three_sig) if command == "3" and servo_three_sig < 575: servo_three_sig += move_by moveservo.main(mainsail_channel, servo_three_sig) if command == "4" and servo_two_sig > 200: servo_two_sig -= move_by moveservo.main(aftsail_channel, servo_two_sig) if command == "5" and servo_three_sig > 225: servo_three_sig = 387 moveservo.main(aftsail_channel, servo_three_sig) if command == "6" and servo_two_sig < 575: servo_two_sig += move_by moveservo.main(aftsail_channel, servo_two_sig) if command == "7" and servo_one_sig > 200: servo_one_sig -= move_by moveservo.main(rudder_channel, servo_one_sig) if command == "8" and servo_three_sig > 225: servo_three_sig = 387 moveservo.main(rudder_channel, servo_three_sig) if command == "9" and servo_one_sig < 575: servo_one_sig += move_by moveservo.main(rudder_channel, servo_one_sig) rfSend("Connected") displaySensorInfo()
# calculates main sail angle depending on angle of wind direction sensor def mainSailAngle(): windAngle = analogTest.readadc(potentiometer_adc, SPICLK, SPIMOSI, SPIMISO, SPICS) print("Wind Dir: " + str(windAngle)) angle = (0.0068 * windAngle - (0.6428 + (math.pi / 2))) if angle < 0: angle = (2 * math.pi) + angle # equation abs(-180*sin(radians)+150) calulates main sail angle from wind angle radians #mainSail = abs(-180*math.sin(angle) + 150) mainSail = angle moveservo.main(mainsail_channel, int((mainSail * 180) / math.pi)) print("Wind Angle: " + str((angle * 180) / math.pi)) print("Mainsail Angle: " + str((mainSail * 180) / math.pi)) # first move main sail to neutral position moveservo.main(mainsail_channel, 360) time.sleep(3) while True: mainSailAngle() time.sleep(0.5)