robot_state_update.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import unittest
00004 import numpy as np
00005 import rospy
00006 import rostest
00007 import os
00008 
00009 from moveit_ros_planning_interface._moveit_move_group_interface import MoveGroup
00010 
00011 
00012 class RobotStateUpdateTest(unittest.TestCase):
00013     PLANNING_GROUP = "manipulator"
00014 
00015     @classmethod
00016     def setUpClass(self):
00017         self.group = MoveGroup(self.PLANNING_GROUP, "robot_description")
00018 
00019     @classmethod
00020     def tearDown(self):
00021         pass
00022 
00023     def plan(self, target):
00024         self.group.set_joint_value_target(target)
00025         return self.group.compute_plan()
00026 
00027     def test(self):
00028         current = np.asarray(self.group.get_current_joint_values())
00029         for i in range(30):
00030             target = current + np.random.uniform(-0.5, 0.5, size = current.shape)
00031             # if plan was successfully executed, current state should be reported at target
00032             if self.group.execute(self.plan(target)):
00033                  actual = np.asarray(self.group.get_current_joint_values())
00034                  self.assertTrue(np.allclose(target, actual, atol=1e-4, rtol=0.0))
00035             # otherwise current state should be still the same
00036             else:
00037                actual = np.asarray(self.group.get_current_joint_values())
00038                self.assertTrue(np.allclose(current, actual, atol=1e-4, rtol=0.0))
00039 
00040 
00041 if __name__ == '__main__':
00042     PKGNAME = 'moveit_ros_planning_interface'
00043     NODENAME = 'moveit_test_robot_state_update'
00044     rospy.init_node(NODENAME)
00045     rostest.rosrun(PKGNAME, NODENAME, RobotStateUpdateTest)
00046 
00047     # suppress cleanup segfault in ROS < Kinetic
00048     os._exit(0)


planning_interface
Author(s): Ioan Sucan
autogenerated on Wed Jun 19 2019 19:24:53