Advertisement
Dr_Goddard

Seek.ks

Jan 3rd, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 KB | None | 0 0
  1. //KOS
  2. //This is a Kerbal kOS and Infernal Robotics Integration tool by Peter Goddard.
  3. //this script accepts variables for setting groups of robotic segments.
  4. // an example command is seek(0,0) which says move the leg root rotatrons to 0 degrees.
  5. // seek(0 degrees, main rotatron group)
  6. // 0 {SET refmod to ROTMODS1 > Main Rotatrons
  7. // 1 {SET refmod to FOLDMODS1 > First leg segment
  8. // 2 {SET refmod to FOLDMODS2 > Second Leg segment
  9. // 3 {SET refmod to FOLDMODS3 > Third Leg segment
  10. // 4 {SET refmod to ROTMODS2 > Front Main Rotatrons
  11. // 5 {SET refmod to ROTMODS3 > Rear Main Rotatrons
  12. //needless to say there are limits to be observed in setting rotations.
  13. //I will try and code the min/max later maybe.
  14.  
  15. //A few groups have been set out, but more are needed for complex scripts.
  16. //
  17. clearscreen.
  18. declare parameter angle.
  19. declare parameter sel.
  20. set throttle to 0.
  21. //if ag2 = false{ toggle ag2.}
  22. print "DEPLOY IN PROGRESS".
  23.  
  24. //FRont Left Leg names
  25. SET FLext TO SHIP:PARTSTAGGED("FL Extendatron")[0].
  26. SET FLr TO SHIP:PARTSTAGGED("FL Rotatron")[0].
  27. SET FLf1 TO SHIP:PARTSTAGGED("FL Foldatron 1")[0].
  28. SET FLf2 TO SHIP:PARTSTAGGED("FL Foldatron 2")[0].
  29. SET FLf3 TO SHIP:PARTSTAGGED("FL Foldatron 3")[0].
  30.  
  31. //FRont Right Leg names
  32. SET FRext TO SHIP:PARTSTAGGED("FR Extendatron")[0].
  33. SET FRr TO SHIP:PARTSTAGGED("FR Rotatron")[0].
  34. SET FRf1 TO SHIP:PARTSTAGGED("FR Foldatron 1")[0].
  35. SET FRf2 TO SHIP:PARTSTAGGED("FR Foldatron 2")[0].
  36. SET FRf3 TO SHIP:PARTSTAGGED("FR Foldatron 3")[0].
  37.  
  38. //Rear Left leg names
  39. SET RLext TO SHIP:PARTSTAGGED("RL Extendatron")[0].
  40. SET RLr TO SHIP:PARTSTAGGED("RL Rotatron")[0].
  41. SET RLf1 TO SHIP:PARTSTAGGED("RL Foldatron 1")[0].
  42. SET RLf2 TO SHIP:PARTSTAGGED("RL Foldatron 2")[0].
  43. SET RLf3 TO SHIP:PARTSTAGGED("RL Foldatron 3")[0].
  44.  
  45. ///Rear Right leg names
  46. SET RRext TO SHIP:PARTSTAGGED("RR Extendatron")[0].
  47. SET RRr TO SHIP:PARTSTAGGED("RR Rotatron")[0].
  48. SET RRf1 TO SHIP:PARTSTAGGED("RR Foldatron 1")[0].
  49. SET RRf2 TO SHIP:PARTSTAGGED("RR Foldatron 2")[0].
  50. SET RRf3 TO SHIP:PARTSTAGGED("RR Foldatron 3")[0].
  51.  
  52. //Mid Left leg names
  53. SET MLext TO SHIP:PARTSTAGGED("ML Extendatron")[0].
  54. SET MLr TO SHIP:PARTSTAGGED("ML Rotatron")[0].
  55. SET MLf1 TO SHIP:PARTSTAGGED("ML Foldatron 1")[0].
  56. SET MLf2 TO SHIP:PARTSTAGGED("ML Foldatron 2")[0].
  57. SET MLf3 TO SHIP:PARTSTAGGED("ML Foldatron 3")[0].
  58.  
  59. //Mid Right leg names
  60. SET MRext TO SHIP:PARTSTAGGED("MR Extendatron")[0].
  61. SET MRr TO SHIP:PARTSTAGGED("MR Rotatron")[0].
  62. SET MRf1 TO SHIP:PARTSTAGGED("MR Foldatron 1")[0].
  63. SET MRf2 TO SHIP:PARTSTAGGED("MR Foldatron 2")[0].
  64. SET MRf3 TO SHIP:PARTSTAGGED("MR Foldatron 3")[0].
  65.  
  66. //Create group lists for parts to act together
  67. //extgroup1 is the list of ALL the extendatrons.
  68. SET extgroup1 TO list().
  69. extgroup1:ADD(FRext).
  70. extgroup1:ADD(FLext).
  71. extgroup1:ADD(RRext).
  72. extgroup1:ADD(RLext).
  73. extgroup1:ADD(MRext).
  74. extgroup1:ADD(MLext).
  75. // A corresponding list of all the mumechtoggle's attached to those parts:
  76. SET EXTMODS1 TO LIST().
  77. FOR L IN extgroup1 {EXTMODS1:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  78.  
  79. //extgroup2 is the list of the extendatrons at the 4 corners.
  80. SET extgroup2 TO list().
  81. extgroup2:ADD(FRext).
  82. extgroup2:ADD(FLext).
  83. extgroup2:ADD(RRext).
  84. extgroup2:ADD(RLext).
  85. // A corresponding list of all the mumechtoggle's attached to those parts:
  86. SET EXTMODS2 TO LIST().
  87. FOR L IN extgroup2 {EXTMODS2:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  88.  
  89. //extgroup3 is the list of the extendatrons at the middle sides
  90. SET extgroup3 TO list().
  91. extgroup3:ADD(MRext).
  92. extgroup3:ADD(MLext).
  93. // A corresponding list of all the mumechtoggle's attached to those parts:
  94. SET EXTMODS3 TO LIST().
  95. FOR L IN extgroup3 {EXTMODS3:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  96.  
  97. //rotgroup1 is the list of ALL base rotatrons.
  98. SET rotgroup1 TO list().
  99. rotgroup1:ADD(FLr).
  100. rotgroup1:ADD(FRr).
  101. rotgroup1:ADD(MLr).
  102. rotgroup1:ADD(MRr).
  103. rotgroup1:ADD(RRr).
  104. rotgroup1:ADD(RLr).
  105. // A corresponding list of all the mumechtoggle's attached to those parts:
  106. SET ROTMODS1 TO LIST().
  107. FOR L IN rotgroup1 {ROTMODS1:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  108.  
  109. //rotgroup2 is the list of the rotatrons at the front corners.
  110. SET rotgroup2 TO list().
  111. rotgroup2:ADD(FLr).
  112. rotgroup2:ADD(FRr).
  113. // A corresponding list of all the mumechtoggle's attached to those parts:
  114. SET ROTMODS2 TO LIST().
  115. FOR L IN rotgroup2 {ROTMODS2:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  116.  
  117. //rotgroup3 is the list of the rotatrons at the rear corners.
  118. SET rotgroup3 TO list().
  119. rotgroup3:ADD(RLr).
  120. rotgroup3:ADD(RRr).
  121. // A corresponding list of all the mumechtoggle's attached to those parts:
  122. SET ROTMODS3 TO LIST().
  123. FOR L IN rotgroup3 {ROTMODS3:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  124.  
  125.  
  126. //foldgroup1 is the list of ALL joint 1 foldatrons.
  127. SET foldgroup1 TO list().
  128. foldgroup1:ADD(FLf1).
  129. foldgroup1:ADD(FRf1).
  130. foldgroup1:ADD(MLf1).
  131. foldgroup1:ADD(MRf1).
  132. foldgroup1:ADD(RLf1).
  133. foldgroup1:ADD(RRf1).
  134. // A corresponding list of all the mumechtoggle's attached to those parts:
  135. SET foldmods1 TO LIST().
  136. FOR L IN foldgroup1 {foldmods1:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  137.  
  138.  
  139. //foldgroup2 is the list of ALL joint 2 foldatrons.
  140. SET foldgroup2 TO list().
  141. foldgroup2:ADD(FLf2).
  142. foldgroup2:ADD(FRf2).
  143. foldgroup2:ADD(MLf2).
  144. foldgroup2:ADD(MRf2).
  145. foldgroup2:ADD(RLf2).
  146. foldgroup2:ADD(RRf2).
  147. // A corresponding list of all the mumechtoggle's attached to those parts:
  148. SET FOLDMODS2 TO LIST().
  149. FOR L IN foldgroup2 {FOLDMODS2:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  150.  
  151. //foldgroup3 is the list of ALL joint 3 foldatrons.
  152. SET foldgroup3 TO list().
  153. foldgroup3:ADD(FLf3).
  154. foldgroup3:ADD(FRf3).
  155. foldgroup3:ADD(MLf3).
  156. foldgroup3:ADD(MRf3).
  157. foldgroup3:ADD(RLf3).
  158. foldgroup3:ADD(RRf3).
  159. // A corresponding list of all the mumechtoggle's attached to those parts:
  160. SET FOLDMODS3 TO LIST().
  161. FOR L IN foldgroup3{FOLDMODS3:ADD(L:GETMODULE("MUMECHTOGGLE")). }.
  162.  
  163. ///set variables according to command line RUN SEEK(angle in degrees,servo#)////
  164. If sel = 0 {SET refmod to ROTMODS1.} ELSE IF sel = 1 {SET refmod to FOLDMODS1.} ELSE IF sel = 2 {SET refmod to FOLDMODS2.}ELSE IF sel = 3 {SET refmod to FOLDMODS3.} ELSE IF sel = 4 {SET refmod to ROTMODS2.} ELSE IF sel = 5 {SET refmod to ROTMODS3.}
  165. SET x to 0.
  166. SET TEST to 0.
  167. SET BYE to 0.
  168. UNTIL x =1{
  169. SET TIMECHECK TO TIME:SECONDS.
  170. WAIT UNTIL TIME:SECONDS > TIMECHECK. // Force a physics tick to pass here.
  171. SET INDEX to 0.
  172. UNTIL INDEX >= refmod:LENGTH{ //loop for the number of items in the list
  173.  
  174. SET RMOD TO refmod[INDEX].//get the current item from the list
  175. //gather some rotation angle information
  176. SET CURRENTPOS TO RMOD:GETFIELD("rotation:").
  177. SET DELTA TO round(ABS(CURRENTPOS - ANGLE ),2).//difference between where I am and where I want to be.
  178.  
  179. // ramp up and ramp down speed for realism and accuracy setting the delta mutiplier to a bigger number shortens the curve. 2 or 3, not 500.
  180. RMOD:SETFIELD("fine speed", -0.08).
  181. RMOD:SETFIELD("coarse speed", MIN(3,DELTA*.15)).
  182. //Stopping accuracy is a tradeoff. Parts oscillate when they come to a stop and this increses with speed. In the following line, changing the DELTA <=X.XX will change the accuracy of your angles. The number is in degrees. For some actions the speed of the routine is greatly improved by giving a larger number (0.5 to 1.5) Smaller numbers give it the jitters as it bounces back and forth, and it takes forever to succeed. Remember you are confirming up to 6 leg positions at once.
  183. IF DELTA <=0.05 {//if it reaches seekpoint then stop
  184. RMOD:DOACTION("MOVE -",false).
  185. RMOD:DOACTION("MOVE +",false).
  186. SET test to 1.//adds a token to the stack saying "I am here"
  187. }
  188. ELSE IF CURRENTPOS < ANGLE {//move to seek angle +
  189. RMOD:DOACTION("MOVE -",false).
  190. RMOD:DOACTION("MOVE +",true).
  191. }
  192. ELSE IF CURRENTPOS > ANGLE {//move to seek angle -
  193. RMOD:DOACTION("MOVE -",true).
  194. RMOD:DOACTION("MOVE +",false).
  195. }
  196. ELSE {//if nothing triggers do nothing(probably not necessary)
  197. RMOD:DOACTION("MOVE -",false).
  198. RMOD:DOACTION("MOVE +",false).
  199. }.
  200. IF test = 1 {set bye to bye+1. // count up if token set
  201. RMOD:DOACTION("MOVE -",false).
  202. RMOD:DOACTION("MOVE +",false).
  203. }
  204. IF bye = 6 set x to x+1.//if the tokens ever add up to the value if INDEX then all the jpoints have reached the seekpoint.
  205.  
  206. //remove comment for debug
  207. //print delta" "+bye+" "+test.
  208.  
  209. SET INDEX TO INDEX + 1.
  210. }
  211.  
  212. }
  213. //wanted
  214. //////seeking routine for leg proportional movement//////////
  215. ////adapt self leveling routine
  216. ///add logic for extendatrons... should be easy
  217. //create a splash screen with instructions
  218. //create more movement routines
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement