Skip to content

Commit adc33f7

Browse files
Fix service calls
1 parent 0283961 commit adc33f7

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

formant_ros2_adapter/scripts/components/formant_control/formant_control.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def _handle_teleop(self, msg):
6868
def _handle_command(self, msg):
6969
self._logger.info("Command received %s" % str(msg))
7070
formant_stream = msg.command
71+
72+
# To do: this shouldn't always happen
7173
service_call_result = self._service_coordinator.call_service(
7274
formant_stream, msg.text
7375
)
@@ -85,6 +87,8 @@ def _handle_command(self, msg):
8587
timestamp=msg_timestamp,
8688
),
8789
)
90+
91+
# To do: this shouldn't always happen
8892
self._publisher_coodinator.generic_publisher.publish_command(
8993
formant_stream, msg.text
9094
)

formant_ros2_adapter/scripts/components/publisher/generic_publisher.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,23 @@ def __init__(
8484

8585
def publish_command(self, formant_stream, msg: str):
8686
with self._config_lock:
87-
for publisher in self._publishers[formant_stream]:
88-
ros2_msg_type = publisher.msg_type.__name__
89-
if ros2_msg_type == "String":
90-
ros2_msg = String()
91-
ros2_msg.data = msg
92-
publisher.publish(ros2_msg)
93-
elif (ros2_msg_type in ROS2_NUMERIC_TYPES) and msg.isnumeric():
94-
self._publish_ros2_numeric(publisher, ros2_msg_type, msg)
95-
else:
96-
self._logger.warn(
97-
"Unsupported ROS2 message type for command: %s" % formant_stream
98-
)
99-
continue
87+
# To do: is this the right place to check for this?
88+
if formant_stream in self._publishers:
89+
for publisher in self._publishers[formant_stream]:
90+
ros2_msg_type = publisher.msg_type.__name__
91+
if ros2_msg_type == "String":
92+
ros2_msg = String()
93+
ros2_msg.data = msg
94+
publisher.publish(ros2_msg)
95+
elif (ros2_msg_type in ROS2_NUMERIC_TYPES) and msg.isnumeric():
96+
self._publish_ros2_numeric(publisher, ros2_msg_type, msg)
97+
else:
98+
self._logger.warn(
99+
"Unsupported ROS2 message type for command: %s" % formant_stream
100+
)
101+
continue
102+
else:
103+
self._logger.info(f"No publisher for formant stream {formant_stream}, skipping")
100104

101105
def publish(self, formant_stream, msg):
102106
for publisher in self._publishers[formant_stream]:

formant_ros2_adapter/scripts/components/services/prepare_service_request.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def prepare_serivce_request(service_client: Client, parameter: str) -> SrvTypeRe
6262
request_value,
6363
)
6464

65+
return service_request
66+
6567

6668
def get_bool_value(parameter):
6769
if parameter == "":

formant_ros2_adapter/scripts/components/services/service_coordinator.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,19 @@ def _setup_services_for_config(self, service_config: ServiceClientConfig):
5959
service_name = service_config.service
6060
formant_stream = service_config.formant_stream
6161

62-
service_type = service_config.service_type
63-
if service_type is None:
64-
service_type = self._topic_type_provider.get_service_type_for_name(
62+
service_type_string = service_config.service_type
63+
if service_type_string is None:
64+
service_type_string = self._topic_type_provider.get_service_type_for_name(
6565
service_name
6666
)
67-
if service_type is None:
67+
if service_type_string is None:
6868
raise ValueError("No Service type found for %s" % service_name)
6969

70+
service_type = get_ros2_type_from_string(service_type_string)
71+
7072
self._logger.debug(
7173
"Setting up service %s, %s, %s"
72-
% (service_name, formant_stream, service_type)
74+
% (service_name, formant_stream, service_type_string)
7375
)
7476
try:
7577
new_service_client = self._node.create_client(
@@ -82,8 +84,13 @@ def _setup_services_for_config(self, service_config: ServiceClientConfig):
8284
self._service_clients[formant_stream] = []
8385

8486
self._service_clients[formant_stream].append(new_service_client)
87+
88+
self._logger.debug("Set up service: %s" %service_name)
8589
except Exception as e:
86-
self._logger.warn("Failed to set up service client for %s" % service_name)
90+
self._logger.warn(
91+
"Failed to set up service client for %s\n%s"
92+
% (service_name, e)
93+
)
8794

8895
def call_service(self, formant_stream, parameter: str):
8996
with self._config_lock:

0 commit comments

Comments
 (0)