@@ -59,7 +59,26 @@ const g_shape_values = {
59
59
*/
60
60
61
61
// 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
+ } ;
63
82
Blockly . Blocks [ 'niryo_one_move_joints' ] = {
64
83
init : function ( ) {
65
84
this . appendDummyInput ( ) . appendField ( 'Move Joints' ) ;
@@ -861,7 +880,34 @@ Blockly.Blocks['niryo_one_conveyor_stop'] = {
861
880
* Generators
862
881
*/
863
882
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
+ } ;
865
911
866
912
Blockly . Python [ 'niryo_one_move_joints' ] = function ( block ) {
867
913
var number_joints_1 = block . getFieldValue ( 'JOINTS_1' ) ;
@@ -1921,9 +1967,177 @@ const TOOLBOX = {
1921
1967
colour : '210' ,
1922
1968
name : 'Niryo' ,
1923
1969
contents : [
1970
+ {
1971
+ kind : 'BLOCK' ,
1972
+ type : 'niryo_one_connect'
1973
+ } ,
1924
1974
{
1925
1975
kind : 'BLOCK' ,
1926
1976
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'
1927
2141
}
1928
2142
]
1929
2143
}
0 commit comments