forked from CentroEPiaggio/kuka-lwr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ros_control.src
189 lines (162 loc) · 4.93 KB
/
ros_control.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
&ACCESS RVP
&REL 3
&PARAM TEMPLATE = C:\KRC\Roboter\Template\vorgabe
&PARAM EDITMASK = *
DEF ros_control( )
;FOLD INI
;FOLD BASISTECH INI
GLOBAL INTERRUPT DECL 3 WHEN $STOPMESS==TRUE DO IR_STOPM ( )
INTERRUPT ON 3
BAS (#INITMOV,0 )
;ENDFOLD (BASISTECH INI)
;FOLD USER INI
;Make your modifications here
;ENDFOLD (USER INI)
;ENDFOLD (INI)
;FOLD Contact information
;-----------------------------------------------
; KRL script to be used with the pkgs in
; https://github.com/CentroEPiaggio/kuka-lwr
;
; Author: Carlos J. Rosales, [email protected]
;-----------------------------------------------
;ENDFOLD (Contact information)
;FOLD Variable definitions
; ----------------------------------------------
;
; INDEXES: IN KRL [1-16] / IN C++ [0-15]
;
; ----------------------------------------------
; $FRI_FRM_INT[1]
; This value is used to read from the remote
; the desired control strategy, i.e.
;
; 10 -> joint position control
; 20 -> Cartesian impedance control
; 30 -> joint impedance control
;
; An stopFRI() - setToKRLInt(0, $) - startFRI()
; sequence must be performed in the remote.
; ----------------------------------------------
; $FRI_FRM_INT[2]
; This value is used to call friStart() or
; friStop() from the remote
;
; 1 -> to call friStart()
; 0 -> to call fiStop()
; ----------------------------------------------
; $FRI_TO_INT[2]
; This value is used to tell the remote that
; either friStart() or friStop() was called
;
; 0 -> fiStop() was called
; 1 -> friStart() was called
; 10 -> Init flag, to avoid cyclic start/stop
; ----------------------------------------------
; $FRI_FRM_INT[16] AND $FRI_TO_INT[16]
; $FRI_FRM_REA[16] AND $FRI_TO_REA[16]
;
; These values are used for the handshake
; ----------------------------------------------
;ENDFOLD (Variable definitions)
;FOLD Init
;Close and stop the communication in case it is open
retVal = friStop()
retVal = friClose()
;Reset FRI values
FOR I = 1 TO 16
$FRI_TO_INT[i] = 0
$FRI_TO_REA[i] = 0.0
ENDFOR
;Init flag
$FRI_TO_INT[2] = 10
; Stay at the same position
PTP $AXIS_ACT_MES
;Impedance default parameters
;$stiffness.axisstiffness={A1 1000, A2 1000, A3 1000, A4 1000, A5 1000, A6 1000, E1 1000}
;$stiffness.axisdamping = {A1 0.7, A2 0.7, A3 0.7, A4 0.7, A5 0.7, A6 0.7, E1 0.7}
$stiffness.axismaxdeltatrq={A1 100, A2 100, A3 100, A4 100, A5 100, A6 30, E1 30}
$stiffness.axismaxdelta = {A1 100.0, A2 100.0, A3 100.0, A4 100.0, A5 100.0, A6 100.0, E1 100.0}
;Start with position control
$stiffness.strategy = 10
$stiffness.commit = true
;ENDFOLD (init)
;Input correct tool number here and restart
BAS (#tool,1 )
;Specify ip and port
retVal = friSetup("192.168.0.150", 49939, 49939)
;Open FRI with datarate 2 msec
retVal=friOpen(2)
;FOLD Screen output
WAIT FOR ($FriState == #MON)
$MSG_T.KEY[] = "FRI successfully opened."
$MSG_T.VALID = TRUE
WAIT SEC 0.3
;ENDFOLD (Screen output)
;The infinite loop
LOOP
;stopFRI() from remote
IF ($FRI_FRM_INT[2] == 0) AND ($FRI_TO_INT[2] == 1) THEN
;FOLD Screen output
$MSG_T.KEY[] = "Stopping FRI..."
$MSG_T.VALID = TRUE
WAIT SEC 0.5
;ENDFOLD (Screen output)
retVal = friStop()
$FRI_TO_INT[2] = 0
WAIT FOR ($FriState == #MON)
;FOLD Screen output
$MSG_T.KEY[] = "FRI successfully stopped."
$MSG_T.VALID = TRUE
WAIT SEC 0.5
;ENDFOLD (Screen output)
ENDIF
;startFRI() from remote in desired strategy
IF ($FRI_FRM_INT[2] == 1) AND ($FRI_TO_INT[2] <> 1) THEN
;Only change strategy after init
IF ($FRI_TO_INT[2] <> 10) THEN
$stiffness.strategy = $FRI_FRM_INT[1]
$stiffness.commit = true
ENDIF
;FOLD Screen output
$MSG_T.KEY[] = "Starting FRI..."
$MSG_T.VALID = TRUE
WAIT SEC 0.5
;ENDFOLD (Screen output)
;Please, start the ROS node.
WAIT FOR ($FriQuality == #PERFECT)
;Due to init, wait to actually trigger the start
WAIT FOR $FRI_FRM_INT[2] == 1
retVal = friStart(1.0)
WAIT FOR ($FriState == #CMD)
$FRI_TO_INT[2] = 1
;FOLD Screen output
$MSG_T.KEY[] = "FRI successfully started."
$MSG_T.VALID = TRUE
WAIT SEC 0.5
;ENDFOLD (Screen output)
;FOLD Screen output
IF ($stiffness.strategy == 10) THEN
$MSG_T.KEY[] = "ControlStrategy changed to JOINT_POSITION"
ELSE
IF($stiffness.strategy == 20) THEN
$MSG_T.KEY[] = "ControlStrategy changed to CARTESIAN_IMPEDANCE"
ELSE
IF ($stiffness.strategy == 30) THEN
$MSG_T.KEY[] = "ControlStrategy changed to JOINT_IMPEDANCE"
ELSE
$MSG_T.KEY[] = "ERROR: Unknown ControlStrategy."
ENDIF
ENDIF
ENDIF
$MSG_T.VALID = TRUE
;ENDFOLD (Screen output)
ENDIF
;FRI / ROS control - communication activated
WAIT SEC 0.05
ENDLOOP
;Stop and close when done
retVal = friStop()
WAIT sec 0.5
retVal = friClose()
END