'use strict'; goog.provide('Blockly.Python.robot'); goog.require('Blockly.Python'); /* Blockly.Python['robot_biped_init'] = function(block) { var text_pin_11 = block.getFieldValue('pin_11'); var text_pin_10 = block.getFieldValue('pin_10'); var text_pin_9 = block.getFieldValue('pin_9'); var text_pin_6 = block.getFieldValue('pin_6'); var text_pin_rr = block.getFieldValue('pin_rr'); var text_pin_rl = block.getFieldValue('pin_rl'); var text_pin_yr = block.getFieldValue('pin_yr'); var text_pin_yl = block.getFieldValue('pin_yl'); var text_intervaltime = block.getFieldValue('intervaltime'); var robot_biped_pin = '#define PIN_RR ' + text_pin_rr + '\n#define PIN_RL ' + text_pin_rl + '\n#define PIN_YR ' + text_pin_yr + '\n#define PIN_YL ' + text_pin_yl + '\n#define INTERVALTIME ' + text_intervaltime + '\n'; Blockly.Python.addDeclaration('robot_biped_pin', robot_biped_pin); var robot_biped_decl = '#include \n' + '#include \n' + '#include \n' + '#define N_SERVOS 4\n' + '\n' + '//-- First step: Configure the pins where the servos are attached\n' + '/*\n' + ' --------------- \n' + ' | O O |\n' + ' |---------------|\n' + 'YR 3==> | | <== YL 2\n' + ' --------------- \n' + ' || ||\n' + ' || ||\n' + 'RR 5==> ----- ------ <== RL 4\n' + ' |----- ------|\n' + '\n' + '#define EEPROM_TRIM false \n' + '\n' + '// Activate to take callibration data from internal memory\n' + '#define TRIM_RR 7\n' + '#define TRIM_RL 4\n' + '#define TRIM_YR 4\n' + '#define TRIM_YL -7\n' + '//OTTO.setTrims(-7,-4,-4,7);\n' + 'Oscillator servo[N_SERVOS];\n'+ '\n' + 'void goingUp(int tempo);\n' + 'void drunk (int tempo);\n' + 'void noGravity(int tempo);\n' + 'void kickLeft(int tempo);\n' + 'void kickRight(int tempo);\n' + 'void run(int steps, int T=500);\n' + 'void walk(int steps, int T=1000);\n' + 'void backyard(int steps, int T=3000);\n' + 'void backyardSlow(int steps, int T=5000);\n' + 'void turnLeft(int steps, int T=3000);\n' + 'void turnRight(int steps, int T=3000);\n' + 'void moonWalkLeft(int steps, int T=1000);\n' + 'void moonWalkRight(int steps, int T=1000);\n' + 'void crusaito(int steps, int T=1000);\n' + 'void swing(int steps, int T=1000);\n' + 'void upDown(int steps, int T=1000);\n' + 'void flapping(int steps, int T=1000);\n' + '//Tempo\n' + 'int t=495;\n'+ 'double pause=0;\n'; Blockly.Python.addDeclaration('robot_biped_decl', robot_biped_decl); var robot_biped_setup = 'Serial.begin(19200);\n' + ' servo[0].attach(PIN_RR);\n' + ' servo[1].attach(PIN_RL);\n' + ' servo[2].attach(PIN_YR);\n' + ' servo[3].attach(PIN_YL);\n' + ' \n' + ' int trim;\n' + ' \n' + ' if(EEPROM_TRIM){\n' + ' for(int x=0;x<4;x++){\n' + ' trim=EEPROM.read(x);\n' + ' if(trim>128)trim=trim-256;\n' + ' Serial.print("TRIM ");\n' + ' Serial.print(x);\n' + ' Serial.print(" en ");\n' + ' Serial.println(trim);\n' + ' servo[x].SetTrim(trim);\n' + ' }\n' + ' }\n' + ' else{\n' + ' servo[0].SetTrim(TRIM_RR);\n' + ' servo[1].SetTrim(TRIM_RL);\n' + ' servo[2].SetTrim(TRIM_YR);\n' + ' servo[3].SetTrim(TRIM_YL);\n' + ' }\n' + ' \n' + ' for(int i=0;i<3;i++) { servo[i].SetPosition(90); }\n' + ' servo[3].SetPosition(20);\n'; Blockly.Python.addSetup('robot_biped_setup', robot_biped_setup); //load all robot's actions var robot_biped_oscillate ='void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){\n' + ' for (int i=0; i<4; i++) {\n' + ' servo[i].SetO(O[i]);\n' + ' servo[i].SetA(A[i]);\n' + ' servo[i].SetT(T);\n' + ' servo[i].SetPh(phase_diff[i]);\n' + ' }\n' + ' double ref=millis();\n' + ' for (double x=ref; x