moveit2
The MoveIt Motion Planning Framework for ROS 2.
python_time_parameterization.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2012, Willow Garage, Inc.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of Willow Garage, Inc. nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 # Author: Masaki Murooka (JSK Robotics Lab, The University of Tokyo)
36 
37 import unittest
38 import numpy as np
39 import rospy
40 import rostest
41 import os
42 
43 from moveit_commander import RobotCommander
44 
45 
46 class PythonTimeParameterizationTest(unittest.TestCase):
47  PLANNING_GROUP = "manipulator"
48 
49  @classmethod
50  def setUpClass(self):
51  self.commandercommander = RobotCommander("robot_description")
52  self.groupgroup = self.commandercommander.get_group(self.PLANNING_GROUPPLANNING_GROUP)
53 
54  @classmethod
55  def tearDown(self):
56  pass
57 
58  def plan(self):
59  start_pose = self.group.get_current_pose().pose
60  goal_pose = self.group.get_current_pose().pose
61  goal_pose.position.z -= 0.1
62  (plan, fraction) = self.group.compute_cartesian_path(
63  [start_pose, goal_pose], 0.005, 0.0
64  )
65  self.assertEqual(fraction, 1.0, "Cartesian path plan failed")
66  return plan
67 
68  def time_parameterization(self, plan, algorithm):
69  ref_state = self.commandercommander.get_current_state()
70  retimed_plan = self.groupgroup.retime_trajectory(
71  ref_state,
72  plan,
73  velocity_scaling_factor=0.1,
74  acceleration_scaling_factor=0.1,
75  algorithm=algorithm,
76  )
77  return retimed_plan
78 
80  plan = self.planplan()
81  retimed_plan = self.time_parameterizationtime_parameterization(
82  plan, "iterative_time_parameterization"
83  )
84  self.assertTrue(
85  len(retimed_plan.joint_trajectory.points) > 0, "Retimed plan is invalid"
86  )
87  retimed_plan = self.time_parameterizationtime_parameterization(
88  plan, "iterative_spline_parameterization"
89  )
90  self.assertTrue(
91  len(retimed_plan.joint_trajectory.points) > 0, "Retimed plan is invalid"
92  )
93  retimed_plan = self.time_parameterizationtime_parameterization(
94  plan, "time_optimal_trajectory_generation"
95  )
96  self.assertTrue(
97  len(retimed_plan.joint_trajectory.points) > 0, "Retimed plan is invalid"
98  )
99  retimed_plan = self.time_parameterizationtime_parameterization(plan, "")
100  self.assertTrue(
101  len(retimed_plan.joint_trajectory.points) == 0, "Invalid retime algorithm"
102  )
103 
104 
105 if __name__ == "__main__":
106  PKGNAME = "moveit_ros_planning_interface"
107  NODENAME = "moveit_test_python_time_parameterization"
108  rospy.init_node(NODENAME)
109  rostest.rosrun(PKGNAME, NODENAME, PythonTimeParameterizationTest)
110 
111  # suppress cleanup segfault
112  os._exit(0)