robot.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. 'use strict';
  2. goog.provide('Blockly.Python.robot');
  3. goog.require('Blockly.Python');
  4. /* Blockly.Python['robot_biped_init'] = function(block) {
  5. var text_pin_11 = block.getFieldValue('pin_11');
  6. var text_pin_10 = block.getFieldValue('pin_10');
  7. var text_pin_9 = block.getFieldValue('pin_9');
  8. var text_pin_6 = block.getFieldValue('pin_6');
  9. var text_pin_rr = block.getFieldValue('pin_rr');
  10. var text_pin_rl = block.getFieldValue('pin_rl');
  11. var text_pin_yr = block.getFieldValue('pin_yr');
  12. var text_pin_yl = block.getFieldValue('pin_yl');
  13. var text_intervaltime = block.getFieldValue('intervaltime');
  14. var robot_biped_pin = '#define PIN_RR ' + text_pin_rr +
  15. '\n#define PIN_RL ' + text_pin_rl +
  16. '\n#define PIN_YR ' + text_pin_yr +
  17. '\n#define PIN_YL ' + text_pin_yl +
  18. '\n#define INTERVALTIME ' + text_intervaltime + '\n';
  19. Blockly.Python.addDeclaration('robot_biped_pin', robot_biped_pin);
  20. var robot_biped_decl = '#include <Servo.h>\n' +
  21. '#include <Oscillator.h>\n' +
  22. '#include <EEPROM.h>\n' +
  23. '#define N_SERVOS 4\n' +
  24. '\n' +
  25. '//-- First step: Configure the pins where the servos are attached\n' +
  26. '/*\n' +
  27. ' --------------- \n' +
  28. ' | O O |\n' +
  29. ' |---------------|\n' +
  30. 'YR 3==> | | <== YL 2\n' +
  31. ' --------------- \n' +
  32. ' || ||\n' +
  33. ' || ||\n' +
  34. 'RR 5==> ----- ------ <== RL 4\n' +
  35. ' |----- ------|\n' +
  36. '\n' +
  37. '#define EEPROM_TRIM false \n' +
  38. '\n' +
  39. '// Activate to take callibration data from internal memory\n' +
  40. '#define TRIM_RR 7\n' +
  41. '#define TRIM_RL 4\n' +
  42. '#define TRIM_YR 4\n' +
  43. '#define TRIM_YL -7\n' +
  44. '//OTTO.setTrims(-7,-4,-4,7);\n' +
  45. 'Oscillator servo[N_SERVOS];\n'+
  46. '\n' +
  47. 'void goingUp(int tempo);\n' +
  48. 'void drunk (int tempo);\n' +
  49. 'void noGravity(int tempo);\n' +
  50. 'void kickLeft(int tempo);\n' +
  51. 'void kickRight(int tempo);\n' +
  52. 'void run(int steps, int T=500);\n' +
  53. 'void walk(int steps, int T=1000);\n' +
  54. 'void backyard(int steps, int T=3000);\n' +
  55. 'void backyardSlow(int steps, int T=5000);\n' +
  56. 'void turnLeft(int steps, int T=3000);\n' +
  57. 'void turnRight(int steps, int T=3000);\n' +
  58. 'void moonWalkLeft(int steps, int T=1000);\n' +
  59. 'void moonWalkRight(int steps, int T=1000);\n' +
  60. 'void crusaito(int steps, int T=1000);\n' +
  61. 'void swing(int steps, int T=1000);\n' +
  62. 'void upDown(int steps, int T=1000);\n' +
  63. 'void flapping(int steps, int T=1000);\n' +
  64. '//Tempo\n' +
  65. 'int t=495;\n'+
  66. 'double pause=0;\n';
  67. Blockly.Python.addDeclaration('robot_biped_decl', robot_biped_decl);
  68. var robot_biped_setup = 'Serial.begin(19200);\n' +
  69. ' servo[0].attach(PIN_RR);\n' +
  70. ' servo[1].attach(PIN_RL);\n' +
  71. ' servo[2].attach(PIN_YR);\n' +
  72. ' servo[3].attach(PIN_YL);\n' +
  73. ' \n' +
  74. ' int trim;\n' +
  75. ' \n' +
  76. ' if(EEPROM_TRIM){\n' +
  77. ' for(int x=0;x<4;x++){\n' +
  78. ' trim=EEPROM.read(x);\n' +
  79. ' if(trim>128)trim=trim-256;\n' +
  80. ' Serial.print("TRIM ");\n' +
  81. ' Serial.print(x);\n' +
  82. ' Serial.print(" en ");\n' +
  83. ' Serial.println(trim);\n' +
  84. ' servo[x].SetTrim(trim);\n' +
  85. ' }\n' +
  86. ' }\n' +
  87. ' else{\n' +
  88. ' servo[0].SetTrim(TRIM_RR);\n' +
  89. ' servo[1].SetTrim(TRIM_RL);\n' +
  90. ' servo[2].SetTrim(TRIM_YR);\n' +
  91. ' servo[3].SetTrim(TRIM_YL);\n' +
  92. ' }\n' +
  93. ' \n' +
  94. ' for(int i=0;i<3;i++) { servo[i].SetPosition(90); }\n' +
  95. ' servo[3].SetPosition(20);\n';
  96. Blockly.Python.addSetup('robot_biped_setup', robot_biped_setup);
  97. //load all robot's actions
  98. var robot_biped_oscillate ='void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){\n' +
  99. ' for (int i=0; i<4; i++) {\n' +
  100. ' servo[i].SetO(O[i]);\n' +
  101. ' servo[i].SetA(A[i]);\n' +
  102. ' servo[i].SetT(T);\n' +
  103. ' servo[i].SetPh(phase_diff[i]);\n' +
  104. ' }\n' +
  105. ' double ref=millis();\n' +
  106. ' for (double x=ref; x<T+ref; x=millis()){\n' +
  107. ' for (int i=0; i<4; i++){\n' +
  108. ' servo[i].refresh();\n' +
  109. ' }\n' +
  110. ' }\n' +
  111. '}\n';
  112. Blockly.Python.addFunction('robot_biped_oscillate', robot_biped_oscillate);
  113. //moveNServos needs more declaration
  114. var robot_biped_moveNServos_decl = 'unsigned long final_time;\n' +
  115. 'unsigned long interval_time;\n' +
  116. 'int oneTime;\n' +
  117. 'int iteration;\n' +
  118. 'float increment[N_SERVOS]; \n' +
  119. 'int oldPosition[]={90,90,90,90};\n';
  120. Blockly.Python.addDeclaration('robot_biped_moveNServos_decl',robot_biped_moveNServos_decl);
  121. var robot_biped_moveNServos = 'void moveNServos(int time, int newPosition[]){\n' +
  122. ' for(int i=0;i<N_SERVOS;i++) increment[i] = ((newPosition[i])-oldPosition[i])/(time/INTERVALTIME);\n' +
  123. ' \n' +
  124. ' final_time = millis() + time; \n' +
  125. ' \n' +
  126. ' iteration = 1; \n' +
  127. ' while(millis() < final_time){ //Javi del futuro cambia esto \n' +
  128. ' interval_time = millis()+INTERVALTIME; \n' +
  129. ' \n' +
  130. ' oneTime=0; \n' +
  131. ' while(millis()<interval_time){ \n' +
  132. ' if(oneTime<1){ \n' +
  133. ' for(int i=0;i<N_SERVOS;i++){\n' +
  134. ' servo[i].SetPosition(oldPosition[i] + (iteration * increment[i]));\n' +
  135. ' } \n' +
  136. ' iteration++;\n' +
  137. ' oneTime++;\n' +
  138. ' }\n' +
  139. ' } \n' +
  140. ' } \n' +
  141. '\n' +
  142. ' for(int i=0;i<N_SERVOS;i++){ \n' +
  143. ' oldPosition[i] = newPosition[i];\n' +
  144. ' } \n' +
  145. '}\n';
  146. Blockly.Python.addFunction('robot_biped_moveNServos', robot_biped_moveNServos);
  147. var robot_biped_goingUp = 'void goingUp(int tempo){\n' +
  148. ' \n' +
  149. ' pause=millis();\n' +
  150. ' for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  151. ' delay(tempo);\n' +
  152. ' servo[0].SetPosition(80);\n' +
  153. ' servo[1].SetPosition(100);\n' +
  154. ' delay(tempo);\n' +
  155. ' servo[0].SetPosition(70);\n' +
  156. ' servo[1].SetPosition(110);\n' +
  157. ' delay(tempo);\n' +
  158. ' servo[0].SetPosition(60);\n' +
  159. ' servo[1].SetPosition(120);\n' +
  160. ' delay(tempo);\n' +
  161. ' servo[0].SetPosition(50);\n' +
  162. ' servo[1].SetPosition(130);\n' +
  163. ' delay(tempo);\n' +
  164. ' servo[0].SetPosition(40);\n' +
  165. ' servo[1].SetPosition(140);\n' +
  166. ' delay(tempo);\n' +
  167. ' servo[0].SetPosition(30);\n' +
  168. ' servo[1].SetPosition(150);\n' +
  169. ' delay(tempo);\n' +
  170. ' servo[0].SetPosition(20);\n' +
  171. ' servo[1].SetPosition(160);\n' +
  172. ' delay(tempo);\n' +
  173. ' \n' +
  174. ' while(millis()<pause+8*t);\n' +
  175. '}\n';
  176. Blockly.Python.addFunction('robot_biped_goingUp', robot_biped_goingUp);
  177. var robot_biped_drunk = 'void drunk (int tempo){\n' +
  178. ' pause=millis();\n' +
  179. ' \n' +
  180. ' int move1[] = {60,70,90,90};\n' +
  181. ' int move2[] = {110,120,90,90};\n' +
  182. ' int move3[] = {60,70,90,90};\n' +
  183. ' int move4[] = {110,120,90,90};\n' +
  184. ' \n' +
  185. ' moveNServos(tempo*0.235,move1);\n' +
  186. ' moveNServos(tempo*0.235,move2);\n' +
  187. ' moveNServos(tempo*0.235,move3);\n' +
  188. ' moveNServos(tempo*0.235,move4);\n' +
  189. ' while(millis()<(pause+tempo));\n' +
  190. '}\n';
  191. Blockly.Python.addFunction('robot_biped_drunk', robot_biped_drunk);
  192. var robot_biped_noGavity = 'void noGravity(int tempo){ \n' +
  193. ' int move1[4] = {120,140,90,90};\n' +
  194. ' int move2[4] = {140,140,90,90};\n' +
  195. ' int move3[4] = {120,140,90,90};\n' +
  196. ' int move4[4] = {90,90,90,90};\n' +
  197. ' \n' +
  198. ' for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  199. ' for(int i=0;i<N_SERVOS;i++) oldPosition[i]=90;\n' +
  200. ' moveNServos(tempo*2,move1);\n' +
  201. ' moveNServos(tempo*2,move2);\n' +
  202. ' delay(tempo*2);\n' +
  203. ' moveNServos(tempo*2,move3);\n' +
  204. ' moveNServos(tempo*2,move4);\n' +
  205. '}\n';
  206. Blockly.Python.addFunction('robot_biped_noGavity', robot_biped_noGavity);
  207. var robot_biped_kickRight = 'void kickRight(int tempo){\n' +
  208. 'for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  209. ' delay(tempo);\n' +
  210. ' servo[0].SetPosition(110); //pie derecho\n' +
  211. ' servo[1].SetPosition(130); //pie izquiero\n' +
  212. ' delay(tempo);\n' +
  213. ' servo[0].SetPosition(110); //pie derecho\n' +
  214. ' servo[1].SetPosition(100); //pie izquiero\n' +
  215. ' delay(tempo/4);\n' +
  216. ' servo[0].SetPosition(110); //pie derecho\n' +
  217. ' servo[1].SetPosition(150); //pie izquiero\n' +
  218. ' delay(tempo/4);\n' +
  219. ' servo[0].SetPosition(110); //pie derecho\n' +
  220. ' servo[1].SetPosition(80); //pie izquiero\n' +
  221. ' delay(tempo/4);\n' +
  222. ' servo[0].SetPosition(110); //pie derecho\n' +
  223. ' servo[1].SetPosition(150); //pie izquiero\n' +
  224. ' delay(tempo/4);\n' +
  225. ' servo[0].SetPosition(110); //pie derecho\n' +
  226. ' servo[1].SetPosition(100); //pie izquiero\n' +
  227. ' delay(tempo);\n' +
  228. '}\n';
  229. Blockly.Python.addFunction('robot_biped_kickRight', robot_biped_kickRight);
  230. var robot_biped_kickLeft = 'void kickLeft(int tempo){\n' +
  231. ' for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  232. ' delay(tempo);\n' +
  233. ' servo[0].SetPosition(50); //pie derecho\n' +
  234. ' servo[1].SetPosition(70); //pie izquiero\n' +
  235. ' delay(tempo);\n' +
  236. ' servo[0].SetPosition(80); //pie derecho\n' +
  237. ' servo[1].SetPosition(70); //pie izquiero\n' +
  238. ' delay(tempo/4);\n' +
  239. ' servo[0].SetPosition(30); //pie derecho\n' +
  240. ' servo[1].SetPosition(70); //pie izquiero\n' +
  241. ' delay(tempo/4);\n' +
  242. ' servo[0].SetPosition(80); //pie derecho\n' +
  243. ' servo[1].SetPosition(70); //pie izquiero\n' +
  244. ' delay(tempo/4);\n' +
  245. ' servo[0].SetPosition(30); //pie derecho\n' +
  246. ' servo[1].SetPosition(70); //pie izquiero\n' +
  247. ' delay(tempo/4);\n' +
  248. ' servo[0].SetPosition(80); //pie derecho\n' +
  249. ' servo[1].SetPosition(70); //pie izquiero\n' +
  250. ' delay(tempo);\n' +
  251. '}\n';
  252. Blockly.Python.addFunction('robot_biped_kickLeft', robot_biped_kickLeft);
  253. var robot_biped_walk = 'void walk(int steps, int T){\n' +
  254. ' int A[4]= {15, 15, 30, 30};\n' +
  255. ' int O[4] = {0, 0, 0, 0};\n' +
  256. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n' +
  257. ' \n' +
  258. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  259. '}\n';
  260. Blockly.Python.addFunction('robot_biped_walk', robot_biped_walk);
  261. var robot_biped_run = 'void run(int steps, int T){\n' +
  262. ' int A[4]= {10, 10, 10, 10};\n' +
  263. ' int O[4] = {0, 0, 0, 0};\n' +
  264. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; \n' +
  265. ' \n' +
  266. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  267. '}\n';
  268. Blockly.Python.addFunction('robot_biped_run', robot_biped_run);
  269. var robot_biped_backyard = 'void backyard(int steps, int T){\n' +
  270. ' int A[4]= {15, 15, 30, 30};\n' +
  271. ' int O[4] = {0, 0, 0, 0};\n' +
  272. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)}; \n' +
  273. ' \n' +
  274. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  275. '}\n';
  276. Blockly.Python.addFunction('robot_biped_backyard', robot_biped_backyard);
  277. var robot_biped_backyardSlow = 'void backyardSlow(int steps, int T){\n' +
  278. ' int A[4]= {15, 15, 30, 30};\n' +
  279. ' int O[4] = {0, 0, 0, 0};\n' +
  280. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)}; \n' +
  281. ' \n' +
  282. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  283. '}\n';
  284. Blockly.Python.addFunction('robot_biped_backyardSlow', robot_biped_backyardSlow);
  285. var robot_biped_turnLeft = 'void turnLeft(int steps, int T){\n' +
  286. ' int A[4]= {20, 20, 10, 30};\n' +
  287. ' int O[4] = {0, 0, 0, 0};\n' +
  288. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; \n' +
  289. ' \n' +
  290. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  291. '}\n';
  292. Blockly.Python.addFunction('robot_biped_turnLeft', robot_biped_turnLeft);
  293. var robot_biped_turnRight = 'void turnRight(int steps, int T){\n' +
  294. ' int A[4]= {20, 20, 30, 10};\n' +
  295. ' int O[4] = {0, 0, 0, 0};\n' +
  296. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; \n' +
  297. ' \n' +
  298. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  299. '}\n';
  300. Blockly.Python.addFunction('robot_biped_turnRight', robot_biped_turnRight);
  301. var robot_biped_moonWalkRight = 'void moonWalkRight(int steps, int T){\n' +
  302. ' int A[4]= {25, 25, 0, 0};\n' +
  303. ' int O[4] = {-15 ,15, 0, 0};\n' +
  304. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; \n' +
  305. ' \n' +
  306. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  307. '}\n';
  308. Blockly.Python.addFunction('robot_biped_moonWalkRight', robot_biped_moonWalkRight);
  309. var robot_biped_moonWalkLeft = 'void moonWalkLeft(int steps, int T){\n' +
  310. ' int A[4]= {25, 25, 0, 0};\n' +
  311. ' int O[4] = {-15, 15, 0, 0};\n' +
  312. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 - 120), DEG2RAD(90), DEG2RAD(90)}; \n' +
  313. ' \n' +
  314. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  315. '}\n';
  316. Blockly.Python.addFunction('robot_biped_moonWalkLeft', robot_biped_moonWalkLeft);
  317. var robot_biped_crusaito = 'void crusaito(int steps, int T){\n' +
  318. ' int A[4]= {25, 25, 30, 30};\n' +
  319. ' int O[4] = {- 15, 15, 0, 0};\n' +
  320. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; \n' +
  321. ' \n' +
  322. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  323. '}\n';
  324. Blockly.Python.addFunction('robot_biped_crusaito', robot_biped_crusaito);
  325. var robot_biped_swing = 'void swing(int steps, int T){\n' +
  326. ' int A[4]= {25, 25, 0, 0};\n' +
  327. ' int O[4] = {-15, 15, 0, 0};\n' +
  328. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n' +
  329. ' \n' +
  330. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  331. '}\n';
  332. Blockly.Python.addFunction('robot_biped_swing', robot_biped_swing);
  333. var robot_biped_upDown = 'void upDown(int steps, int T){\n' +
  334. ' int A[4]= {25, 25, 0, 0};\n' +
  335. ' int O[4] = {-15, 15, 0, 0};\n' +
  336. ' double phase_diff[4] = {DEG2RAD(180), DEG2RAD(0), DEG2RAD(270), DEG2RAD(270)};\n' +
  337. ' \n' +
  338. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  339. '}\n';
  340. Blockly.Python.addFunction('robot_biped_upDown', robot_biped_upDown);
  341. var robot_biped_flapping = 'void flapping(int steps, int T){\n' +
  342. ' int A[4]= {15, 15, 8, 8};\n' +
  343. ' int O[4] = {-A[0], A[1], 0, 0};\n' +
  344. ' double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};\n' +
  345. ' \n' +
  346. ' for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n' +
  347. '}\n';
  348. Blockly.Python.addFunction('robot_biped_flapping', robot_biped_flapping);
  349. var robot_biped_lateral_fuerte = 'void lateral_fuerte(boolean side, int tempo){\n' +
  350. ' for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  351. ' if (side) servo[0].SetPosition(40);\n' +
  352. ' else servo[1].SetPosition(140);\n' +
  353. ' delay(tempo/2);\n' +
  354. ' servo[0].SetPosition(90);\n' +
  355. ' servo[1].SetPosition(90);\n' +
  356. ' delay(tempo/2);\n' +
  357. '}\n';
  358. Blockly.Python.addFunction('robot_biped_lateral_fuerte', robot_biped_lateral_fuerte);
  359. var robot_biped_segunda_parte = 'void segunda_parte(){\n' +
  360. ' int move1[4] = {90,90,80,100};\n' +
  361. ' int move2[4] = {90,90,100,80};\n' +
  362. ' int move3[4] = {90,90,80,100};\n' +
  363. ' int move4[4] = {90,90,100,80};\n' +
  364. ' \n' +
  365. ' int move5[4] = {40,140,80,100};\n' +
  366. ' int move6[4] = {40,140,100,80};\n' +
  367. ' int move7[4] = {90,90,80,100};\n' +
  368. ' int move8[4] = {90,90,100,80};\n' +
  369. ' \n' +
  370. ' int move9[4] = {40,140,80,100};\n' +
  371. ' int move10[4] = {40,140,100,80};\n' +
  372. ' int move11[4] = {90,90,80,100};\n' +
  373. ' int move12[4] = {90,90,100,80};\n' +
  374. ' \n' +
  375. ' for(int x=0; x<7; x++){ \n' +
  376. ' for(int i=0; i<3; i++){\n' +
  377. ' pause=millis();\n' +
  378. ' moveNServos(t*0.15,move1);\n' +
  379. ' moveNServos(t*0.15,move2);\n' +
  380. ' moveNServos(t*0.15,move3);\n' +
  381. ' moveNServos(t*0.15,move4);\n' +
  382. ' while(millis()<(pause+t));\n' +
  383. ' }\n' +
  384. ' pause=millis();\n' +
  385. ' moveNServos(t*0.15,move5);\n' +
  386. ' moveNServos(t*0.15,move6);\n' +
  387. ' moveNServos(t*0.15,move7);\n' +
  388. ' moveNServos(t*0.15,move8);\n' +
  389. ' while(millis()<(pause+t));\n' +
  390. ' }\n' +
  391. ' \n' +
  392. ' for(int i=0; i<3; i++){\n' +
  393. ' pause=millis();\n' +
  394. ' moveNServos(t*0.15,move9);\n' +
  395. ' moveNServos(t*0.15,move10);\n' +
  396. ' moveNServos(t*0.15,move11);\n' +
  397. ' moveNServos(t*0.15,move12);\n' +
  398. ' while(millis()<(pause+t));\n' +
  399. ' }\n' +
  400. '}\n';
  401. Blockly.Python.addFunction('robot_biped_segunda_parte', robot_biped_segunda_parte);
  402. var robot_biped_primera_parte = 'void primera_parte(){\n' +
  403. ' int move1[4] = {60,120,90,90};\n' +
  404. ' int move2[4] = {90,90,90,90};\n' +
  405. ' int move3[4] = {40,140,90,90};\n' +
  406. ' for(int x=0; x<3; x++){\n' +
  407. ' for(int i=0; i<3; i++){\n' +
  408. ' lateral_fuerte(1,t/2);\n' +
  409. ' lateral_fuerte(0,t/4);\n' +
  410. ' lateral_fuerte(1,t/4);\n' +
  411. ' delay(t);\n' +
  412. ' }\n' +
  413. ' pause=millis();\n' +
  414. ' for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  415. ' moveNServos(t*0.4,move1);\n' +
  416. ' moveNServos(t*0.4,move2);\n' +
  417. ' while(millis()<(pause+t*2));\n' +
  418. ' }\n' +
  419. ' for(int i=0; i<2; i++){\n' +
  420. ' lateral_fuerte(1,t/2);\n' +
  421. ' lateral_fuerte(0,t/4);\n' +
  422. ' lateral_fuerte(1,t/4);\n' +
  423. ' delay(t);\n' +
  424. ' }\n' +
  425. ' \n' +
  426. ' pause=millis();\n' +
  427. ' for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  428. ' crusaito(1,t*1.4);\n' +
  429. ' moveNServos(t*1,move3);\n' +
  430. ' for(int i=0;i<4;i++) servo[i].SetPosition(90);\n' +
  431. ' while(millis()<(pause+t*4));\n' +
  432. '}\n';
  433. Blockly.Python.addFunction('robot_biped_primera_parte', robot_biped_primera_parte);
  434. return '';
  435. };
  436. Blockly.Python['robot_biped_movement'] = function(block) {
  437. var movement = block.getFieldValue('robot_biped_movement');
  438. return movement + '\n';
  439. };
  440. Blockly.Python['robot_biped_initialize'] = function(block) {
  441. var code = 'for(int i=0;i<4;i++) servo[i].SetPosition(90);';
  442. return code;
  443. };*/