blocks: add block for reading RC values

This commit is contained in:
Oleg Kalachev
2023-04-11 19:35:00 +03:00
parent 28ddbbcdf9
commit cbba62d165
3 changed files with 22 additions and 0 deletions

View File

@@ -269,6 +269,19 @@ Blockly.Blocks['voltage'] = {
}
};
Blockly.Blocks['get_rc'] = {
init: function () {
this.appendDummyInput()
.appendField("RC channel")
this.appendValueInput("CHANNEL")
.setCheck("Number");
this.setInputsInline(true);
this.setOutput(true, "Number");
this.setColour(COLOR_STATE);
this.setTooltip("Returns current RC channel value.");
this.setHelpUrl(DOCS_URL + '#' + this.type);
}
}
Blockly.Blocks['armed'] = {
init: function () {

View File

@@ -100,6 +100,9 @@
<block type="mode"></block>
<block type="armed"></block>
<block type="voltage"></block>
<block type="get_rc">
<value name="CHANNEL"><shadow type="math_number"><field name="NUM">0</field></shadow></value>
</block>
</category>
<category name="LED" colour="#02d754">
<block type="set_effect">

View File

@@ -402,6 +402,12 @@ Blockly.Python.voltage = function(block) {
return [code, Blockly.Python.ORDER_FUNCTION_CALL];
}
Blockly.Python.get_rc = function(block) {
Blockly.Python.definitions_['import_rcin'] = 'from mavros_msgs.msg import RCIn';
var channel = Blockly.Python.valueToCode(block, 'CHANNEL', Blockly.Python.ORDER_NONE);
return [`rospy.wait_for_message('mavros/rc/in', RCIn).channels[${channel}]`, Blockly.Python.ORDER_FUNCTION_CALL]
}
function parseColor(color) {
return {
r: parseInt(color.substr(2, 2), 16),