99from pyhpp .manipulation import Device , Graph , Problem , urdf , StatesPathFinder
1010
1111from pyhpp .manipulation import (
12- RandomShortcut as ManipRandomShortcut ,
1312 GraphRandomShortcut ,
1413 GraphPartialShortcut ,
1514)
2221from pyhpp .constraints import (
2322 LockedJoint ,
2423)
25- from pinocchio import SE3 , Quaternion
24+ from pinocchio import SE3
2625
2726parser = ArgumentParser ()
28- parser .add_argument ('-N' , default = 0 , type = int )
29- parser .add_argument (' --display' , action = ' store_true' )
30- parser .add_argument (' --run' , action = ' store_true' )
27+ parser .add_argument ("-N" , default = 0 , type = int )
28+ parser .add_argument (" --display" , action = " store_true" )
29+ parser .add_argument (" --run" , action = " store_true" )
3130args = parser .parse_args ()
3231
3332# Robot and object file paths
7069 box_pose ,
7170 )
7271 robot .setJointBounds (
73- boxes [i ] + '/root_joint' ,
74- [- 1 , 0.5 , - 1 , 2 , 0.6 , 1.9 , - 1 , 1 , - 1 , 1 , - 1 , 1 , - 1 , 1 ]
72+ boxes [i ] + "/root_joint" , [- 1 , 0.5 , - 1 , 2 , 0.6 , 1.9 , - 1 , 1 , - 1 , 1 , - 1 , 1 , - 1 , 1 ]
7573 )
7674
7775model = robot .model ()
8886# Calculate box positions
8987rankB = list ()
9088for i in range (K ):
91- joint_id = robot .model ().getJointId (boxes [i ] + ' /root_joint' )
92- rankB .append (robot .model ().idx_qs [joint_id ])
89+ joint_id = robot .model ().getJointId (boxes [i ] + " /root_joint" )
90+ rankB .append (robot .model ().idx_qs [joint_id ])
9391
94- bb = [0.7 , 0.8 , 0. , 0.1 ]
92+ bb = [0.7 , 0.8 , 0.0 , 0.1 ]
9593c = sqrt (2 ) / 2
9694xstep = (bb [1 ] - bb [0 ]) / (nBoxPerLine - 1 ) if nBoxPerLine > 1 else (bb [1 ] - bb [0 ])
97- nbCols = int (K * 1. / nBoxPerLine + 0.5 )
95+ nbCols = int (K * 1.0 / nBoxPerLine + 0.5 )
9896ystep = (bb [3 ] - bb [2 ]) / (nbCols - 1 ) if nbCols > 1 else (bb [3 ] - bb [2 ])
9997for i in range (K ):
10098 iL = i % nBoxPerLine
10199 iC = (i - iL ) / nBoxPerLine
102100 x = bb [0 ] + xstep * iL
103101 y = bb [2 ] + xstep * iC
104- q_init [rankB [i ]: rankB [i ]+ 7 ] = [x , y , 0.746 , 0 , - c , 0 , c ]
102+ q_init [rankB [i ] : rankB [i ] + 7 ] = [x , y , 0.746 , 0 , - c , 0 , c ]
105103
106104q_goal = q_init [::].copy ()
107105for i in range (K ):
108106 r = rankB [i ]
109107 rn = rankB [goal [i ]]
110- q_goal [r : r + 7 ] = q_init [rn : rn + 7 ]
108+ q_goal [r : r + 7 ] = q_init [rn : rn + 7 ]
111109
112110constraints = dict ()
113111graphConstraints = dict ()
114112
115113jointNames = dict ()
116- jointNames [' all' ] = robot .model ().names
117- jointNames [' baxterRightSide' ] = list ()
118- jointNames [' baxterLeftSide' ] = list ()
114+ jointNames [" all" ] = robot .model ().names
115+ jointNames [" baxterRightSide" ] = list ()
116+ jointNames [" baxterLeftSide" ] = list ()
119117
120- for n in jointNames [' all' ]:
118+ for n in jointNames [" all" ]:
121119 if n .startswith ("baxter" ):
122120 if n .startswith ("baxter/left_" ):
123- jointNames [' baxterLeftSide' ].append (n )
121+ jointNames [" baxterLeftSide" ].append (n )
124122 if n .startswith ("baxter/right_" ):
125- jointNames [' baxterRightSide' ].append (n )
123+ jointNames [" baxterRightSide" ].append (n )
126124# Lock finger joints
127- lockFingers = ["r_gripper_l_finger" ,
128- "r_gripper_r_finger" ,
129- "l_gripper_l_finger" ,
130- "l_gripper_r_finger" ,
131- ]
125+ lockFingers = [
126+ "r_gripper_l_finger" ,
127+ "r_gripper_r_finger" ,
128+ "l_gripper_l_finger" ,
129+ "l_gripper_r_finger" ,
130+ ]
132131for side in ["r" , "l" ]:
133132 joint_name = "baxter/" + side + "_gripper_r_finger_joint"
134133 cs = LockedJoint (robot , joint_name , np .array ([- 0.02 ]))
141140
142141
143142# Lock head
144- lockHead = ' head_pan'
145- joint_name = ' baxter/head_pan'
143+ lockHead = " head_pan"
144+ joint_name = " baxter/head_pan"
146145joint_id = robot .model ().getJointId (joint_name )
147146cs = LockedJoint (robot , joint_name , np .array ([q_init [robot .model ().idx_qs [joint_id ]]]))
148147constraints [lockHead ] = cs
149148graphConstraints [lockHead ] = cs
150149for n in jointNames ["baxterRightSide" ]:
151- cs = LockedJoint (robot , n , np .array ([0. ]))
150+ cs = LockedJoint (robot , n , np .array ([0.0 ]))
152151 constraints [n ] = cs
153152
154153for n in jointNames ["baxterLeftSide" ]:
155- cs = LockedJoint (robot , n , np .array ([0. ]))
154+ cs = LockedJoint (robot , n , np .array ([0.0 ]))
156155 constraints [n ] = cs
157156
158157# Define handles and contact surfaces
168167
169168factory = ConstraintGraphFactory (cg , constraints )
170169factory .setGrippers (grippers )
171- factory .environmentContacts ([' table/pancake_table_table_top' ])
170+ factory .environmentContacts ([" table/pancake_table_table_top" ])
172171factory .setObjects (boxes , handlesPerObject , objContactSurfaces )
173172factory .setRules (rules )
174173factory .generate ()
175- cg .addNumericalConstraintsToGraph ( list (graphConstraints .values ()))
174+ cg .addNumericalConstraintsToGraph (list (graphConstraints .values ()))
176175cg .initialize ()
177176
178- res , q_init_proj , err = cg .applyStateConstraints (cg .getState (' free' ), q_init )
177+ res , q_init_proj , err = cg .applyStateConstraints (cg .getState (" free" ), q_init )
179178if not res :
180- raise Exception (' Init configuration could not be projected.' )
179+ raise Exception (" Init configuration could not be projected." )
181180
182- res , q_goal_proj , err = cg .applyStateConstraints (cg .getState (' free' ), q_goal )
181+ res , q_goal_proj , err = cg .applyStateConstraints (cg .getState (" free" ), q_goal )
183182if not res :
184- raise Exception (' Goal configuration could not be projected.' )
183+ raise Exception (" Goal configuration could not be projected." )
185184
186185problem .initConfig (q_init_proj )
187186
200199problem .addConfigValidation ("CollisionValidation" )
201200
202201optimizers = {
203- ' GraphPartialShortcut' : GraphPartialShortcut (problem ),
204- ' GraphRandomShortcut' : GraphRandomShortcut (problem ),
205- ' PartialShortcut' : PartialShortcut (problem ),
206- ' RandomShortcut' : RandomShortcut (problem ),
207- ' SimpleShortcut' : SimpleShortcut (problem ),
202+ " GraphPartialShortcut" : GraphPartialShortcut (problem ),
203+ " GraphRandomShortcut" : GraphRandomShortcut (problem ),
204+ " PartialShortcut" : PartialShortcut (problem ),
205+ " RandomShortcut" : RandomShortcut (problem ),
206+ " SimpleShortcut" : SimpleShortcut (problem ),
208207}
209- optimizerNames = ['GraphPartialShortcut' , 'GraphRandomShortcut' , 'PartialShortcut' ,
210- 'RandomShortcut' , 'SimpleShortcut' ]
208+ optimizerNames = [
209+ "GraphPartialShortcut" ,
210+ "GraphRandomShortcut" ,
211+ "PartialShortcut" ,
212+ "RandomShortcut" ,
213+ "SimpleShortcut" ,
214+ ]
211215iOpt = 0
212216
213217totalTime = dt .timedelta (0 )
219223 iOpt += 1
220224 if iOpt == len (optimizerNames ):
221225 iOpt = 0
222-
226+
223227 try :
224228 planner .roadmap ().clear ()
225229 problem .resetGoalConfigs ()
245249 print (f"Success rate: { success / args .N * 100 } %" )
246250 if success > 0 :
247251 print (f"Average time per success: { totalTime .total_seconds () / success } " )
248- print (f"Average number nodes per success: { totalNumberNodes / success } " )
252+ print (f"Average number nodes per success: { totalNumberNodes / success } " )
0 commit comments