Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior Tree Compilator PoC: Blockly -> PDDL #21 #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
Binary file added .vs/slnx.sqlite
Binary file not shown.
155 changes: 153 additions & 2 deletions blocks/operational_model_behavior_tree_PoC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@
<field name="HUE">150</field>
</block>
</value>
</block><block type="factory_base" id="=gu21?lVsQZUld#HASc?" deletable="false" movable="false" x="10" y="10">
</block>
<block type="factory_base" id="=gu21?lVsQZUld#HASc?" deletable="false" movable="false" x="10" y="10">
<mutation connections="BOTH"></mutation>
<field name="NAME">Act</field>
<field name="INLINE">AUTO</field>
Expand Down Expand Up @@ -838,4 +839,154 @@
<field name="HUE">345</field>
</block>
</value>
</block></xml>
</block>
<block type="factory_base" id="C71eeM34YccT84S|cw)q" deletable="false" movable="false" x="10" y="10">
<mutation connections="NONE"/>
<field name="NAME">User Object</field>
<field name="INLINE">EXT</field>
<field name="CONNECTIONS">NONE</field>
<statement name="INPUTS">
<block type="input_statement" id="q{L(aZkKm)tg0shCSG+0">
<field name="INPUTNAME">input_name</field>
<field name="ALIGN">LEFT</field>
<statement name="FIELDS">
<block type="field_input" id="{:gu3NA.y8Y[rUnE{b(R">
<field name="TEXT">Name</field>
<field name="FIELDNAME">var_name</field>
</block>
</statement>
<value name="TYPE">
<shadow type="type_null" id=",Kb:T)8!f~K!dNDrc}EX"/>
<block type="type_string" id="){6oS-z8}%T:L?W^5gaH"/>
</value>
<next>
<block type="input_value" id="c^uh()2~L4-HieBg$H=[">
<field name="INPUTNAME">input_age</field>
<field name="ALIGN">LEFT</field>
<statement name="FIELDS">
<block type="field_input" id="}~b|Gc6J_un~i))=l!)N">
<field name="TEXT">Age</field>
<field name="FIELDNAME">var_age</field>
</block>
</statement>
<value name="TYPE">
<shadow type="type_null" id="BRfwAft!F9S2nSg|`%a3"/>
<block type="type_number" id="M~Q!t[UNN7aUIik:DXUy"/>
</value>
<next>
<block type="input_statement" id="`_ii:$/lWD8Mic+/GVlm">
<field name="INPUTNAME">input_role</field>
<field name="ALIGN">LEFT</field>
<statement name="FIELDS">
<block type="field_dropdown" id="1Xx8T5b@j9=(`$Df(#Oc">
<mutation options="["text=""","text=""","text="""]"/>
<field name="FIELDNAME">Role</field>
<field name="USER0">Admin</field>
<field name="CPU0">var_admin</field>
<field name="USER1">User</field>
<field name="CPU1">var_user</field>
<field name="USER2">Developer</field>
<field name="CPU2">var_dev</field>
</block>
</statement>
<value name="TYPE">
<shadow type="type_null" id="slyik{k!fQ[K/D9_)i@y"/>
<block type="type_string" id=";l)#I2,o9c3vyu;zfqqB"/>
</value>
<next>
<block type="input_value" id="5,e3RDjGUSJ*.r{$~tUI">
<field name="INPUTNAME">user_id</field>
<field name="ALIGN">LEFT</field>
<statement name="FIELDS">
<block type="field_input" id="r#UStMR@V8|P.##o2}$E">
<field name="TEXT">User Id</field>
<field name="FIELDNAME">var_user_id</field>
</block>
</statement>
<value name="TYPE">
<shadow type="type_null" id="t7a,v887hoS!6y^,8Jf0"/>
<block type="type_number" id="(KO%ELIKlCv#Gx(uHX~b"/>
</value>
<next>
<block type="input_statement" id="YgUJiq}(MWx2doVN2#{G">
<field name="INPUTNAME">input_manager</field>
<field name="ALIGN">LEFT</field>
<statement name="FIELDS">
<block type="field_input" id="#p_^KRi{QdE/a]rJK@H3">
<field name="TEXT">Manger</field>
<field name="FIELDNAME">var_manager</field>
</block>
</statement>
<value name="TYPE">
<shadow type="type_null" id="ynusGJng3a.[@`Z-WyOW"/>
<block type="type_group" id="a6vqYH=@VnvF5oy5k2Gj">
<mutation types="2"/>
<value name="TYPE0">
<block type="type_string" id="cjm@s/imh-G{h}dk*|,F"/>
</value>
<value name="TYPE1">
<block type="type_list" id="px:I/mHrSOp14,ut7#N9"/>
</value>
</block>
</value>
<next>
<block type="input_statement" id="CiU]4RHuMSNM_-#Mn|0(">
<field name="INPUTNAME">input_profile_photo</field>
<field name="ALIGN">LEFT</field>
<statement name="FIELDS">
<block type="field_input" id="UPl6rRw#`l]49LK_{J@c">
<field name="TEXT">Profile Photo</field>
<field name="FIELDNAME">var_image_address</field>
<next>
<block type="field_image" id="=`U$2{/OLM^H^O{5G/2,">
<field name="SRC">https://www.gstatic.com/codesite/ph/images/star_on.gif</field>
<field name="WIDTH">15</field>
<field name="HEIGHT">15</field>
<field name="ALT">*</field>
<field name="FLIP_RTL">FALSE</field>
<next>
<block type="field_colour" id="EE0GCD~cl+18rdYAV]g-">
<field name="COLOUR">#ff0000</field>
<field name="FIELDNAME">NAME</field>
</block>
</next>
</block>
</next>
</block>
</statement>
<value name="TYPE">
<shadow type="type_null" id=")|f~6UMdxsh^[Ea0@tAM"/>
<block type="type_other" id="d{|oL8P8so^WZ^A.FLKF">
<field name="TYPE">Image address</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</statement>
<value name="TOOLTIP">
<block type="text" id="Rkt=:ZZz,6%T9)Okf2c7" deletable="false" movable="false">
<field name="TEXT"/>
</block>
</value>
<value name="HELPURL">
<block type="text" id="vbk^U|e_?+zC%vH$uT;l" deletable="false" movable="false">
<field name="TEXT"/>
</block>
</value>
<value name="COLOUR">
<block type="colour_hue" id="5^$D}S.r*CD7U1JdYJRB">
<mutation colour="#5b67a5"/>
<field name="HUE">230</field>
</block>
</value>
</block>
</xml>
37 changes: 37 additions & 0 deletions poc-blockly-bt/Content/VisualPDDL/js/btpddl_block_codegen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Blockly.JavaScript['sequence_BT'] = function(block) {
var text_name = block.getFieldValue('NAME');
// TODO: Assemble JavaScript into code variable.
var code = 'seqnode_' + text_name + ' = py_trees.composites.Sequence("'+ text_name+'")';
return code;
};

