Guest User

Untitled

a guest
Feb 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #Imports
  2. import sys
  3. import keyboard
  4. from NavInterfaceClient import NavInterfaceClient
  5.  
  6. #Login information
  7. serverHost = "sim.sailsim.org"
  8. serverPort = 20170
  9. username = "PinkFlags"
  10. password = "lagena"
  11. s="sailAngle"
  12. b="boatHeading "
  13. #Logs in if information is correct
  14. simAPI = NavInterfaceClient(True)
  15. connected = simAPI.connect(username, password, serverHost, serverPort)
  16.  
  17. #Connects and verifies if connected, or verifies that not connected.
  18. if connected:
  19. print("Connection established.")
  20. else:
  21. print("Connection not established.", file=sys.stderr)
  22.  
  23. #Sets the initial boat direction.
  24.  
  25. #Confirms that simulation is connected.
  26. if simAPI.isConnected():
  27. print("Connection is operational.")
  28.  
  29. anchor="up"
  30. simAPI.send("anchor false")
  31. simAPI.receive()
  32.  
  33. boatheading=33.3
  34. simAPI.send("boatHeading 33.3")
  35. simAPI.receive()
  36.  
  37. sailangle=25
  38. simAPI.send("sailAngle 25")
  39. simAPI.receive()
  40.  
  41.  
  42.  
  43. simAPI.send("boatPosition")
  44. bposfull=simAPI.receive()
  45. bpos=bposfull[1]
  46. print (bpos)
  47. bposlist = bpos.split()
  48. bposx,bposy = bposlist[0],bposlist[1]
  49. print (bposx)
  50. print (bposy)
  51. bposx=float(bposx)
  52. bposy=float(bposy)
  53.  
  54. if((bposx<10)or(bposx>1990)):
  55. simAPI.send("anchor true")
  56. simAPI.receive()
  57.  
  58. while(True):
  59. if(keyboard.is_pressed('a')):
  60. sailangle-=5
  61. if(sailangle>90):
  62. sailangle=90
  63. sailangle = str(sailangle)
  64. simAPI.send("sailAngle",sailangle)
  65. simAPI.receive()
  66. sailangle = int(sailangle)
  67. if(keyboard.is_pressed('d')):
  68. sailangle+=5
  69. if(sailangle<270):
  70. sailangle=270
  71. sailangle = str(sailangle)
  72. simAPI.send("sailAngle",sailangle)
  73. simAPI.receive()
  74. sailangle = int(sailangle)
  75.  
  76.  
  77. if(keyboard.is_pressed('w')):
  78. boatheading-=5
  79. if(boatheading<0):
  80. boatheading=boatheading+360
  81. boatheading = str(boatheading)
  82. simAPI.send("boatHeading",boatheading)
  83. simAPI.receive()
  84. boatheading = float(boatheading)
  85. if(keyboard.is_pressed('s')):
  86. boatheading+=5
  87. if(boatheading>360):
  88. boatheading=boatheading-360
  89. boatheading = str(sailangle)
  90. simAPI.send("boatHeading",boatheading)
  91. simAPI.receive()
  92. boatheading = float(boatheading)
  93.  
  94. if(keyboard.is_pressed('e')):
  95. if(anchor=="down"):
  96. simAPI.send("anchor true")
  97. simAPI.receive()
  98. anchor="up"
  99. elif(anchor=="up"):
  100. simAPI.send("anchor false")
  101. simAPI.receive()
  102. anchor="down"
  103.  
  104.  
  105. #if < 0 = 360
  106. #if > 360 = 0
Add Comment
Please, Sign In to add comment