@@ -272,6 +272,7 @@ export default {
272
272
CB : process .env .CB_ENDPOINT + process .env .APIv2 ,
273
273
CBv1: process .env .CB_ENDPOINT ,
274
274
status: null ,
275
+ info: null ,
275
276
code: ' ' ,
276
277
workspace: null ,
277
278
generalDialog: false ,
@@ -757,6 +758,7 @@ export default {
757
758
return sbsPrefix + ' get_bot().sleep(' + elapse + ' )\n ' ;
758
759
};
759
760
761
+ /** ENCODER METHODS **/
760
762
// muovi bot [direzione] a velocità [velcità] per [tempo]
761
763
Blockly .Blocks [' coderbot_adv_move' ] = {
762
764
// Block for moving forward.
@@ -794,6 +796,10 @@ export default {
794
796
});
795
797
this .setPreviousStatement (true );
796
798
this .setNextStatement (true );
799
+ if (self .info .motors !== " DC encoder motors" )
800
+ {
801
+ this .setDisabled (true );
802
+ }
797
803
}
798
804
};
799
805
@@ -844,6 +850,10 @@ export default {
844
850
});
845
851
this .setPreviousStatement (true );
846
852
this .setNextStatement (true );
853
+ if (self .info .motors !== " DC encoder motors" )
854
+ {
855
+ this .setDisabled (true );
856
+ }
847
857
}
848
858
};
849
859
@@ -860,7 +870,59 @@ export default {
860
870
var code = sbsPrefix + " get_bot()." + action + " (speed=" + speed + " , distance=" + distance + " )\n " ;
861
871
return code;
862
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
+ };
863
924
925
+ /** end of ENCODER METHODS **/
864
926
865
927
Blockly .Blocks [' coderbot_motion_move' ] = {
866
928
// Block for moving forward.
@@ -1823,6 +1885,11 @@ export default {
1823
1885
this .statusData = response .data
1824
1886
this .status = response .status
1825
1887
}.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 ))
1826
1893
.catch (function (error ) {
1827
1894
console .log (error);
1828
1895
// If the disconnection happened while in this component, send a notification
0 commit comments