@@ -249,9 +249,230 @@ def test_get_maximum_payloads(self):
249249 self .assertEqual (max_payloads [0 ]["tree_id" ], selected_subtrees [0 ]["tree_id" ], "Tree ID should match the selected subtree's tree ID" )
250250
251251 print ("✅ Get maximum payloads assertion passed" )
252+
253+
254+ def test_get_normalized_torques (self ):
255+ standard_config = self .robot_handler .get_zero_configuration ()
256+ # get torques for standard configuration
257+ torques = self .robot_handler .compute_inverse_dynamics (standard_config , self .robot_handler .get_zero_velocity (), self .robot_handler .get_zero_acceleration ())
258+
259+ normalized_torques = self .robot_handler .get_normalized_torques (torques )
260+
261+ self .assertIsNotNone (normalized_torques , "Normalized torques should not be None" )
262+ self .assertIsInstance (normalized_torques , np .ndarray , "Normalized torques should be a numpy array" )
263+ self .assertEqual (len (normalized_torques ), len (torques ), "Normalized torques length should match the torques length" )
264+ self .assertTrue (all (0 <= nt <= 1.0 for nt in normalized_torques ), "All normalized torques should be between 0 and 1" )
265+
266+ self .robot_handler .set_joint_tree_selection (tree_id = 5 , joint_id = 25 )
267+ valid_configurations = self .robot_handler .get_valid_workspace (range = 1 , resolution = 0.3 , masses = None , checked_frames = None )
268+
269+ max_torques = self .robot_handler .get_maximum_torques (valid_configurations )
270+ normalized_torques_with_max = self .robot_handler .get_normalized_torques (torques , target_torque = max_torques , tree_id = 5 )
271+
272+ self .assertIsNotNone (normalized_torques_with_max , "Normalized torques with max should not be None" )
273+ self .assertIsInstance (normalized_torques_with_max , np .ndarray , "Normalized torques with max should be a numpy array" )
274+ self .assertEqual (len (normalized_torques_with_max ), len (torques ), "Normalized torques with max length should match the torques length" )
275+
276+ print ("✅ Get normalized torques assertion passed" )
277+
278+ def test_get_normalized_payload (self ):
279+ norm_payload = self .robot_handler .get_normalized_payload (payload = 5 ,target_payload = 10 )
280+
281+ self .assertIsNotNone (norm_payload , "Normalized payload should not be None" )
282+ self .assertIsInstance (norm_payload , float , "Normalized payload should be a float" )
283+ self .assertGreaterEqual (norm_payload , 0.0 , "Normalized payload should be non-negative" )
284+ self .assertEqual (norm_payload , 0.5 , "Normalized payload should be 0.5 for payload 5 and target payload 10" )
285+
286+ print ("✅ Get normalized payload assertion passed" )
287+
288+ def test_get_unified_configurations_torque (self ):
289+ self .robot_handler .set_joint_tree_selection (tree_id = 5 , joint_id = 25 )
290+ valid_configurations = self .robot_handler .get_valid_workspace (range = 1 , resolution = 0.3 , masses = None , checked_frames = None )
291+ valid_configurations = self .robot_handler .compute_maximum_payloads (valid_configurations )
292+
293+ unified_configs = self .robot_handler .get_unified_configurations_torque (valid_configurations )
294+
295+ self .assertIsNotNone (unified_configs , "Unified configurations should not be None" )
296+ self .assertIsInstance (unified_configs , np .ndarray , "Unified configurations should be a numpy array" )
297+ self .assertIn ("norm_tau" , unified_configs [0 ], "Each unified configuration should have a normalized_torque key" )
298+ self .assertEqual (len (unified_configs ), len (valid_configurations ), "Unified configurations length should match the valid configurations length" )
299+
300+ print ("✅ Get unified configurations torque assertion passed" )
301+
302+ def test_check_zero (self ):
303+ zero_config = np .zeros (self .robot_handler .model .nv )
304+ non_zero_config = zero_config + 1
305+
306+ self .assertTrue (self .robot_handler .check_zero (zero_config ), "Zero configuration should be identified as zero" )
307+ self .assertFalse (self .robot_handler .check_zero (non_zero_config ), "Non-zero configuration should not be identified as zero" )
308+
309+ print ("✅ Check zero assertion passed" )
310+
311+ def test_get_zero_config_vel_acc (self ):
312+ zero_config = self .robot_handler .get_zero_configuration ()
313+ zero_velocity = self .robot_handler .get_zero_velocity ()
314+ zero_acceleration = self .robot_handler .get_zero_acceleration ()
315+
316+ self .assertIsNotNone (zero_config , "Zero configuration should not be None" )
317+ self .assertIsNotNone (zero_velocity , "Zero velocity should not be None" )
318+ self .assertIsNotNone (zero_acceleration , "Zero acceleration should not be None" )
319+
320+ self .assertIsInstance (zero_config , np .ndarray , "Zero configuration should be a numpy array" )
321+ self .assertIsInstance (zero_velocity , np .ndarray , "Zero velocity should be a numpy array" )
322+ self .assertIsInstance (zero_acceleration , np .ndarray , "Zero acceleration should be a numpy array" )
323+
324+ self .assertTrue (all (v == 0.0 for v in zero_config ), "All elements in zero configuration should be zero" )
325+ self .assertTrue (all (v == 0.0 for v in zero_velocity ), "All elements in zero velocity should be zero" )
326+ self .assertTrue (all (v == 0.0 for v in zero_acceleration ), "All elements in zero acceleration should be zero" )
327+
328+ print ("✅ Get zero configuration, velocity, and acceleration assertion passed" )
329+
330+ def test_get_analyzed_points (self ):
331+ analyzed_points = self .robot_handler .get_analyzed_points ()
332+
333+ self .assertIsInstance (analyzed_points , np .ndarray , "Analyzed points should be a numpy array" )
334+ self .assertEqual (len (analyzed_points ), 0 , "Analyzed points length should be zero initially" )
335+
336+ self .robot_handler .set_joint_tree_selection (tree_id = 5 , joint_id = 25 )
337+ valid_configurations = self .robot_handler .get_valid_workspace (range = 1 , resolution = 0.3 , masses = None , checked_frames = None )
338+
339+ analyzed_points = self .robot_handler .get_analyzed_points ()
340+
341+ self .assertGreater (len (analyzed_points ), 0 , "Analyzed points length should be greater than zero after computing valid workspace" )
342+
343+ print ("✅ Get analyzed points assertion passed" )
344+
345+ def test_get_random_configuration (self ):
346+ q , qdot = self .robot_handler .get_random_configuration ()
252347
348+ self .assertIsNotNone (q , "Random configuration should not be None" )
349+ self .assertIsInstance (q , np .ndarray , "Random configuration should be a numpy array" )
350+ self .assertIsNotNone (qdot , "Random velocity should not be None" )
351+ self .assertIsInstance (qdot , np .ndarray , "Random velocity should be a numpy array" )
253352
353+ print ("✅ Get random configuration assertion passed" )
354+
355+ def test_check_joint_limits (self ):
356+ within_limits_config = self .robot_handler .get_zero_configuration ()
357+ out_of_limits_config = within_limits_config + 100 # Assuming this will exceed joint limits
358+
359+ self .assertIsInstance (self .robot_handler .check_joint_limits (within_limits_config ), np .ndarray , "Return value should be a numpy array of booleans" )
360+ self .assertTrue (np .all (self .robot_handler .check_joint_limits (within_limits_config )), "Configuration within limits should return True" )
361+ self .assertFalse (np .all (self .robot_handler .check_joint_limits (out_of_limits_config )), "Configuration out of limits should return False" )
362+
363+ print ("✅ Check joint limits assertion passed" )
364+
365+ def test_check_effort_limits (self ):
366+ low_tau = self .robot_handler .compute_inverse_dynamics (self .robot_handler .get_zero_configuration (), self .robot_handler .get_zero_velocity (), self .robot_handler .get_zero_acceleration ())
367+ high_tau = low_tau + 100
254368
255369
370+ self .assertIsInstance (self .robot_handler .check_effort_limits (low_tau ,tree_id = 5 ), np .ndarray , "Return value should be a numpy array of booleans" )
371+ self .assertTrue (np .all (self .robot_handler .check_effort_limits (low_tau ,tree_id = 5 )), "Torques within limits should return True" )
372+ self .assertFalse (np .all (self .robot_handler .check_effort_limits (high_tau ,tree_id = 5 )), "Torques out of limits should return False" )
373+
374+ print ("✅ Check effort limits assertion passed" )
375+
376+ def test_get_position_for_joint_states (self ):
377+ q = self .robot_handler .get_zero_configuration ()
378+
379+ position = self .robot_handler .get_position_for_joint_states (q )
380+
381+ self .assertIsNotNone (position , "Position should not be None" )
382+ self .assertIsInstance (position , np .ndarray , "Position should be a numpy array" )
383+
384+ print ("✅ Get position for joint states assertion passed" )
385+
386+ def test_get_joints_placements (self ):
387+ q = self .robot_handler .get_zero_configuration ()
388+
389+ joint_placement , offset = self .robot_handler .get_joints_placements (q = q )
390+
391+ self .assertIsNotNone (joint_placement , "Joint placement should not be None" )
392+ self .assertIsInstance (joint_placement , np .ndarray , "Joint placement should be a numpy array" )
393+ self .assertIsNotNone (offset , "Offset should not be None" )
394+ self .assertIsInstance (offset , float , "Offset should be a float" )
395+
396+ def test_get_joint_placement (self ):
397+ q = self .robot_handler .get_zero_configuration ()
398+
399+ joint_placement = self .robot_handler .get_joint_placement (joint_id = 20 ,q = q )
400+
401+ self .assertIsNotNone (joint_placement , "Joint placement should not be None" )
402+ self .assertIsInstance (joint_placement , dict , "Joint placement should be a dictionary" )
403+ self .assertIn ("x" , joint_placement , "Joint placement should have an 'x' key" )
404+ self .assertIn ("y" , joint_placement , "Joint placement should have a 'y' key" )
405+ self .assertIn ("z" , joint_placement , "Joint placement should have a 'z' key" )
406+
407+ print ("✅ Get joint placement assertion passed" )
408+
409+ def test_get_joint_name (self ):
410+ joint_name = self .robot_handler .get_joint_name (joint_id = 25 )
411+
412+ self .assertIsNotNone (joint_name , "Joint name should not be None" )
413+ self .assertIsInstance (joint_name , str , "Joint name should be a string" )
414+ self .assertEqual (joint_name , "arm_right_7_joint" , "Joint name should match the expected value" )
415+
416+ print ("✅ Get joint name assertion passed" )
417+
418+ def test_get_mass_matrix (self ):
419+ q = self .robot_handler .get_zero_configuration ()
420+
421+ mass_matrix = self .robot_handler .get_mass_matrix (q = q )
422+
423+ self .assertIsNotNone (mass_matrix , "Mass matrix should not be None" )
424+ self .assertIsInstance (mass_matrix , np .ndarray , "Mass matrix should be a numpy array" )
425+ self .assertEqual (mass_matrix .shape , (self .robot_handler .model .nv , self .robot_handler .model .nv ), "Mass matrix shape should be (nv, nv)" )
426+
427+ print ("✅ Get mass matrix assertion passed" )
428+
429+ def test_get_joints (self ):
430+ joints = self .robot_handler .get_joints ()
431+
432+ self .assertIsNotNone (joints , "Joints should not be None" )
433+ self .assertIsInstance (joints , np .ndarray , "Joints should be a list" )
434+ self .assertGreater (len (joints ), 0 , "Joints list should not be empty" )
435+ self .assertIn ("arm_right_1_joint" , joints , "Joints list should contain 'arm_right_1_joint'" )
436+
437+ print ("✅ Get joints assertion passed" )
438+
439+ def test_get_frames (self ):
440+ frames = self .robot_handler .get_frames ()
441+
442+ self .assertIsNotNone (frames , "Frames should not be None" )
443+ self .assertIsInstance (frames , np .ndarray , "Frames should be a list" )
444+ self .assertGreater (len (frames ), 0 , "Frames list should not be empty" )
445+ self .assertIn ("arm_right_1_link" , frames , "Frames list should contain 'arm_right_1_link'" )
446+
447+ print ("✅ Get frames assertion passed" )
448+
449+ def test_get_links (self ):
450+ self .robot_handler .set_joint_tree_selection (tree_id = 5 , joint_id = 25 )
451+ links = self .robot_handler .get_links (all_frames = True )
452+
453+ self .assertIsNotNone (links , "Links should not be None" )
454+ self .assertIsInstance (links , np .ndarray , "Links should be a list" )
455+ self .assertGreater (len (links ), 0 , "Links list should not be empty" )
456+ self .assertIn ("arm_right_1_link" , links , "Links list should contain 'arm_right_1_link'" )
457+
458+ only_tip_links = self .robot_handler .get_links (all_frames = False )
459+
460+ self .assertIsNotNone (only_tip_links , "Links should not be None" )
461+ self .assertIsInstance (only_tip_links , np .ndarray , "Links should be a list" )
462+ self .assertGreater (len (only_tip_links ), 0 , "Links list should not be empty" )
463+ self .assertLess (len (only_tip_links ), len (links ), "Tip links list should be smaller than all links list" )
464+ self .assertIn ("arm_right_7_link" , only_tip_links , "Tip links list should contain 'arm_right_7_link'" )
465+
466+ print ("✅ Get links assertion passed" )
467+
468+ def test_get_parent_joint_id (self ):
469+ parent_id = self .robot_handler .get_parent_joint_id (frame_name = "arm_right_7_link" )
470+
471+ self .assertIsNotNone (parent_id , "Parent joint ID should not be None" )
472+ self .assertIsInstance (parent_id , int , "Parent joint ID should be an integer" )
473+ self .assertEqual (parent_id , 24 , "Parent joint ID should match the expected value" )
474+
475+ print ("✅ Get parent joint ID assertion passed" )
476+
256477if __name__ == "__main__" :
257478 unittest .main ()
0 commit comments