4 from rospkg
import RosPack
5 import xml.etree.ElementTree
as ET
12 @author: Philipp Schillinger 17 Provides a list of all known behavior manifests. 28 Parses all ROS packages to update the internal behavior library. 31 for pkg
in self._rp.list():
32 for export
in self._rp._load_manifest(pkg).exports:
33 if export.tag ==
"flexbe_behaviors":
39 Recursively add all behavior manifests in the given folder to the internal library. 40 If a package name is specified, only manifests referring to this package are added. 43 @param path: Path of the folder to be traversed. 46 @param pkg: Optional name of a package to only add manifests referring to this package. 48 for entry
in os.listdir(path):
49 entry_path = os.path.join(path, entry)
50 if os.path.isdir(entry_path):
52 elif entry.endswith(
".xml")
and not entry.startswith(
"#"):
53 m = ET.parse(entry_path).getroot()
55 if m.tag !=
"behavior" \
56 or len(m.findall(
".//executable")) == 0 \
57 or m.find(
"executable").get(
"package_path")
is None \
58 or len(m.find(
"executable").get(
"package_path").split(
".")) != 2:
60 e = m.find(
"executable")
61 if pkg
is not None and e.get(
"package_path").split(
".")[0] != pkg:
63 be_id = zlib.adler32(e.get(
"package_path"))
65 "name": m.get(
"name"),
66 "package": e.get(
"package_path").split(
".")[0],
67 "file": e.get(
"package_path").split(
".")[1],
68 "class": e.get(
"class")
74 Provides the library entry corresponding to the given ID. 77 @param be_id: Behavior ID to look up. 79 @return Corresponding library entry or None if not found. 84 rospy.logwarn(
"Did not find ID %d in libary, updating..." % be_id)
86 return self._behavior_lib.get(be_id,
None)
91 Searches for a behavior with the given name and returns it along with its ID. 94 @param be_name: Behavior ID to look up. 96 @return Tuple (be_id, be_entry) corresponding to the name or (None, None) if not found. 98 find =
lambda: next((id, be)
for (id, be)
in self._behavior_lib.items()
if be[
"name"] == be_name)
101 except StopIteration:
102 rospy.logwarn(
"Did not find behavior '%s' in libary, updating..." % be_name)
109 Counts the available behaviors. 111 @return Number of behaviors.
def find_behavior(self, be_name)
def get_behavior(self, be_id)
def count_behaviors(self)
def _add_behavior_manifests(self, path, pkg=None)