Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions js/xrp_blockly_toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ var baseToolbox = {
{
"kind": "BLOCK",
"type": "math_random_float"
},
{
"kind": "BLOCK",
"type": "xrp_deadband",
"inputs":{
"VALUE": {"shadow": {"type": "math_number", "fields": {"NUM": "1"}}},
"DEADBAND": {"shadow": {"type": "math_number", "fields": {"NUM": "0.1"}}}
}
}
],
"name": "Math",
Expand Down
18 changes: 18 additions & 0 deletions js/xrp_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,24 @@ Blockly.Blocks['xrp_sleep'] = {
}
};

// Math
Blockly.Blocks['xrp_deadband'] = {
init: function () {
this.appendDummyInput()
.appendField("set the value:");
this.appendValueInput("VALUE")
.setCheck("Number");
this.appendValueInput("DEADBAND")
.setCheck("Number")
.appendField("to 0 if the value is less than:");
this.setInputsInline(true);
this.setOutput(true, "Number");
this.setColour(230); // indigo
this.setTooltip("Sets the value to 0 if it is within the deadband range, which is useful for filtering drift from joysticks");
this.setHelpUrl("");
}
}

// OTHER BLOCK COLORS - These colors can be found in the xrp_blockly_toolbox1.js file
// BLOCK TYPE --> COLOR
// Loops --> grass green
Expand Down
8 changes: 8 additions & 0 deletions js/xrp_blocks_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ Blockly.Python['xrp_sleep'] = function (block) {
return code;
};

//Math
Blockly.Python['xrp_deadband'] = function (block) {
var number_value = Blockly.Python.valueToCode(block, 'VALUE', Blockly.Python.ORDER_ATOMIC);
var number_deadband = Blockly.Python.valueToCode(block, 'DEADBAND', Blockly.Python.ORDER_ATOMIC);
var code = `(${number_value} if abs(${number_value}) > ${number_deadband} else 0)`;
return [code, Blockly.Python.ORDER_ATOMIC];
}

Blockly.Python['comment'] = function(block) {
var text = block.getFieldValue('TEXT');
return '# ' + text + '\n';
Expand Down