test_moveit.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2015, University of Tokyo and
7 # TORK (Tokyo Opensource Robotics Kyokai Association) All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of University of Tokyo and
20 # Tokyo Opensource Robotics Kyokai Association. nor the
21 # names of its contributors may be used to endorse or promote products
22 # derived from this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 # POSSIBILITY OF SUCH DAMAGE.
36 #
37 # Author: Isaac I.Y. Saito
38 
39 ## workaround until https://github.com/ros-planning/moveit/pull/581 is released
40 import sys
41 sys.modules["pyassimp"] = sys
42 import pyassimp
43 
44 import unittest
45 
46 from geometry_msgs.msg import Pose, PoseStamped, Point, Quaternion
47 from tf.transformations import quaternion_from_euler
48 from moveit_commander import MoveGroupCommander, MoveItCommanderException, RobotCommander
49 from moveit_msgs.msg import RobotTrajectory, PlanningScene, PlanningSceneComponents
50 from moveit_msgs.srv import GetPlanningScene
51 import rospy
52 
53 import actionlib
54 from moveit_msgs.msg import MoveGroupAction
55 
56 class TestMoveit(unittest.TestCase):
57  _MOVEGROUP_MAIN = 'manipulator'
58  _KINEMATICSOLVER_SAFE = 'RRTConnectkConfigDefault'
59 
60  @classmethod
61  def setUpClass(self):
62  rospy.init_node('test_moveit_vs060')
63  # wait for /move_group/goal
64  client = actionlib.SimpleActionClient('move_group', MoveGroupAction)
65  rospy.loginfo('wait for move_group')
66  client.wait_for_server();
67  rospy.loginfo('wait for move_group done')
68  self.robot = RobotCommander()
69  self._mvgroup = MoveGroupCommander(self._MOVEGROUP_MAIN)
70  # Temporary workaround of planner's issue similar to https://github.com/tork-a/rtmros_nextage/issues/170
71  self._mvgroup.set_planner_id(self._KINEMATICSOLVER_SAFE)
72 
73  self._movegroups = sorted(['manipulator', 'manipulator_flange'])
74  self._joints_movegroup_main = sorted(['j1', 'j2', 'j3', 'j4', 'j5', 'flange'])
75 
76  @classmethod
77  def tearDownClass(self):
78  True # TODO impl something meaningful
79 
80  def _set_sample_pose(self):
81  '''
82  @return: Pose() with some values populated in.
83  '''
84  pose_target = Pose()
85  pose_target.orientation.x = 0.00
86  pose_target.orientation.y = 0.00
87  pose_target.orientation.z = -0.20
88  pose_target.orientation.w = 0.98
89  pose_target.position.x = 0.18
90  pose_target.position.y = 0.18
91  pose_target.position.z = 0.94
92  return pose_target
93 
94  def _plan(self):
95  '''
96  Run `clear_pose_targets` at the beginning.
97  @rtype: RobotTrajectory http://docs.ros.org/api/moveit_msgs/html/msg/RobotTrajectory.html
98  '''
99  self._mvgroup.clear_pose_targets()
100 
101  pose_target = self._set_sample_pose()
102  self._mvgroup.set_pose_target(pose_target)
103  plan = self._mvgroup.plan()
104  rospy.loginfo(' plan: '.format(plan))
105  return plan
106 
108  '''Check if the defined move groups are loaded.'''
109  self.assertEqual(self._movegroups, sorted(self.robot.get_group_names()))
110 
112  '''Check if the defined joints in a move group are loaded.'''
113  self.assertEqual(self._joints_movegroup_main, sorted(self._mvgroup.get_active_joints()))
114 
115  def test_plan(self):
116  '''Evaluate plan (RobotTrajectory)'''
117  plan = self._plan()
118  # TODO Better way to check the plan is valid.
119  # Currently the following checks if the number of waypoints is not zero,
120  # which (hopefully) indicates that a path is computed.
121  self.assertNotEqual(0, plan.joint_trajectory.points)
122 
124  '''
125  Evaluate Plan and Execute works.
126  Currently no value checking is done (, which is better to be implemented)
127  '''
128  for i in range(3):
129  self._plan()
130  # TODO Better way to check the plan is valid.
131  # The following checks if plan execution was successful or not.
132  ret = self._mvgroup.go()
133  if ret:
134  break
135  rospy.sleep(3)
136  self.assertTrue(ret)
137 
139  '''
140  Check for simple planning, originally testd in moved from denso_vs060_moveit_demo_test.py
141  '''
142  self._plan()
143  p = [ 0.1, -0.35, 0.4]
144  pose = PoseStamped(header = rospy.Header(stamp = rospy.Time.now(), frame_id = '/BASE'),
145  pose = Pose(position = Point(*p),
146  orientation = Quaternion(*quaternion_from_euler(1.57, 0, 1.57, 'sxyz'))))
147  for i in range(3):
148  self._mvgroup.set_pose_target(pose)
149  ret = self._mvgroup.go()
150  if ret:
151  break
152  rospy.sleep(3)
153  self.assertTrue(ret)
154 
156  '''
157  Check if publish_simple_scene.py is working
158  '''
159  rospy.wait_for_service('/get_planning_scene', timeout=20);
160  get_planning_scene = rospy.ServiceProxy("/get_planning_scene", GetPlanningScene)
161  collision_objects = []
162  # wait for 10 sec
163  time_start = rospy.Time.now()
164  while not collision_objects and (rospy.Time.now() - time_start).to_sec() < 10.0:
165  world = get_planning_scene(PlanningSceneComponents(components=PlanningSceneComponents.WORLD_OBJECT_NAMES)).scene.world
166  collision_objects = world.collision_objects
167  rospy.loginfo("collision_objects = " + str(world.collision_objects))
168  rospy.sleep(1)
169  self.assertTrue(world.collision_objects != [], world)
170 
171 if __name__ == '__main__':
172  import rostest
173  rostest.rosrun('vs060', 'test_moveit_vs060', TestMoveit)
def test_list_activejoints(self)
Definition: test_moveit.py:111
def test_set_pose_target(self)
Definition: test_moveit.py:138
def test_planandexecute(self)
Definition: test_moveit.py:123
def test_list_movegroups(self)
Definition: test_moveit.py:107
def _set_sample_pose(self)
Definition: test_moveit.py:80
def test_planning_scene(self)
Definition: test_moveit.py:155


denso_launch
Author(s): Ryohei Ueda
autogenerated on Mon Jun 10 2019 13:13:34