Blockly.JavaScript['condition_BT'] = function(block) {
var text_name = block.getFieldValue('NAME');
var dropdown_type = block.getFieldValue('type');
// TODO: Assemble JavaScript into code variable.
var code = ' ?' + text_name + ' - ' + dropdown_type;
return code;
};

Blockly.JavaScript['action_BT'] = function(block) {
var text_name = block.getFieldValue('NAME');
var dropdown_type = block.getFieldValue('type');
// TODO: Assemble JavaScript into code variable.
var code = ' ?' + text_name + ' - ' + dropdown_type;
return code;
};

Blockly.JavaScript['selector_BT'] = function(block) {
var text_name = block.getFieldValue('NAME');
// TODO: Assemble JavaScript into code variable.
var code = 'selnode_' + text_name + ' = py_trees.composites.Selector("'+ text_name+'")';
return code;
};


Blockly.JavaScript['parallel_BT'] = function(block) {
var text_name = block.getFieldValue('NAME');
// TODO: Assemble JavaScript into code variable.
var code = 'parnode_' + text_name + ' = py_trees.composites.Parallel("'+ text_name+'")';
return code;
};
109 changes: 109 additions & 0 deletions poc-blockly-bt/Content/VisualPDDL/js/btpddl_block_defs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
'use strict';

goog.require('Blockly.Blocks');
goog.require('Blockly');

