Esempio n. 1
0
    def from_file(cls, robot, file_name, *args):
        """Extract sub gait data of the given yaml.

        :param robot:
            The robot corresponding to the given subgait file
        :param file_name:
            The .yaml file name of the subgait

        :returns
            A populated Subgait object
        """
        if file_name is None or not os.path.isfile(file_name):
            raise FileNotFoundError(file_path=file_name)
        try:
            gait_name = file_name.split("/")[-3]
            subgait_name = file_name.split("/")[-2]
            version = file_name.split("/")[-1].replace(SUBGAIT_SUFFIX, "")

            with open(file_name, "r") as yaml_file:
                subgait_dict = yaml.load(yaml_file, Loader=yaml.SafeLoader)

        except Exception as e:  # noqa: PIE786
            rospy.logerr("Error occurred in subgait: {te}, {er} ".format(
                te=type(e), er=e))
            return None

        return cls.from_dict(robot, subgait_dict, gait_name, subgait_name,
                             version, *args)
Esempio n. 2
0
    def __init__(self, package, directory):
        self.loaded_gaits = None
        self.gait_directory = None
        self.joint_names = list()
        self.robot = None

        package_path = self.get_ros_package_path(package)
        self.default_yaml = os.path.join(package_path, directory,
                                         'default.yaml')

        if not os.path.isfile(self.default_yaml):
            raise FileNotFoundError(file_path=self.default_yaml)

        with open(self.default_yaml, 'r') as default_yaml_file:
            default_config = yaml.load(default_yaml_file,
                                       Loader=yaml.SafeLoader)

        self.gait_directory = os.path.join(package_path, directory)
        self._gait_version_map = default_config['gaits']

        self.robot = urdf.Robot.from_parameter_server('/robot_description')
        self.joint_names = [
            joint.name for joint in self.robot.joints if joint.type != 'fixed'
        ]

        rospy.loginfo(
            'GaitSelection initialized with package: {pk} of directory {dr}'.
            format(pk=package, dr=directory))
        rospy.logdebug(
            'GaitSelection initialized with gait_version_map: {vm}'.format(
                vm=str(self.gait_version_map)))

        self.load_gaits()
Esempio n. 3
0
    def validate_gait_in_directory(self, gait_name):
        """Check if the .gait file exists in the given directory."""
        gait_map = gait_name
        gait_path = os.path.join(self.gait_directory, gait_map,
                                 gait_name + '.gait')

        if not os.path.isfile(gait_path):
            raise FileNotFoundError(gait_path)
Esempio n. 4
0
    def __init__(self, package, directory):
        package_path = self.get_ros_package_path(package)
        self._gait_directory = os.path.join(package_path, directory)
        self._default_yaml = os.path.join(self._gait_directory, 'default.yaml')

        if not os.path.isfile(self._default_yaml):
            raise FileNotFoundError(file_path=self._default_yaml)

        self._robot = urdf.Robot.from_parameter_server('/robot_description')
        self._balance_gait = BalanceGait.create_balance_subgait()

        self._gait_version_map = self._load_version_map()
        self._loaded_gaits = self._load_gaits()
Esempio n. 5
0
    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)
Esempio n. 6
0
    def from_file(cls, gait_name, gait_directory, robot, gait_version_map):
        """Extract the data from the .gait file.

        :param gait_name:
            name of the gait to unpack
        :param gait_directory:
            path of the directory where the .gait file is located
        :param robot:
            the robot corresponding to the given .gait file
        :param gait_version_map:
            The parsed yaml file which states the version of the subgaits
        """
        gait_folder = gait_name
        gait_path = os.path.join(gait_directory, gait_folder, gait_name + ".gait")
        if not os.path.isfile(gait_path):
            raise FileNotFoundError(gait_path)

        with open(gait_path, "r") as gait_file:
            gait_dictionary = yaml.load(gait_file, Loader=yaml.SafeLoader)

        return cls.from_dict(robot, gait_dictionary, gait_directory, gait_version_map)