Skip to content

Commit 7c86362

Browse files
committed
added blocks for tools category
1 parent e8b7b1f commit 7c86362

File tree

1 file changed

+177
-30
lines changed

1 file changed

+177
-30
lines changed

src/niryo_one_python_generators.js

Lines changed: 177 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,11 +1041,11 @@ Blockly.Blocks['niryo_one_tool_select'] = {
10411041
init: function () {
10421042
this.appendDummyInput().appendField(
10431043
new Blockly.FieldDropdown([
1044-
['Standard gripper', 'GRIPPER_1_ID'],
1045-
['Large gripper', 'GRIPPER_2_ID'],
1046-
['Adaptive gripper ', 'GRIPPER_3_ID'],
1047-
['Electromagnet 1', 'ELECTROMAGNET_1_ID'],
1048-
['Vacuum pump 1', 'VACUUM_PUMP_1_ID']
1044+
['Standard gripper', 'GRIPPER_1'],
1045+
['Large gripper', 'GRIPPER_2'],
1046+
['Adaptive gripper ', 'GRIPPER_3'],
1047+
['Electromagnet 1', 'ELECTROMAGNET_1'],
1048+
['Vacuum pump 1', 'VACUUM_PUMP_1']
10491049
]),
10501050
'TOOL_SELECT'
10511051
);
@@ -1056,6 +1056,16 @@ Blockly.Blocks['niryo_one_tool_select'] = {
10561056
}
10571057
};
10581058

1059+
Blockly.Blocks['niryo_one_get_current_tool_id'] = {
1060+
init: function () {
1061+
this.appendDummyInput().appendField('Get current tool id');
1062+
this.setOutput(true, 'niryo_one_tool_select');
1063+
this.setColour(tool_color);
1064+
this.setTooltip('');
1065+
this.setHelpUrl('');
1066+
}
1067+
};
1068+
10591069
Blockly.Blocks['niryo_one_update_tool'] = {
10601070
init: function () {
10611071
this.appendDummyInput().appendField('Update tool');
@@ -1067,16 +1077,31 @@ Blockly.Blocks['niryo_one_update_tool'] = {
10671077
}
10681078
};
10691079

1070-
// Blockly.Blocks['niryo_one_detach_tool'] = {
1071-
// init: function () {
1072-
// this.appendDummyInput().appendField('Detach current tool');
1073-
// this.setPreviousStatement(true, null);
1074-
// this.setNextStatement(true, null);
1075-
// this.setColour(tool_color);
1076-
// this.setTooltip('');
1077-
// this.setHelpUrl('');
1078-
// }
1079-
// };
1080+
Blockly.Blocks['niryo_one_grasp_with_tool'] = {
1081+
init: function () {
1082+
this.appendDummyInput().appendField('Grasp with tool');
1083+
this.setPreviousStatement(true, null);
1084+
this.setNextStatement(true, null);
1085+
this.setColour(tool_color);
1086+
this.setTooltip(
1087+
'Grasp with tool | This action correspond to | - Close gripper for Grippers | - Pull Air for Vacuum pump | - Activate for Electromagnet'
1088+
);
1089+
this.setHelpUrl('');
1090+
}
1091+
};
1092+
1093+
Blockly.Blocks['niryo_one_release_with_tool'] = {
1094+
init: function () {
1095+
this.appendDummyInput().appendField('Release with tool');
1096+
this.setPreviousStatement(true, null);
1097+
this.setNextStatement(true, null);
1098+
this.setColour(tool_color);
1099+
this.setTooltip(
1100+
'Release with tool | This action correspond to | - Open gripper for Grippers | - Push Air for Vacuum pump | - Deactivate for Electromagnet'
1101+
);
1102+
this.setHelpUrl('');
1103+
}
1104+
};
10801105

10811106
Blockly.Blocks['niryo_one_open_gripper'] = {
10821107
init: function () {
@@ -1195,6 +1220,68 @@ Blockly.Blocks['niryo_one_deactivate_electromagnet'] = {
11951220
}
11961221
};
11971222

1223+
Blockly.Blocks['niryo_one_enable_tcp'] = {
1224+
init: function () {
1225+
this.appendDummyInput()
1226+
.appendField('Enable TCP')
1227+
.appendField(
1228+
new Blockly.FieldDropdown([
1229+
['True', '1'],
1230+
['False', '0']
1231+
]),
1232+
'ENABLE_TCP'
1233+
);
1234+
this.setInputsInline(true);
1235+
this.setPreviousStatement(true, null);
1236+
this.setNextStatement(true, null);
1237+
this.setColour(tool_color);
1238+
this.setTooltip(
1239+
'Enables or disables the TCP function (Tool Center Point). If activation is requested, the last recorded TCP value will be applied. The default value depends on the gripper equipped. If deactivation is requested, the TCP will be coincident with the tool_link.'
1240+
);
1241+
this.setHelpUrl('');
1242+
}
1243+
};
1244+
1245+
Blockly.Blocks['niryo_one_set_tcp'] = {
1246+
init: function () {
1247+
this.appendValueInput('POSE')
1248+
.setCheck('niryo_one_pose')
1249+
.appendField('Set tcp with pose');
1250+
this.setTooltip(
1251+
'Activates the TCP function (Tool Center Point) and defines the transformation between the tool_link frame and the TCP frame.'
1252+
);
1253+
this.setPreviousStatement(true, null);
1254+
this.setNextStatement(true, null);
1255+
this.setColour(tool_color);
1256+
this.setHelpUrl('');
1257+
}
1258+
};
1259+
1260+
Blockly.Blocks['niryo_one_reset_tcp'] = {
1261+
init: function () {
1262+
this.appendDummyInput().appendField('Reset TCP');
1263+
this.setPreviousStatement(true, null);
1264+
this.setNextStatement(true, null);
1265+
this.setColour(tool_color);
1266+
this.setTooltip(
1267+
'Reset the TCP (Tool Center Point) transformation. The TCP will be reset according to the tool equipped.'
1268+
);
1269+
this.setHelpUrl('');
1270+
}
1271+
};
1272+
1273+
Blockly.Blocks['niryo_one_tool_reboot'] = {
1274+
init: function () {
1275+
this.appendDummyInput().appendField('Reboot tool');
1276+
this.setPreviousStatement(true, null);
1277+
this.setNextStatement(true, null);
1278+
this.setColour(tool_color);
1279+
this.setTooltip(
1280+
'Reboot the motor of the tool equparam_list = [workspace_name]'
1281+
);
1282+
this.setHelpUrl('');
1283+
}
1284+
};
11981285
// Utility
11991286

12001287
Blockly.Blocks['niryo_one_wait'] = {
@@ -1496,10 +1583,6 @@ Blockly.Blocks['niryo_one_play_sound'] = {
14961583
.setCheck('String')
14971584
.appendField('Play sound named');
14981585

1499-
// this.appendValueInput('WAIT_END')
1500-
// .setcheck('Boolean')
1501-
// .appendField('wait until the end');
1502-
15031586
this.appendDummyInput().appendField('wait until the end');
15041587
this.appendDummyInput().appendField(
15051588
new Blockly.FieldDropdown([
@@ -2186,8 +2269,24 @@ BlocklyPy['niryo_one_set_12v_switch'] = function (block) {
21862269
// Tool
21872270

21882271
BlocklyPy['niryo_one_tool_select'] = function (block) {
2189-
var dropdown_tool_select = block.getFieldValue('TOOL_SELECT');
2190-
var code = dropdown_tool_select;
2272+
const tool_id_map = {
2273+
NONE: 0,
2274+
GRIPPER_1: 11,
2275+
GRIPPER_2: 12,
2276+
GRIPPER_3: 13,
2277+
ELECTROMAGNET_1: 30,
2278+
VACUUM_PUMP_1: 31
2279+
};
2280+
var tool_model_id = block.getFieldValue('TOOL_SELECT');
2281+
var code = tool_id_map[tool_model_id];
2282+
2283+
// var dropdown_tool_select = block.getFieldValue('TOOL_SELECT');
2284+
// var code = dropdown_tool_select;
2285+
return [code, BlocklyPy.ORDER_NONE];
2286+
};
2287+
2288+
BlocklyPy['niryo_one_get_current_tool_id'] = function (block) {
2289+
var code = 'n.get_current_tool_id()\n';
21912290
return [code, BlocklyPy.ORDER_NONE];
21922291
};
21932292

@@ -2196,11 +2295,15 @@ BlocklyPy['niryo_one_update_tool'] = function (block) {
21962295
return code;
21972296
};
21982297

2199-
// new function corresponds to release_with_tool (made in pair with grasp_with_tool)
2200-
// BlocklyPy['niryo_one_detach_tool'] = function (block) {
2201-
// var code = 'n.change_tool(0)\n';
2202-
// return code;
2203-
// };
2298+
BlocklyPy['niryo_one_grasp_with_tool'] = function (block) {
2299+
var code = 'n.grasp_with_tool()\n';
2300+
return [code, BlocklyPy.ORDER_NONE];
2301+
};
2302+
2303+
BlocklyPy['niryo_one_release_with_tool'] = function (block) {
2304+
var code = 'n.release_with_tool()\n';
2305+
return [code, BlocklyPy.ORDER_NONE];
2306+
};
22042307

22052308
BlocklyPy['niryo_one_open_gripper'] = function (block) {
22062309
var number_open_speed = block.getFieldValue('OPEN_SPEED');
@@ -2266,6 +2369,30 @@ BlocklyPy['niryo_one_deactivate_electromagnet'] = function (block) {
22662369
return code;
22672370
};
22682371

2372+
BlocklyPy['niryo_one_enable_tcp'] = function (block) {
2373+
var dropdown_enable_tcp = block.getFieldValue('ENABLE_TCP');
2374+
var code = 'n.enable_tcp(' + dropdown_enable_tcp + ')\n';
2375+
return [code, BlocklyPy.ORDER_NONE];
2376+
};
2377+
2378+
BlocklyPy['niryo_one_set_tcp'] = function (block) {
2379+
var value_pose = BlocklyPy.valueToCode(block, 'POSE', BlocklyPy.ORDER_ATOMIC);
2380+
value_pose = value_pose.replace('(', '').replace(')', '');
2381+
2382+
var code = 'n.set_tcp(' + value_pose + ')\n';
2383+
return code;
2384+
};
2385+
2386+
BlocklyPy['niryo_one_reset_tcp'] = function (block) {
2387+
var code = 'n.reset_tcp()\n';
2388+
return code;
2389+
};
2390+
2391+
BlocklyPy['niryo_one_tool_reboot'] = function (block) {
2392+
var code = 'n.tool_reboot()\n';
2393+
return code;
2394+
};
2395+
22692396
// Utility
22702397

22712398
BlocklyPy['niryo_one_wait'] = function (block) {
@@ -3067,14 +3194,22 @@ const TOOLBOX = {
30673194
kind: 'BLOCK',
30683195
type: 'niryo_one_tool_select'
30693196
},
3197+
{
3198+
kind: 'BLOCK',
3199+
type: 'niryo_one_get_current_tool_id'
3200+
},
30703201
{
30713202
kind: 'BLOCK',
30723203
type: 'niryo_one_update_tool'
30733204
},
3074-
// {
3075-
// kind: 'BLOCK',
3076-
// type: 'niryo_one_detach_tool'
3077-
// },
3205+
{
3206+
kind: 'BLOCK',
3207+
type: 'niryo_one_grasp_with_tool'
3208+
},
3209+
{
3210+
kind: 'BLOCK',
3211+
type: 'niryo_one_release_with_tool'
3212+
},
30783213
{
30793214
kind: 'BLOCK',
30803215
type: 'niryo_one_open_gripper'
@@ -3103,6 +3238,18 @@ const TOOLBOX = {
31033238
kind: 'BLOCK',
31043239
type: 'niryo_one_deactivate_electromagnet'
31053240
},
3241+
{
3242+
kind: 'BLOCK',
3243+
type: 'niryo_one_set_tcp'
3244+
},
3245+
{
3246+
kind: 'BLOCK',
3247+
type: 'niryo_one_reset_tcp'
3248+
},
3249+
{
3250+
kind: 'BLOCK',
3251+
type: 'niryo_one_tool_reboot'
3252+
},
31063253
{
31073254
kind: 'BLOCK',
31083255
type: 'niryo_one_wait'

0 commit comments

Comments
 (0)