1
- from reachy2_symbolic_ik .symbolic_ik import SymbolicIK
2
- import numpy as np
3
- from reachy_placo .ik_reachy_placo import IKReachyQP
4
1
import math
5
2
import time
6
- from scipy .spatial .transform import Rotation as R
3
+ from pathlib import Path
4
+ from typing import List
5
+
6
+ import numpy as np
7
7
from grasping_utils .utils import get_homogeneous_matrix_msg_from_euler
8
- from importlib .resources import files
8
+ from reachy_placo .ik_reachy_placo import IKReachyQP
9
+ from scipy .spatial .transform import Rotation as R
10
+
11
+ from reachy2_symbolic_ik .symbolic_ik import SymbolicIK
9
12
from reachy2_symbolic_ik .utils import go_to_position
10
13
11
14
@@ -60,7 +63,7 @@ def time_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP) -> None:
60
63
print ("placo ik : " , end - start )
61
64
62
65
63
- def joints_space_test (symbolic_ik : SymbolicIK , placo_ik : IKReachyQP , verbose = False ) -> None :
66
+ def joints_space_test (symbolic_ik : SymbolicIK , placo_ik : IKReachyQP , verbose : bool = False ) -> None :
64
67
green = "\033 [92m" # GREEN
65
68
blue = "\033 [94m" # BLUE
66
69
yellow = "\033 [93m" # YELLOW
@@ -72,7 +75,7 @@ def joints_space_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, verbose=Fal
72
75
symbolic_success = 0
73
76
symbolic_fail = 0
74
77
# pose_fail = []
75
- goal_pose = [[], [] ]
78
+ goal_pose : List [ List [ float ]] = [ ]
76
79
for k in range (100 ):
77
80
shoulder_pitch = np .random .uniform (- math .pi , math .pi )
78
81
shoulder_roll = np .random .uniform (- math .pi , math .pi )
@@ -96,7 +99,6 @@ def joints_space_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, verbose=Fal
96
99
goal_pose_matrix = placo_ik .robot .get_T_a_b ("torso" , "r_tip_joint" )
97
100
goal_pose [0 ] = goal_pose_matrix [:3 , 3 ]
98
101
goal_pose [1 ] = R .from_matrix (goal_pose_matrix [:3 , :3 ]).as_euler ("xyz" )
99
- # print("goal_pose : ", goal_pose)
100
102
is_reachable , joints_placo , errors = placo_ik .is_pose_reachable (
101
103
goal_pose_matrix ,
102
104
arm_name = "r_arm" ,
@@ -124,49 +126,49 @@ def joints_space_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, verbose=Fal
124
126
print (red + "Symbolic not reachable" + reset_color )
125
127
# print("goal_pose : ", goal_pose)
126
128
# pose_fail.append(np.copy(goal_pose))
127
- if verbose :
128
- time .sleep (0.2 )
129
-
130
- for k in range (100 ):
131
- shoulder_pitch = np .random .uniform (- math .pi , math .pi )
132
- shoulder_roll = np .random .uniform (- math .pi , math .pi )
133
- elbow_yaw = np .random .uniform (- math .pi , math .pi )
134
- elbow_pitch = np .random .uniform (- math .pi , math .pi )
135
- wrist_pitch = np .random .uniform (math .pi / 4 , 2 * math .pi - math .pi / 4 )
136
- wrist_roll = np .random .uniform (math .pi / 4 , 2 * math .pi - math .pi / 4 )
137
- wrist_yaw = np .random .uniform (- math .pi , math .pi )
138
- joints = [shoulder_pitch , shoulder_roll , elbow_yaw , elbow_pitch , wrist_pitch , wrist_roll , wrist_yaw ]
139
- if verbose :
140
- print (blue + str (np .degrees (joints )) + reset_color )
141
- go_to_position (placo_ik , joints , wait = 0.0 )
142
- goal_pose_matrix = placo_ik .robot .get_T_a_b ("torso" , "r_tip_joint" )
143
- goal_pose [0 ] = goal_pose_matrix [:3 , 3 ]
144
- goal_pose [1 ] = R .from_matrix (goal_pose_matrix [:3 , :3 ]).as_euler ("xyz" )
145
- is_reachable , joints_placo , errors = placo_ik .is_pose_reachable (
146
- goal_pose_matrix ,
147
- arm_name = "r_arm" ,
148
- q0 = [0.0 , 0.0 , 0.0 , - math .pi / 2 , 0 , 0.0 , 0.0 ],
149
- tolerances = [0.001 , 0.001 , 0.001 , 0.02 , 0.02 , 0.02 ],
150
- max_iter = 45 ,
151
- nb_stepper_solve = 25 ,
152
- )
153
- if is_reachable :
154
- if verbose :
155
- print (green + "Placo reachable" + reset_color )
156
- placo_fail += 1
157
- else :
158
- if verbose :
159
- print (red + "Placo not reachable" + reset_color )
160
- result = symbolic_ik .is_reachable (goal_pose )
161
- if result [0 ]:
162
- if verbose :
163
- print (green + "Symbolic reachable" + reset_color )
164
- symbolic_fail += 1
165
- else :
166
- if verbose :
167
- print (red + "Symbolic not reachable" + reset_color )
168
- if verbose :
169
- time .sleep (0.2 )
129
+ # if verbose:
130
+ # time.sleep(0.2)
131
+
132
+ # for k in range(100):
133
+ # shoulder_pitch = np.random.uniform(-math.pi, math.pi)
134
+ # shoulder_roll = np.random.uniform(-math.pi, math.pi)
135
+ # elbow_yaw = np.random.uniform(-math.pi, math.pi)
136
+ # elbow_pitch = np.random.uniform(-math.pi, math.pi)
137
+ # wrist_pitch = np.random.uniform(math.pi / 4, 2 * math.pi - math.pi / 4)
138
+ # wrist_roll = np.random.uniform(math.pi / 4, 2 * math.pi - math.pi / 4)
139
+ # wrist_yaw = np.random.uniform(-math.pi, math.pi)
140
+ # joints = [shoulder_pitch, shoulder_roll, elbow_yaw, elbow_pitch, wrist_pitch, wrist_roll, wrist_yaw]
141
+ # if verbose:
142
+ # print(blue + str(np.degrees(joints)) + reset_color)
143
+ # go_to_position(placo_ik, joints, wait=0.0)
144
+ # goal_pose_matrix = placo_ik.robot.get_T_a_b("torso", "r_tip_joint")
145
+ # goal_pose[0] = goal_pose_matrix[:3, 3]
146
+ # goal_pose[1] = R.from_matrix(goal_pose_matrix[:3, :3]).as_euler("xyz")
147
+ # is_reachable, joints_placo, errors = placo_ik.is_pose_reachable(
148
+ # goal_pose_matrix,
149
+ # arm_name="r_arm",
150
+ # q0=[0.0, 0.0, 0.0, -math.pi / 2, 0, 0.0, 0.0],
151
+ # tolerances=[0.001, 0.001, 0.001, 0.02, 0.02, 0.02],
152
+ # max_iter=45,
153
+ # nb_stepper_solve=25,
154
+ # )
155
+ # if is_reachable:
156
+ # if verbose:
157
+ # print(green + "Placo reachable" + reset_color)
158
+ # placo_fail += 1
159
+ # else:
160
+ # if verbose:
161
+ # print(red + "Placo not reachable" + reset_color)
162
+ # result = symbolic_ik.is_reachable(goal_pose)
163
+ # if result[0]:
164
+ # if verbose:
165
+ # print(green + "Symbolic reachable" + reset_color)
166
+ # symbolic_fail += 1
167
+ # else:
168
+ # if verbose:
169
+ # print(red + "Symbolic not reachable" + reset_color)
170
+ # if verbose:
171
+ # time.sleep(0.2)
170
172
print ("JOINTS SPACE TEST" )
171
173
# print("Pose fail : ", pose_fail)
172
174
print ("Placo success : " , placo_success )
@@ -178,12 +180,12 @@ def joints_space_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, verbose=Fal
178
180
def task_space_test (
179
181
symbolic_ik : SymbolicIK ,
180
182
placo_ik : IKReachyQP ,
181
- x_step = 0.15 ,
182
- y_step = 0.15 ,
183
- z_step = 0.15 ,
184
- roll_step = 45 ,
185
- pitch_step = 45 ,
186
- yaw_step = 45 ,
183
+ x_step : float = 0.15 ,
184
+ y_step : float = 0.15 ,
185
+ z_step : float = 0.15 ,
186
+ roll_step : int = 45 ,
187
+ pitch_step : int = 45 ,
188
+ yaw_step : int = 45 ,
187
189
) -> None :
188
190
print ("TASK SPACE TEST" )
189
191
shoulder_position = symbolic_ik .shoulder_position
@@ -204,8 +206,7 @@ def task_space_test(
204
206
for roll in np .arange (0 , 360 , roll_step ):
205
207
for pitch in np .arange (0 , 360 , pitch_step ):
206
208
for yaw in np .arange (0 , 360 , yaw_step ):
207
- goal_orientation = (roll , pitch , yaw )
208
- goal_orientation = np .deg2rad (goal_orientation )
209
+ goal_orientation = [np .radians (roll ), np .radians (pitch ), np .radians (yaw )]
209
210
goal_pose = [goal_position , goal_orientation ]
210
211
goal_poses .append (goal_pose )
211
212
end_time = time .time ()
@@ -225,7 +226,7 @@ def task_space_test(
225
226
226
227
def main_test () -> None :
227
228
symbolib_ik = SymbolicIK ()
228
- urdf_path = files ( " config_files" )
229
+ urdf_path = Path ( "src/ config_files" )
229
230
for file in urdf_path .glob ("**/*.urdf" ):
230
231
if file .stem == "reachy2" :
231
232
urdf_path = file .resolve ()
0 commit comments