9 from pathlib
import Path
10 from collections
import OrderedDict
11 from threading
import Event
12 from threading
import RLock
15 return v.lower()
in (
"yes",
"true",
"t",
"1")
19 setattr(aux, attr_list.pop(), value)
38 if reader.has_option(name,
"method"):
39 self.
method = reader.get(name,
"method")
40 if reader.has_option(name,
"msg_type"):
41 self.
msg_type = reader.get(name,
"msg_type")
42 if reader.has_option(name,
"name"):
43 self.
name = reader.get(name,
"name")
44 if reader.has_option(name,
"dependencies"):
47 if reader.has_option(name,
"args"):
48 args_aux = reader.get(name,
"args")
49 self.
args = [y.split(
'.')
for y
in [x.strip()
for x
in args_aux.split(
',')]]
50 if reader.has_option(name,
"params_name"):
51 aux_name = reader.get(name,
"params_name")
52 if reader.has_option(name,
"params_type"):
53 aux_type = reader.get(name,
"params_type")
54 self.
params_dict = OrderedDict((x.strip(),y.strip())
for x,y
in itertools.izip(aux_name.split(
','),aux_type.split(
',')))
56 self.
params_dict = OrderedDict((x.strip(),
"str")
for x
in aux_name.split(
','))
57 if reader.has_option(name,
"buf"):
58 self.
buf = reader.get(name,
"buf")
59 if reader.has_option(name,
"latch"):
60 self.
latch = reader.get(name,
"latch")
64 if self.
method ==
"service":
66 elif self.
method ==
"topic":
71 param_class = getattr(self.
module, msg_type)
72 param_instance = param_class()
73 converted = param_instance
75 param_attr = k.split(
'.')
76 obj_list = [param_instance]
77 for attr
in param_attr:
78 if hasattr(obj_list[-1], attr):
79 if attr
is not param_attr[-1]:
80 obj_list.append(getattr(obj_list[-1], attr))
82 value = getattr(__builtin__, self.
params_dict[k])(p)
95 reader = ConfigParser.RawConfigParser()
97 if len(args) > 0
and Path(args[0]).is_file():
98 man_path = Path(args[0])
102 if man_path.is_file():
103 reader.read(str(man_path))
108 comm_list = reader.sections()
110 for comm
in comm_list:
112 comm_info.fill_data(comm, reader)
118 CommController.__init__(self)
122 return (action_name
in self.
comm_dict.keys())
125 action_completed =
False 128 converted_params = action.convert_params(params)
129 msg_type = getattr(action.module, action.msg_type)
130 node_namespace = rospy.get_namespace()
131 if action.method ==
"service":
132 rospy.wait_for_service(node_namespace + (action.name[1:]
if action.name.startswith(
'/')
else action.name))
134 service_aux = rospy.ServiceProxy(node_namespace + (action.name[1:]
if action.name.startswith(
'/')
else action.name), msg_type)
135 service_aux(converted_params)
136 except rospy.ServiceException
as e:
137 print(
"service "+ action.name +
" call failed: %s." % e)
138 action_completed =
True 139 elif action.method ==
"topic":
141 topic_pub = rospy.Publisher(
142 node_namespace + (action.name[1:]
if action.name.startswith(
'/')
else action.name),
147 if hasattr(converted_params,
"header"):
148 header = std_msgs.msg.Header()
149 header.stamp = rospy.Time.now()
150 setattr(converted_params,
"header", header)
152 topic_pub.publish(converted_params)
153 action_completed =
True 155 print(
"method " + action.method +
" not available.")
156 action_completed =
False 158 action_completed =
False 160 return action_completed
165 CommController.__init__(self)
174 default_section = reader.defaults()
176 self.
rate = float(default_section[
"rate"])
179 CommController.get_info(self, reader)
185 node_namespace = rospy.get_namespace()
187 node_namespace + (perception.name[1:]
if perception.name.startswith(
'/')
else perception.name),
188 getattr(perception.module, perception.msg_type),
194 perception_param = []
199 obj = getattr(obj, d)
201 perception_param.append(obj)
202 perception_param = map(str, perception_param)
204 perception = jason_msgs.msg.Perception()
205 perception.perception_name = name
206 perception.parameters = perception_param
208 perception.update =
False 210 perception.update =
True
def setattr_recursive(obj_list, attr_list, value)
def get_info(self, reader)
def read_manifest(self, args)
def convert_params(self, params)
def perform_action(self, action_name, params)
def executable_action(self, action_name)
def subscriber_callback(self, msg, name)
def fill_data(self, name, reader)
def get_info(self, reader)
def start_perceiving(self)