Skip to content

Commit 58e05ae

Browse files
authored
Merge pull request #25 from DenisaCG/ROS-niryo
Niryo One in Blockly
2 parents 24b2db3 + 2994db3 commit 58e05ae

File tree

2 files changed

+384
-162
lines changed

2 files changed

+384
-162
lines changed

src/niryo/niryo_one_python_generators.js

Lines changed: 216 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,26 @@ const g_shape_values = {
5959
*/
6060

6161
// Movement
62-
62+
Blockly.Blocks['niryo_one_connect'] = {
63+
init: function () {
64+
this.appendDummyInput().appendField('IP Address');
65+
this.appendDummyInput()
66+
.appendField(new Blockly.FieldNumber(10, 0, 255, 0), 'ip_0')
67+
.appendField('.')
68+
.appendField(new Blockly.FieldNumber(10, 0, 255, 0), 'ip_1')
69+
.appendField('.')
70+
.appendField(new Blockly.FieldNumber(10, 0, 255, 0), 'ip_2')
71+
.appendField('.')
72+
.appendField(new Blockly.FieldNumber(10, 0, 255, 0), 'ip_3');
73+
this.appendStatementInput('DO');
74+
this.setInputsInline(true);
75+
this.setPreviousStatement(false, null);
76+
this.setNextStatement(false, null);
77+
this.setColour(function_color);
78+
this.setTooltip('Connect to the robot and disconnects after the execution');
79+
this.setHelpUrl('');
80+
}
81+
};
6382
Blockly.Blocks['niryo_one_move_joints'] = {
6483
init: function () {
6584
this.appendDummyInput().appendField('Move Joints');
@@ -861,7 +880,34 @@ Blockly.Blocks['niryo_one_conveyor_stop'] = {
861880
* Generators
862881
*/
863882

864-
// Movement
883+
const connexion = `
884+
from contextlib import contextmanager
885+
from pyniryo import *
886+
887+
@contextmanager
888+
def niryo_connect(ip):
889+
n = NiryoRobot(ip)
890+
try:
891+
yield n
892+
except:
893+
n.close_connection()
894+
raise
895+
else:
896+
n.close_connection()
897+
`;
898+
899+
Blockly.Python['niryo_one_connect'] = function (block) {
900+
var ip_0 = block.getFieldValue('ip_0');
901+
var ip_1 = block.getFieldValue('ip_1');
902+
var ip_2 = block.getFieldValue('ip_2');
903+
var ip_3 = block.getFieldValue('ip_3');
904+
905+
let branch = Blockly.Python.statementToCode(block, 'DO');
906+
var ip = ip_0 + '.' + ip_1 + '.' + ip_2 + '.' + ip_3;
907+
908+
var code = connexion + '\nwith niryo_connect("' + ip + '") as n:\n' + branch;
909+
return code;
910+
};
865911

866912
Blockly.Python['niryo_one_move_joints'] = function (block) {
867913
var number_joints_1 = block.getFieldValue('JOINTS_1');
@@ -1921,9 +1967,177 @@ const TOOLBOX = {
19211967
colour: '210',
19221968
name: 'Niryo',
19231969
contents: [
1970+
{
1971+
kind: 'BLOCK',
1972+
type: 'niryo_one_connect'
1973+
},
19241974
{
19251975
kind: 'BLOCK',
19261976
type: 'niryo_one_move_joints'
1977+
},
1978+
{
1979+
kind: 'BLOCK',
1980+
type: 'niryo_one_move_pose'
1981+
},
1982+
{
1983+
kind: 'BLOCK',
1984+
type: 'niryo_one_shift_pose'
1985+
},
1986+
{
1987+
kind: 'BLOCK',
1988+
type: 'niryo_one_set_arm_max_speed'
1989+
},
1990+
{
1991+
kind: 'BLOCK',
1992+
type: 'niryo_one_calibrate_auto'
1993+
},
1994+
{
1995+
kind: 'BLOCK',
1996+
type: 'niryo_one_calibrate_manual'
1997+
},
1998+
{
1999+
kind: 'BLOCK',
2000+
type: 'niryo_one_activate_learning_mode'
2001+
},
2002+
{
2003+
kind: 'BLOCK',
2004+
type: 'niryo_one_joint'
2005+
},
2006+
{
2007+
kind: 'BLOCK',
2008+
type: 'niryo_one_move_joint_from_joint'
2009+
},
2010+
{
2011+
kind: 'BLOCK',
2012+
type: 'niryo_one_move_pose_from_pose'
2013+
},
2014+
{
2015+
kind: 'BLOCK',
2016+
type: 'niryo_one_pose'
2017+
},
2018+
{
2019+
kind: 'BLOCK',
2020+
type: 'niryo_one_move_pose_from_pose'
2021+
},
2022+
{
2023+
kind: 'BLOCK',
2024+
type: 'niryo_one_pick_from_pose'
2025+
},
2026+
{
2027+
kind: 'BLOCK',
2028+
type: 'niryo_one_place_from_pose'
2029+
},
2030+
{
2031+
kind: 'BLOCK',
2032+
type: 'niryo_one_gpio_select'
2033+
},
2034+
{
2035+
kind: 'BLOCK',
2036+
type: 'niryo_one_set_pin_mode'
2037+
},
2038+
{
2039+
kind: 'BLOCK',
2040+
type: 'niryo_one_digital_write'
2041+
},
2042+
{
2043+
kind: 'BLOCK',
2044+
type: 'niryo_one_digital_read'
2045+
},
2046+
{
2047+
kind: 'BLOCK',
2048+
type: 'niryo_one_gpio_state'
2049+
},
2050+
{
2051+
kind: 'BLOCK',
2052+
type: 'niryo_one_sw_select'
2053+
},
2054+
{
2055+
kind: 'BLOCK',
2056+
type: 'niryo_one_set_12v_switch'
2057+
},
2058+
{
2059+
kind: 'BLOCK',
2060+
type: 'niryo_one_tool_select'
2061+
},
2062+
{
2063+
kind: 'BLOCK',
2064+
type: 'niryo_one_change_tool'
2065+
},
2066+
{
2067+
kind: 'BLOCK',
2068+
type: 'niryo_one_detach_tool'
2069+
},
2070+
{
2071+
kind: 'BLOCK',
2072+
type: 'niryo_one_open_gripper'
2073+
},
2074+
{
2075+
kind: 'BLOCK',
2076+
type: 'niryo_one_close_gripper'
2077+
},
2078+
{
2079+
kind: 'BLOCK',
2080+
type: 'niryo_one_pull_air_vacuum_pump'
2081+
},
2082+
{
2083+
kind: 'BLOCK',
2084+
type: 'niryo_one_push_air_vacuum_pump'
2085+
},
2086+
{
2087+
kind: 'BLOCK',
2088+
type: 'niryo_one_setup_electromagnet'
2089+
},
2090+
{
2091+
kind: 'BLOCK',
2092+
type: 'niryo_one_activate_electromagnet'
2093+
},
2094+
{
2095+
kind: 'BLOCK',
2096+
type: 'niryo_one_deactivate_electromagnet'
2097+
},
2098+
{
2099+
kind: 'BLOCK',
2100+
type: 'niryo_one_sleep'
2101+
},
2102+
{
2103+
kind: 'BLOCK',
2104+
type: 'niryo_one_comment'
2105+
},
2106+
{
2107+
kind: 'BLOCK',
2108+
type: 'niryo_one_break_point'
2109+
},
2110+
{
2111+
kind: 'BLOCK',
2112+
type: 'niryo_one_vision_color'
2113+
},
2114+
{
2115+
kind: 'BLOCK',
2116+
type: 'niryo_one_vision_shape'
2117+
},
2118+
{
2119+
kind: 'BLOCK',
2120+
type: 'niryo_one_vision_pick'
2121+
},
2122+
{
2123+
kind: 'BLOCK',
2124+
type: 'niryo_one_vision_is_object_detected'
2125+
},
2126+
{
2127+
kind: 'BLOCK',
2128+
type: 'niryo_one_conveyor_models'
2129+
},
2130+
{
2131+
kind: 'BLOCK',
2132+
type: 'niryo_one_conveyor_use'
2133+
},
2134+
{
2135+
kind: 'BLOCK',
2136+
type: 'niryo_one_conveyor_control'
2137+
},
2138+
{
2139+
kind: 'BLOCK',
2140+
type: 'niryo_one_conveyor_stop'
19272141
}
19282142
]
19292143
}

0 commit comments

Comments
 (0)