Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Imports
- import sys
- import keyboard
- from NavInterfaceClient import NavInterfaceClient
- #Login information
- serverHost = "sim.sailsim.org"
- serverPort = 20170
- username = "PinkFlags"
- password = "lagena"
- s="sailAngle"
- b="boatHeading "
- #Logs in if information is correct
- simAPI = NavInterfaceClient(True)
- connected = simAPI.connect(username, password, serverHost, serverPort)
- #Connects and verifies if connected, or verifies that not connected.
- if connected:
- print("Connection established.")
- else:
- print("Connection not established.", file=sys.stderr)
- #Sets the initial boat direction.
- #Confirms that simulation is connected.
- if simAPI.isConnected():
- print("Connection is operational.")
- anchor="up"
- simAPI.send("anchor false")
- simAPI.receive()
- boatheading=33.3
- simAPI.send("boatHeading 33.3")
- simAPI.receive()
- sailangle=25
- simAPI.send("sailAngle 25")
- simAPI.receive()
- simAPI.send("boatPosition")
- bposfull=simAPI.receive()
- bpos=bposfull[1]
- print (bpos)
- bposlist = bpos.split()
- bposx,bposy = bposlist[0],bposlist[1]
- print (bposx)
- print (bposy)
- bposx=float(bposx)
- bposy=float(bposy)
- if((bposx<10)or(bposx>1990)):
- simAPI.send("anchor true")
- simAPI.receive()
- while(True):
- if(keyboard.is_pressed('a')):
- sailangle-=5
- if(sailangle>90):
- sailangle=90
- sailangle = str(sailangle)
- simAPI.send("sailAngle",sailangle)
- simAPI.receive()
- sailangle = int(sailangle)
- if(keyboard.is_pressed('d')):
- sailangle+=5
- if(sailangle<270):
- sailangle=270
- sailangle = str(sailangle)
- simAPI.send("sailAngle",sailangle)
- simAPI.receive()
- sailangle = int(sailangle)
- if(keyboard.is_pressed('w')):
- boatheading-=5
- if(boatheading<0):
- boatheading=boatheading+360
- boatheading = str(boatheading)
- simAPI.send("boatHeading",boatheading)
- simAPI.receive()
- boatheading = float(boatheading)
- if(keyboard.is_pressed('s')):
- boatheading+=5
- if(boatheading>360):
- boatheading=boatheading-360
- boatheading = str(sailangle)
- simAPI.send("boatHeading",boatheading)
- simAPI.receive()
- boatheading = float(boatheading)
- if(keyboard.is_pressed('e')):
- if(anchor=="down"):
- simAPI.send("anchor true")
- simAPI.receive()
- anchor="up"
- elif(anchor=="up"):
- simAPI.send("anchor false")
- simAPI.receive()
- anchor="down"
- #if < 0 = 360
- #if > 360 = 0
Add Comment
Please, Sign In to add comment