@@ -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 ,
@@ -756,7 +757,9 @@ export default {
756757 Blockly .Python .ORDER_NONE ) || ' \'\' ' ;
757758 return sbsPrefix + ' get_bot().sleep(' + elapse + ' )\n ' ;
758759 };
759-
760+
761+ /** ENCODER METHODS **/
762+ // muovi bot [direzione] a velocità [velcità] per [tempo]
760763 Blockly .Blocks [' coderbot_adv_move' ] = {
761764 // Block for moving forward.
762765 init : function () {
@@ -793,6 +796,10 @@ export default {
793796 });
794797 this .setPreviousStatement (true );
795798 this .setNextStatement (true );
799+ if (self .info .motors !== " DC encoder motors" )
800+ {
801+ this .setDisabled (true );
802+ }
796803 }
797804 };
798805
@@ -811,6 +818,111 @@ export default {
811818 var code = sbsPrefix + " get_bot()." + action + " (speed=" + speed + " , elapse=" + elapse + " )\n " ;
812819 return code;
813820 };
821+
822+ // muovi bot [direzione] per [distanza] metri
823+ Blockly .Blocks [' coderbot_adv_move_distance' ] = {
824+ // Block for moving forward.
825+ init : function () {
826+ var ACTIONS = [
827+ [Blockly .Msg .CODERBOT_MOVE_ADV_TIP_FORWARD , ' FORWARD' ],
828+ [Blockly .Msg .CODERBOT_MOVE_ADV_TIP_BACKWARD , ' BACKWARD' ]
829+ ]
830+ this .setHelpUrl (' http://code.google.com/p/blockly/wiki/Move' );
831+ this .setColour (40 );
832+
833+ this .appendDummyInput (" ACTION" )
834+ .appendField (Blockly .Msg .CODERBOT_MOVE_ADV_MOVE )
835+ .appendField (new Blockly.FieldDropdown (ACTIONS ), ' ACTION' );
836+ this .appendValueInput (' DISTANCE' )
837+ .setCheck (' Number' )
838+ .appendField (Blockly .Msg .CODERBOT_MOVE_ADV_ELAPSE )
839+ .appendField (Blockly .Msg .MEASURE_UNIT );
840+ this .setInputsInline (true );
841+ // Assign 'this' to a variable for use in the tooltip closure below.
842+ var thisBlock = this ;
843+ this .setTooltip (function () {
844+ var mode = thisBlock .getFieldValue (' ACTION' );
845+ var TOOLTIPS = {
846+ FORWARD : Blockly .Msg .CODERBOT_MOVE_ADV_TIP_FORWARD ,
847+ BACKWARD : Blockly .Msg .CODERBOT_MOVE_ADV_TIP_BACKWARD
848+ };
849+ return TOOLTIPS [mode] + Blockly .Msg .CODERBOT_MOVE_ADV_TIP_TAIL ;
850+ });
851+ this .setPreviousStatement (true );
852+ this .setNextStatement (true );
853+ if (self .info .motors !== " DC encoder motors" )
854+ {
855+ this .setDisabled (true );
856+ }
857+ }
858+ };
859+
860+ Blockly .Python [' coderbot_adv_move_distance' ] = function (block ) {
861+ // Generate Python for moving forward.
862+ var OPERATORS = {
863+ FORWARD : [' forward' ],
864+ BACKWARD : [' backward' ]
865+ };
866+ var tuple = OPERATORS [block .getFieldValue (' ACTION' )];
867+ var action = tuple[0 ];
868+ var speed = 100 ;
869+ var distance = Blockly .Python .valueToCode (block, ' DISTANCE' , Blockly .Python .ORDER_NONE );
870+ var code = sbsPrefix + " get_bot()." + action + " (speed=" + speed + " , distance=" + distance + " )\n " ;
871+ return code;
872+ };
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+ };
924+
925+ /** end of ENCODER METHODS **/
814926
815927 Blockly .Blocks [' coderbot_motion_move' ] = {
816928 // Block for moving forward.
@@ -1773,6 +1885,11 @@ export default {
17731885 this .statusData = response .data
17741886 this .status = response .status
17751887 }.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 ))
17761893 .catch (function (error ) {
17771894 console .log (error);
17781895 // If the disconnection happened while in this component, send a notification
0 commit comments