// Selector composite UI
Blockly.Blocks['sequence_BT'] = {
init: function() {
// sequence composite behaviour name
this.appendDummyInput()
.appendField("sequence")
.appendField(new Blockly.FieldTextInput("name"), "NAME")
// sequence memory input UI
// when enabled if Tree RUNNING on the previous tick, resumes with the RUNNING child
this.appendDummyInput()
.appendField('memory')
.appendField(new Blockly.FieldDropdown([
['EN', 'EN_MEM'],
['DIS', 'DIS_MEM']
]), 'MEMORY');
// list of children to add in sequence
this.appendStatementInput("child")
.appendField("childs")
.setCheck("child");
this.setPreviousStatement(true, "child");
this.setNextStatement(true, "child");
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Blocks['condition_BT'] = {
init: function() {
this.appendStatementInput("PREDICATE_CALLS")
.setCheck("predicate_call")
.appendField("condition");
this.setPreviousStatement(true, "predicate_call");
this.setNextStatement(true, "predicate_call");
this.setColour(120);
this.setTooltip("");
this.setHelpUrl("");
}
};

Blockly.Blocks['action_BT'] = {
init: function() {
this.appendStatementInput("PREDICATE_CALLS")
.setCheck("predicate_call")
.appendField("action");
this.setPreviousStatement(true, "predicate_call");
this.setNextStatement(true, "predicate_call");
this.setColour(0);
this.setTooltip("");
this.setHelpUrl("");
}
};

// Selector composite UI
Blockly.Blocks['selector_BT'] = {
init: function() {
// selector composite behaviour name
this.appendDummyInput()
.appendField("selector")
.appendField(new Blockly.FieldTextInput("name"), "NAME")
// selector memory input UI
// when enabled if Tree RUNNING on the previous tick, resumes with the RUNNING child
this.appendDummyInput()
.appendField('memory')
.appendField(new Blockly.FieldDropdown([
['EN', 'EN_MEM'],
['DIS', 'DIS_MEM']
]), 'MEMORY');
// list of children to add
this.appendStatementInput("child")
.appendField("childs")
.setCheck("child");
this.setPreviousStatement(true, "child");
this.setNextStatement(true, "child");
this.setColour(60);
this.setTooltip("");
this.setHelpUrl("");
}
};

// Parallel composite UI
Blockly.Blocks['parallel_BT'] = {
init: function() {
// parallel composite behaviour name
this.appendDummyInput()
.appendField("parallel")
.appendField(new Blockly.FieldTextInput("name"), "NAME");
this.appendDummyInput()
.appendField('policy')
.appendField(new Blockly.FieldDropdown([
['optional', 'OP_POLICY'],
['base', 'B_POLICY']
]), 'POLICCY');
// list of children to add
this.appendStatementInput("child")
.appendField("childs")
.setCheck("child");
this.setPreviousStatement(true, "child");
this.setNextStatement(true, "child");
this.setColour(180);
this.setTooltip("");
this.setHelpUrl("");
}
};
2 changes: 1 addition & 1 deletion poc-blockly-bt/Content/VisualPDDL/js/vppdl_block_defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,4 @@ Blockly.Blocks['not'] = {
this.setTooltip("");
this.setHelpUrl("");
}
};
};
11 changes: 11 additions & 0 deletions poc-blockly-bt/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<script type="text/javascript" src="generators/javascript.js"></script>
<script type="text/javascript" src="Content/VisualPDDL/js/vppdl_block_codegen.js"></script>
<script type="text/javascript" src="Content/Blockly/js/msg/en.js"></script>
<!-- Behaviour Tree Block Definition and code generation scripts-->
<script type="text/javascript" src="Content/VisualPDDL/js/btpddl_block_codegen.js"></script>
<script type="text/javascript" src="Content/VisualPDDL/js/btpddl_block_defs.js"></script>
<!-- <script type="text/javascript" src="Content/Blockly/js/msg/messages.js"></script> -->

<!-- Global site tag (gtag.js) - Google Analytics -->
Expand Down Expand Up @@ -141,6 +144,14 @@ <h5 class="modal-title">4K photo</h5>
</block>
</category>
<category name="PDDL Predicates" colour="#995ba5" custom="PREDICATES"></category>
<category name="Behavior tree" colour="#5b67a5" class="list-group-item">
<block type="selector_BT"></block>
<block type="sequence_BT"></block>
<block type="parallel_BT"></block>
<block type="condition_BT"></block>
<block type="action_BT"></block>
<!-- <block type="not"></block> -->
</category>
</xml>

<div id="toast"></div>
Expand Down