@@ -272,6 +272,7 @@ export default {
272272 CB : process .env .CB_ENDPOINT + process .env .APIv2 ,
273273 CBv1: process .env .CB_ENDPOINT ,
274274 status: null ,
275+ info: null ,
275276 code: ' ' ,
276277 workspace: null ,
277278 generalDialog: false ,
@@ -757,6 +758,7 @@ export default {
757758 return sbsPrefix + ' get_bot().sleep(' + elapse + ' )\n ' ;
758759 };
759760
761+ /** ENCODER METHODS **/
760762 // muovi bot [direzione] a velocità [velcità] per [tempo]
761763 Blockly .Blocks [' coderbot_adv_move' ] = {
762764 // Block for moving forward.
@@ -794,6 +796,10 @@ export default {
794796 });
795797 this .setPreviousStatement (true );
796798 this .setNextStatement (true );
799+ if (self .info .motors !== " DC encoder motors" )
800+ {
801+ this .setDisabled (true );
802+ }
797803 }
798804 };
799805
@@ -844,6 +850,10 @@ export default {
844850 });
845851 this .setPreviousStatement (true );
846852 this .setNextStatement (true );
853+ if (self .info .motors !== " DC encoder motors" )
854+ {
855+ this .setDisabled (true );
856+ }
847857 }
848858 };
849859
@@ -860,7 +870,59 @@ export default {
860870 var code = sbsPrefix + " get_bot()." + action + " (speed=" + speed + " , distance=" + distance + " )\n " ;
861871 return code;
862872 };
873+
874+ // muovi bot [direzione] a velocità [velocità] per [distanza] metri
875+ Blockly .Blocks [' coderbot_adv_move_speed_distance' ] = {
876+ // Block for moving forward.
877+ init : function () {
878+ var ACTIONS = [
879+ [Blockly .Msg .CODERBOT_MOVE_ADV_TIP_FORWARD , ' FORWARD' ],
880+ [Blockly .Msg .CODERBOT_MOVE_ADV_TIP_BACKWARD , ' BACKWARD' ]
881+ ]
882+ this .setHelpUrl (' http://code.google.com/p/blockly/wiki/Move' );
883+ this .setColour (40 );
884+
885+ this .appendDummyInput (" ACTION" )
886+ .appendField (Blockly .Msg .CODERBOT_MOVE_ADV_MOVE )
887+ .appendField (new Blockly.FieldDropdown (ACTIONS ), ' ACTION' );
888+ this .appendValueInput (' SPEED' )
889+ .setCheck (' Number' )
890+ .appendField (Blockly .Msg .CODERBOT_MOVE_ADV_SPEED );
891+ this .appendValueInput (' DISTANCE' )
892+ .setCheck (' Number' )
893+ .appendField (Blockly .Msg .CODERBOT_MOVE_ADV_ELAPSE )
894+ .appendField (Blockly .Msg .MEASURE_UNIT );
895+ this .setInputsInline (true );
896+ // Assign 'this' to a variable for use in the tooltip closure below.
897+ var thisBlock = this ;
898+ this .setTooltip (function () {
899+ var mode = thisBlock .getFieldValue (' ACTION' );
900+ var TOOLTIPS = {
901+ FORWARD : Blockly .Msg .CODERBOT_MOVE_ADV_TIP_FORWARD ,
902+ BACKWARD : Blockly .Msg .CODERBOT_MOVE_ADV_TIP_BACKWARD
903+ };
904+ return TOOLTIPS [mode] + Blockly .Msg .CODERBOT_MOVE_ADV_TIP_TAIL ;
905+ });
906+ this .setPreviousStatement (true );
907+ this .setNextStatement (true );
908+ }
909+ };
910+
911+ Blockly .Python [' coderbot_adv_move_speed_distance' ] = function (block ) {
912+ // Generate Python for moving forward.
913+ var OPERATORS = {
914+ FORWARD : [' forward' ],
915+ BACKWARD : [' backward' ]
916+ };
917+ var tuple = OPERATORS [block .getFieldValue (' ACTION' )];
918+ var action = tuple[0 ];
919+ var speed = Blockly .Python .valueToCode (block, ' SPEED' , Blockly .Python .ORDER_NONE );
920+ var distance = Blockly .Python .valueToCode (block, ' DISTANCE' , Blockly .Python .ORDER_NONE );
921+ var code = sbsPrefix + " get_bot()." + action + " (speed=" + speed + " , distance=" + distance + " )\n " ;
922+ return code;
923+ };
863924
925+ /** end of ENCODER METHODS **/
864926
865927 Blockly .Blocks [' coderbot_motion_move' ] = {
866928 // Block for moving forward.
@@ -1823,6 +1885,11 @@ export default {
18231885 this .statusData = response .data
18241886 this .status = response .status
18251887 }.bind (this ))
1888+ axios .get (this .CB + ' /info' )
1889+ .then (function (response ) {
1890+ this .info = response .data
1891+ console .log (this .info )
1892+ }.bind (this ))
18261893 .catch (function (error ) {
18271894 console .log (error);
18281895 // If the disconnection happened while in this component, send a notification
0 commit comments