python_moveit_commander.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: William Baker
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, PlanningSceneInterface
44 
45 
46 class PythonMoveitCommanderTest(unittest.TestCase):
47  PLANNING_GROUP = "manipulator"
48 
49  @classmethod
50  def setUpClass(self):
51  self.commander = RobotCommander("robot_description")
52  self.group = self.commander.get_group(self.PLANNING_GROUP)
53 
54  @classmethod
55  def tearDown(self):
56  pass
57 
58  def check_target_setting(self, expect, *args):
59  if len(args) == 0:
60  args = [expect]
61  self.group.set_joint_value_target(*args)
62  res = self.group.get_joint_value_target()
63  self.assertTrue(np.all(np.asarray(res) == np.asarray(expect)),
64  "Setting failed for %s, values: %s" % (type(args[0]), res))
65 
67  n = self.group.get_variable_count()
68  self.check_target_setting([0.1] * n)
69  self.check_target_setting((0.2,) * n)
70  self.check_target_setting(np.zeros(n))
71  self.check_target_setting([0.3] * n, {name: 0.3 for name in self.group.get_active_joints()})
72  self.check_target_setting([0.5] + [0.3]*(n-1), "joint_1", 0.5)
73 
74  def plan(self, target):
75  self.group.set_joint_value_target(target)
76  return self.group.plan()
77 
78  def test_validation(self):
79  current = np.asarray(self.group.get_current_joint_values())
80 
81  plan1 = self.plan(current + 0.2)
82  plan2 = self.plan(current + 0.2)
83 
84  # first plan should execute
85  self.assertTrue(self.group.execute(plan1))
86 
87  # second plan should be invalid now (due to modified start point) and rejected
88  self.assertFalse(self.group.execute(plan2))
89 
90  # newly planned trajectory should execute again
91  plan3 = self.plan(current)
92  self.assertTrue(self.group.execute(plan3))
93 
95  planning_scene = PlanningSceneInterface()
96 
97 
98 if __name__ == '__main__':
99  PKGNAME = 'moveit_ros_planning_interface'
100  NODENAME = 'moveit_test_python_moveit_commander'
101  rospy.init_node(NODENAME)
102  rostest.rosrun(PKGNAME, NODENAME, PythonMoveitCommanderTest)
103 
104  # suppress cleanup segfault
105  os._exit(0)


moveit_commander
Author(s): Ioan Sucan
autogenerated on Sun Oct 18 2020 13:18:56