def __init__(self, view, robot): self.view = view # Default values self.gait_directory = None self.playback_speed = 100 self.time_slider_thread = None self.current_time = 0 self.robot = robot empty_subgait_file = os.path.join( rospkg.RosPack().get_path('march_rqt_gait_generator'), 'resource/empty_gait/empty_subgait/empty_subgait.subgait') self.subgait = ModifiableSubgait.from_file(robot, empty_subgait_file, self) self.settings_changed_history = RingBuffer(capacity=100, dtype=list) self.settings_changed_redo_list = RingBuffer(capacity=100, dtype=list) standing = Subgait.from_file(robot, empty_subgait_file) previous_subgait_controller = SideSubgaitController( view=self.view.side_subgait_view['previous'], default=standing) next_subgait_controller = SideSubgaitController( view=self.view.side_subgait_view['next'], default=standing) self.side_subgait_controller = { 'previous': previous_subgait_controller, 'next': next_subgait_controller } self.connect_buttons() self.view.load_gait_into_ui(self.subgait) for joint in self.subgait.joints: self.connect_plot(joint)
def load_interpolatable_subgaits(self, subgait_name='left_close', base_version='MV_walk_leftclose_v1', other_version='MV_walk_leftclose_v2'): base_subgait_path = '{rsc}/{gait}/{subgait}/{version}.subgait'.format( rsc=self.resources_folder, gait=self.gait_name, subgait=subgait_name, version=base_version) base_subgait = Subgait.from_file(self.robot, base_subgait_path) other_subgait_path = '{rsc}/{gait}/{subgait}/{version}.subgait'.format( rsc=self.resources_folder, gait=self.gait_name, subgait=subgait_name, version=other_version) other_subgait = Subgait.from_file(self.robot, other_subgait_path) return base_subgait, other_subgait
def test_invalid_subgait_transition_unequal_joints(self): other_subgait_name = 'right_close' other_version = 'MV_walk_rightclose_v2_seven_joints' other_subgait_path = '{rsc}/{gait}/{subgait}/{version}.subgait'.format( rsc=self.resources_folder, gait=self.gait_name, subgait=other_subgait_name, version=other_version) other_subgait = Subgait.from_file(self.robot, other_subgait_path) with self.assertRaises(NonValidGaitContent): other_subgait.validate_subgait_transition(self.subgait)
def test_invalid_subgait_transition(self): other_subgait_name = 'right_close' other_version = 'MV_walk_rightclose_v2' other_subgait_path = '{rsc}/{gait}/{subgait}/{version}.subgait'.format( rsc=self.resources_folder, gait=self.gait_name, subgait=other_subgait_name, version=other_version) other_subgait = Subgait.from_file(self.robot, other_subgait_path) self.assertFalse( other_subgait.validate_subgait_transition(self.subgait))
def load_interpolatable_subgaits_ik( self, subgait_name="swing", base_version="forward_swing", other_version="backward_swing", ): base_subgait_path = "{rsc}/{gait}/{subgait}/{version}.subgait".format( rsc=self.resources_folder, gait=self.gait_name_ik, subgait=subgait_name, version=base_version, ) base_subgait = Subgait.from_file(self.robot, base_subgait_path) other_subgait_path = "{rsc}/{gait}/{subgait}/{version}.subgait".format( rsc=self.resources_folder, gait=self.gait_name_ik, subgait=subgait_name, version=other_version, ) other_subgait = Subgait.from_file(self.robot, other_subgait_path) return base_subgait, other_subgait
def load_interpolatable_subgaits( self, subgait_name="left_close", base_version="MV_walk_leftclose_v1", other_version="MV_walk_leftclose_v2", ): base_subgait_path = "{rsc}/{gait}/{subgait}/{version}.subgait".format( rsc=self.resources_folder, gait=self.gait_name, subgait=subgait_name, version=base_version, ) base_subgait = Subgait.from_file(self.robot, base_subgait_path) other_subgait_path = "{rsc}/{gait}/{subgait}/{version}.subgait".format( rsc=self.resources_folder, gait=self.gait_name, subgait=subgait_name, version=other_version, ) other_subgait = Subgait.from_file(self.robot, other_subgait_path) return base_subgait, other_subgait
def test_valid_subgait_transition(self): other_subgait_name = "right_close" other_version = "MV_walk_rightclose_v2" other_subgait_path = "{rsc}/{gait}/{subgait}/{version}.subgait".format( rsc=self.resources_folder, gait=self.gait_name, subgait=other_subgait_name, version=other_version, ) other_subgait = Subgait.from_file(self.robot, other_subgait_path) self.assertTrue( self.subgait.validate_subgait_transition(other_subgait))
def setUp(self): self.gait_name = 'walk' self.subgait_name = 'left_swing' self.version = 'MV_walk_leftswing_v2' self.resources_folder = rospkg.RosPack().get_path( 'march_shared_classes') + '/test/resources' self.robot = urdf.Robot.from_xml_file( rospkg.RosPack().get_path('march_description') + '/urdf/march4.urdf') self.subgait_path = '{rsc}/{gait}/{subgait}/{version}.subgait'.format( rsc=self.resources_folder, gait=self.gait_name, subgait=self.subgait_name, version=self.version) self.subgait = Subgait.from_file(self.robot, self.subgait_path)
def load_subgait(robot, gait_directory, gait_name, subgait_name, gait_version_map): """Read the .subgait file and extract the data. :returns if gait and subgait names are valid return populated Gait object """ if not gait_version_map.get(gait_name): raise GaitNameNotFound(gait_name) if not gait_version_map[gait_name].get(subgait_name): raise SubgaitNameNotFound(subgait_name) version = gait_version_map[gait_name][subgait_name] subgait_path = os.path.join(gait_directory, gait_name, subgait_name, version + '.subgait') if not os.path.isfile(subgait_path): raise FileNotFoundError(file_path=subgait_path) return Subgait.from_file(robot, subgait_path)
def setUp(self): self.gait_name = "walk" self.gait_name_ik = "ik_test" self.subgait_name = "left_swing" self.base_subgait_name = "swing" self.other_subgait_name = "swing" self.version = "MV_walk_leftswing_v2" self.base_version = "forward_swing" self.other_version = "backward_swing" self.resources_folder = ( rospkg.RosPack().get_path("march_shared_classes") + "/test/resources") self.robot = urdf.Robot.from_xml_file( rospkg.RosPack().get_path("march_description") + "/urdf/march4.urdf") self.subgait_path = "{rsc}/{gait}/{subgait}/{version}.subgait".format( rsc=self.resources_folder, gait=self.gait_name, subgait=self.subgait_name, version=self.version, ) self.subgait = Subgait.from_file(self.robot, self.subgait_path)
def test_from_file_no_robot(self): self.assertIsNone(Subgait.from_file(None, self.subgait_path))
def test_from_file_none_path(self): with self.assertRaises(FileNotFoundError): Subgait.from_file(self.robot, None)
def test_from_file_invalid_path(self): with self.assertRaises(FileNotFoundError): Subgait.from_file( self.robot, self.resources_folder + '/MV_walk_leftswing_v2.subgait')