-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExample.py
142 lines (109 loc) · 5.47 KB
/
Example.py
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
'''
Python 3.x library to control an UR robot through its TCP/IP interfaces
Copyright (C) 2017 Martin Huus Bjerge, Rope Robotics ApS, Denmark
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL "Rope Robotics ApS" BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of "Rope Robotics ApS" shall not be used
in advertising or otherwise to promote the sale, use or other dealings in this Software
without prior written authorization from "Rope Robotics ApS".
'''
__author__ = "Martin Huus Bjerge"
__copyright__ = "Copyright 2017, Rope Robotics ApS, Denmark"
__license__ = "MIT License"
import URBasic
import time
host = '127.0.0.1' #E.g. a Universal Robot offline simulator, please adjust to match your IP
acc = 0.9
vel = 0.9
def ExampleurScript():
'''
This is a small example of how to connect to a Universal Robots robot and use a few simple script commands.
The scrips available is in general all the scrips from the universal robot script manual,
and the implementation is intended to follow the Universal Robots manual as much as possible.
This script can be run connected to a Universal Robot robot (tested at a UR5) or a Universal Robot offline simulator.
See this example in how to setup an offline simulator:
https://www.universal-robots.com/download/?option=26266#section16597
'''
robotModle = URBasic.robotModel.RobotModel()
robot = URBasic.urScriptExt.UrScriptExt(host=host,robotModel=robotModle)
robot.reset_error()
robot.init_realtime_control()
import math
X = 0
Z = 0
r = 10
for x in range(0,200):
X = math.sin(x*6.28/20) *40 + 150
Z = math.cos(x*6.28/20) *40 +150
print(X,Z)
robot.set_realtime_pose([X*0.001,0.3,Z*0.001, 0,3.14,0])
time.sleep(0.1)
robot.set_realtime_pose([0.33,0.3,0.3, 0,3.14,0])
time.sleep(1)
robot.set_realtime_pose([0.3,0.3,0.3, 0,3.14,0])
# robot.set_realtime_pose([-3,-1.,0.5, -1.,-1.5,0])
# time.sleep(0.5)
# print('movej with joint specification')
# robot.movej(q=[-3.14,-1.,0.5, -1.,-1.5,0], a=acc, v=vel)
# print('movej with pose specification')
# robot.movej(pose=[0.3,0.3,0.3, 0,3.14,0], a=1.2, v=vel)
# print('movel with pose specification')
# robot.movel(pose=[0.3,-0.3,0.3, 0,3.14,0], a=1.2, v=vel)
# print('forcs_mode')
#robot.force_mode(task_frame=[0., 0., 0., 0., 0., 0.], selection_vector=[0,0,1,0,0,0], wrench=[0., 0., -20., 0., 0., 0.], f_type=2, limits=[2, 2, 1.5, 1, 1, 1])
time.sleep(1)
robot.end_force_mode()
robot.close()
def ExampleExtendedFunctions():
'''
This is an example of an extension to the Universal Robot script library.
How to update the force parameters remote via the RTDE interface,
hence without sending new programs to the controller.
This enables to update force "realtime" (125Hz)
'''
robotModle = URBasic.robotModel.RobotModel()
robot = URBasic.urScriptExt.UrScriptExt(host=host,robotModel=robotModle)
print('forcs_remote')
robot.set_force_remote(task_frame=[0., 0., 0., 0., 0., 0.], selection_vector=[0,0,1,0,0,0], wrench=[0., 0., 20., 0., 0., 0.], f_type=2, limits=[2, 2, 1.5, 1, 1, 1])
robot.reset_error()
a = 0
upFlag = True
while a<3:
pose = robot.get_actual_tcp_pose()
if pose[2]>0.1 and upFlag:
print('Move Down')
robot.set_force_remote(task_frame=[0., 0., 0., 0., 0., 0.], selection_vector=[0,0,1,0,0,0], wrench=[0., 0., -20., 0., 0., 0.], f_type=2, limits=[2, 2, 1.5, 1, 1, 1])
a +=1
upFlag = False
if pose[2]<0.0 and not upFlag:
print('Move Up')
robot.set_force_remote(task_frame=[0., 0., 0., 0., 0., 0.], selection_vector=[0,0,1,0,0,0], wrench=[0., 0., 20., 0., 0., 0.], f_type=2, limits=[2, 2, 1.5, 1, 1, 1])
upFlag = True
robot.end_force_mode()
robot.reset_error()
robot.close()
def ExampleFT_sensor():
'''
This is a small example of how to connect to a Robotiq FORCE TORQUE SENSOR and read data from the sensor.
To run this part comment in the function call in the main call below.
'''
robotModle = URBasic.robotModel.RobotModel()
robot = URBasic.urScriptExt.UrScriptExt(host=host,robotModel=robotModle,hasForceTorque=True)
print(robotModle.dataDir['urPlus_force_torque_sensor'])
time.sleep(1)
print(robotModle.dataDir['urPlus_force_torque_sensor'])
robot.close()
if __name__ == '__main__':
ExampleurScript()
#ExampleExtendedFunctions()
#ExampleFT_sensor()