Skip to content

Commit

Permalink
Blockly vision updates for the 2021 vision system (#35)
Browse files Browse the repository at this point in the history
Thank you @casheww very clean :)

* update marker blocks

* update for vision syntax changes

* update resolution blocks

* remove redundant import

* build blockly changes

* use consts for block colours

* change cam res block type

* build vision block changes
  • Loading branch information
casheww authored and Minion3665 committed Nov 25, 2021
1 parent fa8beb8 commit dd87e49
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 72 deletions.
3 changes: 1 addition & 2 deletions sheepsrc/app/components/editor/blockly/Blockly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ export default Vue.extend({
// noinspection TypeScriptUnresolvedFunction
this.workspace.addChangeListener(() => {
// noinspection TypeScriptUnresolvedFunction
this.code = `from __future__ import print_function
from robot import *
this.code = `from robot import *
import time
R = Robot()
Expand Down
185 changes: 127 additions & 58 deletions sheepsrc/app/components/editor/blockly/blocks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

// Block colours use HSL. setColor takes the hue value (0 to 255).
const movementHue = 0;
const gpioHue = 210;
const visionHue = 90;
const markerTypeHue = 70;

function loadMovementBlocks(Blockly) {
Blockly.Blocks["motors_set_power"] = {
init: function() {
Expand All @@ -11,7 +18,7 @@ function loadMovementBlocks(Blockly) {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(0);
this.setColour(movementHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -38,7 +45,7 @@ function loadMovementBlocks(Blockly) {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(0);
this.setColour(movementHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -65,7 +72,7 @@ function loadMovementBlocks(Blockly) {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(0);
this.setColour(movementHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -76,7 +83,7 @@ function loadMovementBlocks(Blockly) {
this.appendDummyInput().appendField("Stop both motors");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(0);
this.setColour(movementHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand Down Expand Up @@ -105,7 +112,7 @@ function loadMovementBlocks(Blockly) {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(0);
this.setColour(movementHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -115,7 +122,7 @@ function loadMovementBlocks(Blockly) {
init: function() {
this.appendDummyInput().appendField("Zone");
this.setOutput(true, null);
this.setColour(0);
this.setColour(movementHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand Down Expand Up @@ -221,7 +228,7 @@ function loadGPIOBlocks(Blockly) {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(210);
this.setColour(gpioHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -237,7 +244,7 @@ function loadGPIOBlocks(Blockly) {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(210);
this.setColour(gpioHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -249,7 +256,7 @@ function loadGPIOBlocks(Blockly) {
.appendField("Digital value of GPIO")
.appendField(new Blockly.FieldNumber(1, 1, 4, 1), "GPIO_INDEX");
this.setOutput(true, "Boolean");
this.setColour(210);
this.setColour(gpioHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -261,7 +268,7 @@ function loadGPIOBlocks(Blockly) {
.appendField("Analog value of GPIO")
.appendField(new Blockly.FieldNumber(1, 1, 4, 1), "GPIO_INDEX");
this.setOutput(true, "Number");
this.setColour(210);
this.setColour(gpioHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand Down Expand Up @@ -296,24 +303,109 @@ function loadGPIOBlocks(Blockly) {
};
}

function loadVisionMarkerBlocks(Blockly) {
/* Year dependent marker blocks (2022) */

Blockly.Blocks["vision_marker_type_arena"] = {
init: function() {
this.appendDummyInput().appendField("Arena");
this.setOutput(true, "MarkerType");
this.setColour(markerTypeHue);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks["vision_marker_type_winkie"] = {
init: function() {
this.appendDummyInput().appendField("Winkie");
this.setOutput(true, "MarkerType");
this.setColour(markerTypeHue);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks["vision_marker_type_gillikin"] = {
init: function() {
this.appendDummyInput().appendField("Gillikin");
this.setOutput(true, "MarkerType");
this.setColour(markerTypeHue);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks["vision_marker_type_quadling"] = {
init: function() {
this.appendDummyInput().appendField("Quadling");
this.setOutput(true, "MarkerType");
this.setColour(markerTypeHue);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks["vision_marker_type_munchkin"] = {
init: function() {
this.appendDummyInput().appendField("Munchkin");
this.setOutput(true, "MarkerType");
this.setColour(markerTypeHue);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Python["vision_marker_type_arena"] = function() {
const code = "MARKER_ARENA";
return [code, Blockly.Python.ORDER_NONE];
};
Blockly.Python["vision_marker_type_winkie"] = function() {
const code = "MARKER_CUBE_WINKIE";
return [code, Blockly.Python.ORDER_NONE];
};
Blockly.Python["vision_marker_type_gillikin"] = function() {
const code = "MARKER_CUBE_GILLIKIN";
return [code, Blockly.Python.ORDER_NONE];
};
Blockly.Python["vision_marker_type_quadling"] = function() {
const code = "MARKER_CUBE_QUADLING";
return [code, Blockly.Python.ORDER_NONE];
};
Blockly.Python["vision_marker_type_munchkin"] = function() {
const code = "MARKER_CUBE_MUNCHKIN";
return [code, Blockly.Python.ORDER_NONE];
};
}

function loadVisionBlocks(Blockly) {
/* Loads blocks for vision code that are not dependent on the current year's game.
* Marker blocks (year depentent) are loaded in loadVisionMarkerBlocks. */

Blockly.Blocks["vision_see"] = {
init: function() {
this.appendDummyInput()
.appendField("Visible markers at")
.appendField(
new Blockly.FieldDropdown([
["640x480", "(640, 480)"],
["1296x736", "(1296, 736)"],
["1296x976", "(1296, 976)"],
["1920x1088", "(1920, 1088)"],
["1920x1440", "(1920, 1440)"]
]),
"VISION_RESOLUTION"
)
.appendField("px");
.appendField("Visible markers")
this.setOutput(true, "Array");
this.setColour(90);
this.setColour(visionHue);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Blocks["vision_camera_res"] = {
init: function() {
this.appendDummyInput()
.appendField("Set camera resolution to")
.appendField(
new Blockly.FieldDropdown([
["640x480", "(640, 480)"],
["1296x736", "(1296, 736)"],
["1296x976", "(1296, 976)"],
["1920x1088", "(1920, 1088)"],
["1920x1440", "(1920, 1440)"]
]),
"VISION_RESOLUTION"
);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(visionHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -326,7 +418,7 @@ function loadVisionBlocks(Blockly) {
.appendField("Distance to");
this.setInputsInline(false);
this.setOutput(true, "Number");
this.setColour(90);
this.setColour(visionHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -339,7 +431,7 @@ function loadVisionBlocks(Blockly) {
.appendField("Angle to");
this.setInputsInline(false);
this.setOutput(true, "Number");
this.setColour(90);
this.setColour(visionHue);
this.setTooltip("");
this.setHelpUrl("");
}
Expand All @@ -352,36 +444,20 @@ function loadVisionBlocks(Blockly) {
.appendField("Marker type of");
this.setInputsInline(false);
this.setOutput(true, "MarkerType");
this.setColour(90);
this.setColour(markerTypeHue);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Blocks["vision_marker_type_arena"] = {
init: function() {
this.appendDummyInput().appendField("Arena");
this.setOutput(true, "MarkerType");
this.setColour(90);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Blocks["vision_marker_type_basket"] = {
init: function() {
this.appendDummyInput().appendField("Basket");
this.setOutput(true, "MarkerType");
this.setColour(90);
this.setTooltip("");
this.setHelpUrl("");
}
Blockly.Python["vision_see"] = function(block) {
const code = `R.see()`;
return [code, Blockly.Python.ORDER_NONE];
};

Blockly.Python["vision_see"] = function(block) {
Blockly.Python["vision_camera_res"] = function(block) {
const dropdown_vision_resolution = block.getFieldValue("VISION_RESOLUTION");
const code = `R.see(res=${dropdown_vision_resolution})`;
return [code, Blockly.Python.ORDER_NONE];
return `R.camera.res = ${dropdown_vision_resolution}\n`;
};

Blockly.Python["vision_distance_to"] = function(block) {
Expand All @@ -400,7 +476,7 @@ function loadVisionBlocks(Blockly) {
"MARKER",
Blockly.Python.ORDER_ATOMIC
);
const code = `${value_marker}.rot_y`;
const code = `${value_marker}.bearing.y`;
return [code, Blockly.Python.ORDER_NONE];
};

Expand All @@ -410,19 +486,12 @@ function loadVisionBlocks(Blockly) {
"MARKER",
Blockly.Python.ORDER_ATOMIC
);
const code = `${value_marker}.info.marker_type`;
const code = `${value_marker}.info.type`;
return [code, Blockly.Python.ORDER_NONE];
};

Blockly.Python["vision_marker_type_arena"] = function() {
const code = "MARKER_TYPE_ARENA";
return [code, Blockly.Python.ORDER_NONE];
};

Blockly.Python["vision_marker_type_basket"] = function() {
const code = "MARKER_TYPE_BASKET";
return [code, Blockly.Python.ORDER_NONE];
};
// Load marker blocks. These may change for different competitions.
loadVisionMarkerBlocks(Blockly);
}

export default function loadBlocks(Blockly) {
Expand Down
9 changes: 7 additions & 2 deletions sheepsrc/app/components/editor/blockly/toolbox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@
</category>
<category name="Vision" colour="#80a55b">
<block type="vision_see"></block>
<block type="vision_camera_res"></block>
<block type="vision_distance_to">
<value name="MARKER">
<block type="variables_get">
Expand All @@ -392,15 +393,19 @@
</block>
</value>
</block>
<block type="vision_marker_type">
<block type="vision_marker_type">
<value name="MARKER">
<block type="variables_get">
<field name="VAR" id=";)moF_=/[]v+i@k*^`Aq" variabletype="">marker</field>
</block>
</value>
</block>
<block type="vision_marker_type_arena"></block>
<block type="vision_marker_type_basket"></block>
<block type="vision_marker_type_winkie"></block>
<block type="vision_marker_type_gillikin"></block>
<block type="vision_marker_type_quadling"></block>
<block type="vision_marker_type_munchkin"></block>

<block type="controls_forEach">
<field name="VAR" id=";)moF_=/[]v+i@k*^`Aq" variabletype="">i</field>
<value name="LIST">
Expand Down
15 changes: 5 additions & 10 deletions shepherd/blueprints/staticroutes/editor/bundle.js

Large diffs are not rendered by default.

0 comments on commit dd87e49

Please sign in to comment.