From 84f01d277bf7035c5bfe0f918b4b2c3b14a9c33a Mon Sep 17 00:00:00 2001 From: roboticafacil Date: Tue, 12 Dec 2017 00:01:01 +0100 Subject: [PATCH] new file: img/blocks/LARS.svg new file: img/blocks/LARS_BLH.svg new file: img/blocks/LARS_BLL.svg new file: img/blocks/LARS_BRH.svg new file: img/blocks/LARS_BRL.svg new file: img/blocks/LARS_FLH.svg new file: img/blocks/LARS_FLL.svg new file: img/blocks/LARS_FRH.svg new file: img/blocks/LARS_FRL.svg new file: img/blocks/acknowledgements.html new file: lang/LARS.json modified: lars_blocks.js modified: src/LARS.cpp modified: src/LARS.h --- img/blocks/LARS.svg | 65 ++++ img/blocks/LARS_BLH.svg | 71 ++++ img/blocks/LARS_BLL.svg | 71 ++++ img/blocks/LARS_BRH.svg | 71 ++++ img/blocks/LARS_BRL.svg | 71 ++++ img/blocks/LARS_FLH.svg | 71 ++++ img/blocks/LARS_FLL.svg | 71 ++++ img/blocks/LARS_FRH.svg | 71 ++++ img/blocks/LARS_FRL.svg | 71 ++++ img/blocks/acknowledgements.html | 1 + lang/LARS.json | 36 ++ lars_blocks.js | 543 +++++++++++-------------------- src/LARS.cpp | 12 + src/LARS.h | 1 + 14 files changed, 880 insertions(+), 346 deletions(-) create mode 100644 img/blocks/LARS.svg create mode 100644 img/blocks/LARS_BLH.svg create mode 100644 img/blocks/LARS_BLL.svg create mode 100644 img/blocks/LARS_BRH.svg create mode 100644 img/blocks/LARS_BRL.svg create mode 100644 img/blocks/LARS_FLH.svg create mode 100644 img/blocks/LARS_FLL.svg create mode 100644 img/blocks/LARS_FRH.svg create mode 100644 img/blocks/LARS_FRL.svg create mode 100644 img/blocks/acknowledgements.html create mode 100644 lang/LARS.json diff --git a/img/blocks/LARS.svg b/img/blocks/LARS.svg new file mode 100644 index 0000000..f061f4a --- /dev/null +++ b/img/blocks/LARS.svg @@ -0,0 +1,65 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_BLH.svg b/img/blocks/LARS_BLH.svg new file mode 100644 index 0000000..ad5c6a4 --- /dev/null +++ b/img/blocks/LARS_BLH.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_BLL.svg b/img/blocks/LARS_BLL.svg new file mode 100644 index 0000000..adbce17 --- /dev/null +++ b/img/blocks/LARS_BLL.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_BRH.svg b/img/blocks/LARS_BRH.svg new file mode 100644 index 0000000..1a12f5b --- /dev/null +++ b/img/blocks/LARS_BRH.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_BRL.svg b/img/blocks/LARS_BRL.svg new file mode 100644 index 0000000..6a3259a --- /dev/null +++ b/img/blocks/LARS_BRL.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_FLH.svg b/img/blocks/LARS_FLH.svg new file mode 100644 index 0000000..34972ee --- /dev/null +++ b/img/blocks/LARS_FLH.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_FLL.svg b/img/blocks/LARS_FLL.svg new file mode 100644 index 0000000..788b755 --- /dev/null +++ b/img/blocks/LARS_FLL.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_FRH.svg b/img/blocks/LARS_FRH.svg new file mode 100644 index 0000000..02ae8df --- /dev/null +++ b/img/blocks/LARS_FRH.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/LARS_FRL.svg b/img/blocks/LARS_FRL.svg new file mode 100644 index 0000000..9f81d82 --- /dev/null +++ b/img/blocks/LARS_FRL.svg @@ -0,0 +1,71 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/blocks/acknowledgements.html b/img/blocks/acknowledgements.html new file mode 100644 index 0000000..00bc43c --- /dev/null +++ b/img/blocks/acknowledgements.html @@ -0,0 +1 @@ +
Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
\ No newline at end of file diff --git a/lang/LARS.json b/lang/LARS.json new file mode 100644 index 0000000..4b76305 --- /dev/null +++ b/lang/LARS.json @@ -0,0 +1,36 @@ +{ + "langs": + { + "en-GB": + { + "keys": + { + "LANG_LARS_INIT_TOOLTIP": "Defines the servo pins for a quadruped robot.", + "LANG_LARS_MOVEMENT": "Move robot", + "LANG_LARS_MOVEMENT_MOVEMENT": "Movement", + "LANG_LARS_MOVEMENT_HOME": "Home", + "LANG_LARS_MOVEMENT_WALK": "Walk", + "LANG_LARS_MOVEMENT_OMNIWALK": "Omni walk", + "LANG_LARS_MOVEMENT_TURN_LEFT": "Turn left", + "LANG_LARS_MOVEMENT_TURN_RIGHT": "Turn right", + "LANG_LARS_MOVEMENT_MOONWALK": "Moonwalk", + "LANG_LARS_MOVEMENT_DANCE": "Dance", + "LANG_LARS_MOVEMENT_UPDOWN": "Up-down", + "LANG_LARS_MOVEMENT_PUSHUP": "Push-up", + "LANG_LARS_MOVEMENT_HELLO": "Hello", + "LANG_LARS_MOVEMENT_WAVE": "Wave", + "LANG_LARS_MOVEMENT_LEG_NUMBER": "Leg number", + "LANG_LARS_MOVEMENT_STEPS": "Steps", + "LANG_LARS_MOVEMENT_PERIOD": "Period", + "LANG_LARS_MOVEMENT_DIR": "Direction", + "LANG_LARS_MOVEMENT_SIDE": "Side", + "LANG_LARS_MOVEMENT_TURN_FACTOR": "Turn factor", + "LANG_LARS_MOVEMENT_FORWARD": "Forward", + "LANG_LARS_MOVEMENT_BACKWARD": "Backward", + "LANG_LARS_MOVEMENT_YES": "Yes", + "LANG_LARS_MOVEMENT_NO": "No", + "LANG_LARS_MOVEMENT_TOOLTIP": "Generates movement primitives for a quadruped robot" + } + } + } +} \ No newline at end of file diff --git a/lars_blocks.js b/lars_blocks.js index 5c32438..9643e4b 100644 --- a/lars_blocks.js +++ b/lars_blocks.js @@ -1,349 +1,200 @@ -/* -Blockly.Blocks['espui_prepare_fs'] = { - category: 'ESPUI', - colour: '#3357c7', - helpUrl: Facilino.getHelpUrl('espui'), - tags: ['webinterface'], - examples: ['lol.bly'], - init: function() { - var wifiOptions = [ - ['No', false], - ['Yes', true] - ]; - this.appendDummyInput() - .appendField('Prepare FileSystem (upload once without other in setup code, then omit)'); - } -}; +Facilino.LANG_COLOUR_MOVEMENT = '#CECE42'; +Facilino.LANG_COLOUR_MOVEMENT_WALK = '#8D8D25'; -Blockly.Arduino['espui_prepare_fs'] = function(block) { - var wifi_option = block.getFieldValue('wifi_option'); - Blockly.Arduino.definitions_['define_espui_h'] = '#include '; - Blockly.Arduino.setups_['setup_espui'] = '\n'; - Blockly.Arduino.setups_['setup_espui'] += ' ESPUI.prepareFileSystem();\n'; - return null; -}; +Blockly.Blocks['LARS_init'] = { + category: Facilino.locales.getKey('LANG_CATEGORY_MOVEMENT'), + subcategory: Facilino.locales.getKey('LANG_SUBCATEGORY_WALK'), + helpUrl: Facilino.getHelpUrl('LARS_init'), + category_colour: Facilino.LANG_COLOUR_MOVEMENT, + colour: Facilino.LANG_COLOUR_MOVEMENT_WALK, + tags: [], + examples: [], + init: function () { + this.setPreviousStatement(true,'code'); + this.setNextStatement(true,'code'); + this.setColour(Facilino.LANG_COLOUR_MOVEMENT_WALK); + this.setTooltip(Facilino.locales.getKey('LANG_LARS_INIT_TOOLTIP')); + } +} - */ -Blockly.Blocks['walk_forward'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('walk_forward'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Walking"); - this.setColour("#FF00FF"); - this.setTooltip(""); +Blockly.Arduino['LARS_movement'] = function() { + var code=''; + var movement = this.getFieldValue('MOVEMENT'); + if (movement==='0') + code+='lars.home();\n'; + else if (movement==='1') + code+='lars.hello();\n'; + else if (movement==='2') + code+='lars.wave('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+');\n'; + else if (movement==='3') + code+='lars.turnL('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '600')+');\n'; + else if (movement==='4') + code+='lars.turnR('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '600')+');\n'; + else if (movement==='5') + code+='lars.moonwalk('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '5000')+');\n'; + else if (movement==='6') + code+='lars.dance('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '600')+');\n'; + else if (movement==='7') + code+='lars.upDown('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '5000')+');\n'; + else if (movement==='8') + code+='lars.pushUp('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '600')+');\n'; + else if (movement==='9') + code+='lars.walk('+this.getFieldValue('FIELD3')+','+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '800')+');\n'; + else if (movement==='10') + code+='lars.omniWalk('+(Blockly.Arduino.valueToCode(this, 'INP1', Blockly.Arduino.ORDER_ATOMIC) || '1')+','+(Blockly.Arduino.valueToCode(this, 'INP2', Blockly.Arduino.ORDER_ATOMIC) || '800')+','+this.getFieldValue('FIELD3')+','+(Blockly.Arduino.valueToCode(this, 'INP4', Blockly.Arduino.ORDER_ATOMIC) || '0')+');\n'; + return code; + } - } -}; - -Blockly.Arduino['walk_forward'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.walk();\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['walk_backward'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('walk_backward'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Walking_Back"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['walk_backward'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.walk(0);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['Turn_R'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('Turn_R'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Turn_Right"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['Turn_R'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.turnR(1, 550);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['Turn_L'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('Turn_L'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Turn_Left"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['Turn_L'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.turnL(1, 550);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['PushUp'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('PushUp'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Push_Up"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['PushUp'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.pushUp(1, 600);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['UpDown'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('UpDown'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Up_Down"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['UpDown'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.upDown(1, 5000);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['Dance'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('Dance'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Dance"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['Dance'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.dance(1, 600);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['Wave'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('Wave'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Wave"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['Wave'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.wave();\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['Slow_Turn_R'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('Slow_Turn_R'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Slow_Turn_Right"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['Slow_Turn_R'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.omniWalk(1, 600, true, 1);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['Slow_Turn_L'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('Slow_Turn_L'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Slow_Turn_Left"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['Slow_Turn_L'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.omniWalk(1, 600, false, 1);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['MoonWalk'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('MoonWalk'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Moonwalk"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['MoonWalk'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.moonwalkL(1, 5000);\n'; - code+= '\n'; - return code; -}; - -Blockly.Blocks['Hello'] = { - category: Facilino.locales.getKey('LANG_CATEGORY_BLOCKS'), - helpUrl: Facilino.getHelpUrl('Hello'), - tags: [], - examples: [], - init: function() { - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendDummyInput() - .appendField("Audience_Hello"); - this.setColour("#FF00FF"); - this.setTooltip(""); - - } -}; - -Blockly.Arduino['Hello'] = function(block) { - Blockly.Arduino.setups_['setup_']='robot.init();\n '; - var input_shall_walk = Blockly.Arduino.valueToCode(block, 'shall_walk', Blockly.Arduino.ORDER_ATOMIC); - Blockly.Arduino.definitions_['define_lars_h']='#include '; - Blockly.Arduino.definitions_['declare_var_define_robot']='LARS robot;'; - var code=''; - code+='robot.hello();\n'; - code+= '\n'; - return code; -}; + Blockly.Blocks['LARS_movement'] = { + category: Facilino.locales.getKey('LANG_CATEGORY_MOVEMENT'), + subcategory: Facilino.locales.getKey('LANG_SUBCATEGORY_WALK'), + tags: [], + helpUrl: Facilino.getHelpUrl('LARS_movement'), + examples: [], + category_colour: Facilino.LANG_COLOUR_MOVEMENT, + colour: Facilino.LANG_COLOUR_MOVEMENT_WALK, + init: function() { + this.setColour(Facilino.LANG_COLOUR_MOVEMENT_WALK); + var movement = new Blockly.FieldDropdown([ + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_HOME'),'0'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_HELLO'),'1'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_WAVE'),'2'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_TURN_LEFT'),'3'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_TURN_RIGHT'),'4'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_MOONWALK'),'5'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_DANCE'),'6'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_UPDOWN'),'7'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_PUSHUP'),'8'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_WALK'),'9'], + [Facilino.locales.getKey('LANG_LARS_MOVEMENT_OMNIWALK'),'10'] + ]); + this.appendDummyInput().appendField(new Blockly.FieldImage('img/blocks/LARS.svg', 32*options.zoom, 32*options.zoom)).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT')); + this.appendDummyInput('').appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_MOVEMENT')).appendField(movement,'MOVEMENT').setAlign(Blockly.ALIGN_RIGHT); + this.last_movement = -1; + this._inp1_removed = true; + this._inp2_removed = true; + this._inp3_removed = true; + this._inp4_removed = true; + this.checkMovement(); + this.last_movement = this.getFieldValue('MOVEMENT'); + this.setInputsInline(false); + this.setPreviousStatement(true,'code'); + this.setNextStatement(true,'code'); + this.setOutput(false); + this.setTooltip(Facilino.locales.getKey('LANG_LARS_MOVEMENT_TOOLTIP')); + }, + checkMovement: function() { + var _movement = this.getFieldValue('MOVEMENT'); + try { + if (_movement<10) + { + this._inp4_removed=true; + this.removeInput('INP4'); + } + } catch (e) {} + try { + if (_movement<9) + { + this._inp3_removed=true; + this.removeInput('INP3'); + } + } catch (e) {} + try { + if (_movement<3) + { + this._inp2_removed=true; + this.removeInput('INP2'); + } + } catch (e) {} + try { + if (_movement<2) + { + this._inp1_removed=true; + this.removeInput('INP1'); + } + } catch (e) {} + if ( _movement === '2') { + if (this._inp1_removed) + { + this.appendValueInput('INP1').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_LEG_NUMBER'),'TEXT1').setAlign(Blockly.ALIGN_RIGHT); + this._inp1_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_LEG_NUMBER'),'TEXT1');}catch (e) {} + } else if (( _movement >= '3')&&( _movement <= '8')) { + if (this._inp1_removed) + { + this.appendValueInput('INP1').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_STEPS'),'TEXT1').setAlign(Blockly.ALIGN_RIGHT); + this._inp1_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_STEPS'),'TEXT1');}catch (e) {} + if (this._inp2_removed) + { + this.appendValueInput('INP2').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_PERIOD','TEXT2')).setAlign(Blockly.ALIGN_RIGHT); + this._inp2_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_PERIOD'),'TEXT2');}catch (e) {} + } else if ( _movement === '9') { + if (this._inp1_removed) + { + this.appendValueInput('INP1').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_STEPS'),'TEXT1').setAlign(Blockly.ALIGN_RIGHT); + this._inp1_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_STEPS'),'TEXT1');}catch (e) {} + if (this._inp2_removed) + { + this.appendValueInput('INP2').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_PERIOD'),'TEXT2').setAlign(Blockly.ALIGN_RIGHT); + this._inp2_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_PERIOD'),'TEXT2');}catch (e) {} + if (this._inp3_removed) + { + this.appendDummyInput('INP3').appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_DIR'),'TEXT3').appendField(new Blockly.FieldDropdown([['Forward','0'],['Backward','1']]),'FIELD3').setAlign(Blockly.ALIGN_RIGHT); + this._inp3_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_DIR'),'TEXT3'); this.getInput('INP3').removeField('FIELD3'); this.getInput('INP3').appendField(new Blockly.FieldDropdown([['Forward','0'],['Backward','1']]),'FIELD3');}catch (e) {} + } + else if ( _movement === '10') { + if (this._inp1_removed) + { + this.appendValueInput('INP1').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_STEPS'),'TEXT1').setAlign(Blockly.ALIGN_RIGHT); + this._inp1_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_STEPS'),'TEXT1');}catch (e) {} + if (this._inp2_removed) + { + this.appendValueInput('INP2').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_PERIOD'),'TEXT2').setAlign(Blockly.ALIGN_RIGHT); + this._inp2_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_PERIOD'),'TEXT2');}catch (e) {} + if (this._inp3_removed) + { + this.appendDummyInput('INP3').appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_DIR'),'TEXT3').appendField(new Blockly.FieldDropdown([['Yes','true'],['No','false']]),'FIELD3').setAlign(Blockly.ALIGN_RIGHT); + this._inp3_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_SIDE'),'TEXT3'); this.getInput('INP3').removeField('FIELD3'); this.getInput('INP3').appendField(new Blockly.FieldDropdown([['Yes','true'],['No','false']]),'FIELD3');}catch (e) {} + if (this._inp4_removed) + { + this.appendValueInput('INP4').setCheck(Number).appendField(Facilino.locales.getKey('LANG_LARS_MOVEMENT_TURN_FACTOR'),'TEXT4').setAlign(Blockly.ALIGN_RIGHT); + this._inp4_removed=false; + } + else + try{this.setFieldValue(Facilino.locales.getKey('LANG_LARS_MOVEMENT_TURN_FACTOR'),'TEXT4');}catch (e) {} + + } + }, + onchange: function() { + if (this.getFieldValue('MOVEMENT') !== this.last_movement) { + this.checkMovement(); + this.last_movement = this.getFieldValue('MOVEMENT'); + } + } + }; \ No newline at end of file diff --git a/src/LARS.cpp b/src/LARS.cpp index 8863d6c..737d5ab 100644 --- a/src/LARS.cpp +++ b/src/LARS.cpp @@ -59,6 +59,18 @@ void LARS::init() { home(); } +void init(int FRH, int FLH, int BRH, int BLH, int FRL, int FLL, int BRL, int BLL) +{ + board_pins[FRONT_RIGHT_HIP] = FRH; // front right inner + board_pins[FRONT_LEFT_HIP] = FLH; // front left inner + board_pins[BACK_RIGHT_HIP] = BRH; // back right inner + board_pins[BACK_LEFT_HIP] = BLH; // back left inner + board_pins[FRONT_RIGHT_LEG] = FRL; // front right outer + board_pins[FRONT_LEFT_LEG] = FLL; // front left outer // POSITIONS LOOKING FROM THE MIDDLE OF THE ROBOT!!!!! + board_pins[BACK_RIGHT_LEG] = BRL; // back right outer + board_pins[BACK_LEFT_LEG] = BLL; // back left outer +} + void LARS::turnR(float steps, float T = 600) { //int x_amp = 15; //int z_amp = 15; diff --git a/src/LARS.h b/src/LARS.h index bc1341f..1e97efc 100644 --- a/src/LARS.h +++ b/src/LARS.h @@ -20,6 +20,7 @@ class LARS { public: LARS(); void init(); + void init(int FRH, int FLH, int BRH, int BLH, int FRL, int FLL, int BRL, int BLL); void walk(int dir = 1, float steps = 1, float T = 800); // T initial 400 void omniWalk(float steps, float T, bool side, float turn_factor); void turnL(float steps, float period);