Skip to content

Commit 1028b09

Browse files
Merge pull request #13 from Open-STEM/r004
v0.0.4 Update
2 parents c7bcbcd + 5e6cf79 commit 1028b09

File tree

6 files changed

+100
-5
lines changed

6 files changed

+100
-5
lines changed

app/src/ui/blocklyworkspace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ workspace.addChangeListener(myUpdateFunction);
5151
/* Code Cleaning and Formatting */
5252
function processCode(code) {
5353
// console.log("Processing Code");
54-
code = "from WPILib import *\n\n" + code
54+
code = "from WPILib.WPILib import *\n\n" + code
5555
// if (code.includes('encoded_motor')) {
5656
// // console.log("Found encoded_motor");
5757
// }

app/src/xrp_blocks.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ Blockly.Blocks['xrp_seteffort'] = {
119119
}
120120
};
121121

122+
Blockly.Blocks['xrp_setencoderpos'] = {
123+
init: function() {
124+
this.appendDummyInput()
125+
.appendField("Set Encoder Positions");
126+
this.appendValueInput("LEFT")
127+
.setCheck(null)
128+
.appendField("L:");
129+
this.appendValueInput("RIGHT")
130+
.setCheck(null)
131+
.appendField("R:");
132+
this.setInputsInline(true);
133+
this.setPreviousStatement(true, null);
134+
this.setNextStatement(true, null);
135+
this.setColour(60);
136+
this.setTooltip("");
137+
this.setHelpUrl("");
138+
}
139+
};
140+
122141
Blockly.Blocks['xrp_getsonardist'] = {
123142
init: function () {
124143
this.appendDummyInput()
@@ -130,6 +149,42 @@ Blockly.Blocks['xrp_getsonardist'] = {
130149
}
131150
};
132151

152+
Blockly.Blocks['xrp_getrightencoder'] = {
153+
init: function () {
154+
this.appendDummyInput()
155+
.appendField("Right Encoder");
156+
this.setOutput(true, null);
157+
this.setColour(60);
158+
this.setTooltip("");
159+
this.setHelpUrl("");
160+
}
161+
};
162+
163+
Blockly.Blocks['xrp_getleftencoder'] = {
164+
init: function () {
165+
this.appendDummyInput()
166+
.appendField("Left Encoder");
167+
this.setOutput(true, null);
168+
this.setColour(60);
169+
this.setTooltip("");
170+
this.setHelpUrl("");
171+
}
172+
};
173+
174+
Blockly.Blocks['xrp_encoder_counts'] = {
175+
init: function () {
176+
this.appendDummyInput()
177+
.appendField("Set Encoder Tick Mode:")
178+
.appendField(new Blockly.FieldDropdown([["Legacy", "drivetrain._LEGACY_TICKS_PER_REV"], ["New", "drivetrain._NEW_TICKS_PER_REV"]]), "TICKS")
179+
this.setInputsInline(true);
180+
this.setPreviousStatement(true, null);
181+
this.setNextStatement(true, null);
182+
this.setColour(60);
183+
this.setTooltip("");
184+
this.setHelpUrl("");
185+
}
186+
};
187+
133188
Blockly.Blocks['xrp_sleep'] = {
134189
init: function () {
135190
this.appendDummyInput()

app/src/xrp_blocks_python.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,34 @@ Blockly.Python['xrp_seteffort'] = function (block) {
6161
return code;
6262
};
6363

64+
Blockly.Python['xrp_setencoderpos'] = function (block) {
65+
var value_l = Blockly.Python.valueToCode(block, 'LEFT', Blockly.Python.ORDER_ATOMIC);
66+
var value_r = Blockly.Python.valueToCode(block, 'RIGHT', Blockly.Python.ORDER_ATOMIC);
67+
var code = `drivetrain.set_encoder_position(${value_l}, ${value_r})\n`;
68+
return code;
69+
};
70+
6471
Blockly.Python['xrp_getsonardist'] = function (block) {
6572
var code = `sonar.distance`;
6673
return [code, Blockly.Python.ORDER_NONE];
6774
};
6875

76+
Blockly.Python['xrp_getrightencoder'] = function (block) {
77+
var code = `drivetrain.get_right_encoder_position()`;
78+
return [code, Blockly.Python.ORDER_NONE];
79+
};
80+
81+
Blockly.Python['xrp_getleftencoder'] = function (block) {
82+
var code = `drivetrain.get_left_encoder_position()`;
83+
return [code, Blockly.Python.ORDER_NONE];
84+
};
85+
86+
Blockly.Python['xrp_encoder_counts'] = function (block) {
87+
var ticks = block.getFieldValue('TICKS');
88+
var code = `drivetrain._set_encoder_ticks_per_rev(${ticks})\n`;
89+
return code;
90+
};
91+
6992
Blockly.Python['xrp_sleep'] = function (block) {
7093
var number_time = block.getFieldValue('TIME');
7194
// TODO: Assemble Python into code variable.

index.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,23 @@
426426
<block type="xrp_l_refl"></block>
427427
<block type="xrp_r_refl"></block>
428428
<block type="xrp_getsonardist"></block>
429+
<block type="xrp_setencoderpos">
430+
<value name="LEFT">
431+
<shadow type="math_number">
432+
<field name="NUM">0</field>
433+
</shadow>
434+
</value>
435+
<value name="RIGHT">
436+
<shadow type="math_number">
437+
<field name="NUM">0</field>
438+
</shadow>
439+
</value>
440+
</block>
441+
<block type="xrp_getleftencoder"></block>
442+
<block type="xrp_getrightencoder"></block>
443+
<block type="xrp_encoder_counts">
444+
<field name="TICKS">drivetrain._LEGACY_TICKS_PER_REV</field>
445+
</block>
429446
</category>
430447
<category name="Control Board" colour="#5C9AA6">
431448
<block type="xrp_led_br">
@@ -817,7 +834,7 @@
817834
<div class="row">
818835
<div class="col-8" id="blocklyArea">
819836
<div id="blocklyDiv"></div>
820-
<p id="codeVersion">v0.0.3</p>
837+
<p id="codeVersion">v0.0.4</p>
821838
</div>
822839
<div class="col-4">
823840
<div id="toggleOpen" class="toggleCode">

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "XRP-Blockly",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "XRP Blockly",
55
"main": "app/electron/main.js",
66
"scripts": {

0 commit comments

Comments
 (0)