-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollision_testing.py
172 lines (151 loc) · 5.76 KB
/
collision_testing.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
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
import os
import time
import pybullet as p
if os.environ.get('ROS_DISTRO'):
import rospy
import numpy as np
from cairo_simulator.core.sim_context import SawyerTSRSimContext
from cairo_simulator.core.utils import ASSETS_PATH
from cairo_planning.collisions import DisabledCollisionsContext
from cairo_planning.geometric.transformation import quat2rpy
global dist, inc
inc = 3
dist = .025
def main():
config = {}
config["sawyer"] = {
"robot_name": "sawyer0",
'urdf_file': ASSETS_PATH + 'sawyer_description/urdf/sawyer_static_blockcombine.urdf',
"position": [0, 0, 0.9],
"fixed_base": True
}
config["sim_objects"] = [
{
"object_name": "Ground",
"model_file_or_sim_id": "plane.urdf",
"position": [0, 0, 0]
},
{
"object_name": "Table",
"model_file_or_sim_id": ASSETS_PATH + 'table.sdf',
"position": [0.9, 0, 0],
"orientation": [0, 0, 1.5708]
},
]
config["primitives"] = [
{
"type": "box",
"primitive_configs": {"w": .2, "l": .45, "h": .35},
"sim_object_configs":
{
"object_name": "box",
"position": [.6, 0, .7],
"orientation": [0, 0, 0],
"fixed_base": 1
}
},
{
"type": "box",
"primitive_configs": {"w": .2, "l": .45, "h": .35},
"sim_object_configs":
{
"object_name": "box",
"position": [.9, 0, .7],
"orientation": [0, 0, 0],
"fixed_base": 1
}
},
]
start = [
0.673578125,
-0.2995908203125,
-0.21482421875,
1.4868740234375,
0.53829296875,
0.4117080078125,
-1.2169501953125]
sim_context = SawyerTSRSimContext(configuration=config)
sim = sim_context.get_sim_instance()
logger = sim_context.get_logger()
# _ = sim_context.get_state_space()
sawyer_robot = sim_context.get_robot()
# _ = sawyer_robot.get_simulator_id()
_ = sim_context.get_sim_objects(['Ground'])[0]
svc = sim_context.get_state_validity()
sawyer_robot.set_joint_state(start)
time.sleep(5)
key_u = ord('u') #y up
key_h = ord('h') #x down
key_j = ord('j') #y down
key_k = ord('k') #x up
key_o = ord('o') #z up
key_l = ord('l') #z downkey_8 = ord('8')
key_d = ord('d')
key_q = ord('q')
keys = p.getKeyboardEvents()
joint_config = sawyer_robot.get_current_joint_states()[0:7]
print(joint_config)
fk_results = sawyer_robot.solve_forward_kinematics(joint_configuration=joint_config)
print(fk_results)
xcurrent, ycurrent, zcurrent = fk_results[0][0]
orientation = fk_results[0][1]
input("Press any key to continue")
increment = [.0025, .025, .25]
def print_info(joint_config):
result = sawyer_robot.solve_forward_kinematics(joint_configuration=joint_config)
print(result)
print(quat2rpy(result[0][1]))
print(svc.validate(joint_config))
i = 3
global dist
def set_distance():
global dist
global inc
dist = increment[inc % 3]
inc += 1
print("DISTANCE IS NOW: {}".format(dist))
with DisabledCollisionsContext(sim, [], [], disable_visualization=False):
while key_q not in keys:
keys = p.getKeyboardEvents()
if key_k in keys and keys[key_k] & p.KEY_WAS_TRIGGERED:
ycurrent+=dist
xyz = [xcurrent, ycurrent, zcurrent]
joint_config = sawyer_robot.solve_inverse_kinematics(xyz, orientation)
sawyer_robot.move_to_joint_pos(joint_config)
print_info(joint_config)
if key_u in keys and keys[key_u] & p.KEY_WAS_TRIGGERED:
xcurrent-=dist
xyz = [xcurrent, ycurrent, zcurrent]
joint_config = sawyer_robot.solve_inverse_kinematics(xyz, orientation)
sawyer_robot.move_to_joint_pos(joint_config)
print_info(joint_config)
if key_h in keys and keys[key_h] & p.KEY_WAS_TRIGGERED:
ycurrent-=dist
xyz = [xcurrent, ycurrent, zcurrent]
joint_config = sawyer_robot.solve_inverse_kinematics(xyz, orientation)
sawyer_robot.move_to_joint_pos(joint_config)
print_info(joint_config)
if key_j in keys and keys[key_j] & p.KEY_WAS_TRIGGERED:
xcurrent+=dist
xyz = [xcurrent, ycurrent, zcurrent]
joint_config = sawyer_robot.solve_inverse_kinematics(xyz, orientation)
sawyer_robot.move_to_joint_pos(joint_config)
print_info(joint_config)
if key_o in keys and keys[key_o] & p.KEY_WAS_TRIGGERED:
zcurrent+=dist
xyz = [xcurrent, ycurrent, zcurrent]
joint_config = sawyer_robot.solve_inverse_kinematics(xyz, orientation)
sawyer_robot.move_to_joint_pos(joint_config)
print_info(joint_config)
if key_l in keys and keys[key_l] & p.KEY_WAS_TRIGGERED:
zcurrent-=dist
xyz = [xcurrent, ycurrent, zcurrent]
joint_config = sawyer_robot.solve_inverse_kinematics(xyz, orientation)
sawyer_robot.move_to_joint_pos(joint_config)
print_info(joint_config)
if key_d in keys and keys[key_d] & p.KEY_WAS_TRIGGERED:
set_distance()
if key_q in keys and keys[key_q] & p.KEY_WAS_TRIGGERED:
break
if __name__ == "__main__":
main()