mirror of
https://github.com/CopterExpress/clover.git
synced 2026-05-26 11:43:25 +00:00
blocks: add block for reading RC values
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user