python_move_group_ns.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 # This test is used to ensure planning with a MoveGroupInterface is
38 # possbile if the robot's move_group node is in a different namespace
39 
40 import unittest
41 import numpy as np
42 import rospy
43 import rostest
44 import os
45 
46 from moveit_ros_planning_interface._moveit_move_group_interface import (
47  MoveGroupInterface,
48 )
49 from moveit_msgs.msg import MoveItErrorCodes
50 
51 
52 class PythonMoveGroupNsTest(unittest.TestCase):
53  PLANNING_GROUP = "manipulator"
54  PLANNING_NS = "test_ns/"
55 
56  @classmethod
57  def setUpClass(self):
58  self.group = MoveGroupInterface(
59  self.PLANNING_GROUP,
60  "%srobot_description" % self.PLANNING_NS,
61  self.PLANNING_NS,
62  )
63 
64  @classmethod
65  def tearDown(self):
66  pass
67 
68  def check_target_setting(self, expect, *args):
69  if len(args) == 0:
70  args = [expect]
71  self.group.set_joint_value_target(*args)
72  res = self.group.get_joint_value_target()
73  self.assertTrue(
74  np.all(np.asarray(res) == np.asarray(expect)),
75  "Setting failed for %s, values: %s" % (type(args[0]), res),
76  )
77 
79  n = self.group.get_variable_count()
80  self.check_target_setting([0.1] * n)
81  self.check_target_setting((0.2,) * n)
82  self.check_target_setting(np.zeros(n))
84  [0.3] * n, {name: 0.3 for name in self.group.get_active_joints()}
85  )
86  self.check_target_setting([0.5] + [0.3] * (n - 1), "joint_1", 0.5)
87 
88  def plan(self, target):
89  self.group.set_joint_value_target(target)
90  return self.group.plan()
91 
92  def test_validation(self):
93  current = np.asarray(self.group.get_current_joint_values())
94 
95  error_code1, plan1, time = self.plan(current + 0.2)
96  error_code2, plan2, time = self.plan(current + 0.2)
97 
98  # both plans should have succeeded:
99  error_code = MoveItErrorCodes()
100  error_code.deserialize(error_code1)
101  self.assertEqual(error_code.val, MoveItErrorCodes.SUCCESS)
102  error_code = MoveItErrorCodes()
103  error_code.deserialize(error_code2)
104  self.assertEqual(error_code.val, MoveItErrorCodes.SUCCESS)
105 
106  # first plan should execute
107  self.assertTrue(self.group.execute(plan1))
108 
109  # second plan should be invalid now (due to modified start point) and rejected
110  self.assertFalse(self.group.execute(plan2))
111 
112  # newly planned trajectory should execute again
113  error_code3, plan3, time = self.plan(current)
114  self.assertTrue(self.group.execute(plan3))
115  error_code = MoveItErrorCodes()
116  error_code.deserialize(error_code3)
117  self.assertEqual(error_code.val, MoveItErrorCodes.SUCCESS)
118 
119 
120 if __name__ == "__main__":
121  PKGNAME = "moveit_ros_planning_interface"
122  NODENAME = "moveit_test_python_move_group"
123  rospy.init_node(NODENAME)
124  rostest.rosrun(PKGNAME, NODENAME, PythonMoveGroupNsTest)
python_move_group_ns.PythonMoveGroupNsTest.check_target_setting
def check_target_setting(self, expect, *args)
Definition: python_move_group_ns.py:68
python_move_group_ns.PythonMoveGroupNsTest.tearDown
def tearDown(self)
Definition: python_move_group_ns.py:65
python_move_group_ns.PythonMoveGroupNsTest.PLANNING_NS
string PLANNING_NS
Definition: python_move_group_ns.py:54
python_move_group_ns.PythonMoveGroupNsTest.setUpClass
def setUpClass(self)
Definition: python_move_group_ns.py:57
python_move_group_ns.PythonMoveGroupNsTest.plan
def plan(self, target)
Definition: python_move_group_ns.py:88
python_move_group_ns.PythonMoveGroupNsTest.test_target_setting
def test_target_setting(self)
Definition: python_move_group_ns.py:78
python_move_group_ns.PythonMoveGroupNsTest.test_validation
def test_validation(self)
Definition: python_move_group_ns.py:92
python_move_group_ns.PythonMoveGroupNsTest
Definition: python_move_group_ns.py:52
python_move_group_ns.PythonMoveGroupNsTest.PLANNING_GROUP
string PLANNING_GROUP
Definition: python_move_group_ns.py:53
python_move_group_ns.PythonMoveGroupNsTest.group
group
Definition: python_move_group_ns.py:58


planning_interface
Author(s): Ioan Sucan
autogenerated on Thu Nov 21 2024 03:25:12