Skip to content

Commit

Permalink
Maintaining consistency of automatically putting time stamps in the s…
Browse files Browse the repository at this point in the history
…ervice and action calls similiar to publishing in rostopics. (#961)

* Fix issue #945

Signed-off-by: Sukhvansh2004 <[email protected]>

* Fixed code style error

Signed-off-by: Sukhvansh2004 <[email protected]>

* Fixed Indentation

Signed-off-by: Sukhvansh2004 <[email protected]>

* Called the setters for the message fix

Signed-off-by: Sukhvansh2004 <[email protected]>

* Fixed Format Ros2Action

Signed-off-by: Sukhvansh2004 <[email protected]>

* Fixed copyright issue

Signed-off-by: Sukhvansh2004 <[email protected]>

* Revert format to original

Signed-off-by: Sukhvansh2004 <[email protected]>

* Update ros2action/ros2action/verb/send_goal.py

Commited Suggestion

Co-authored-by: Tomoya Fujita <[email protected]>
Signed-off-by: Sukhvansh Jain <[email protected]>

* Minor Fix of print statement

Signed-off-by: Sukhvansh2004 <[email protected]>

---------

Signed-off-by: Sukhvansh2004 <[email protected]>
Signed-off-by: Sukhvansh Jain <[email protected]>
Co-authored-by: Tomoya Fujita <[email protected]>
  • Loading branch information
Sukhvansh2004 and fujitatomoya authored Jan 21, 2025
1 parent d930a74 commit f3fc36c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion ros2action/ros2action/verb/send_goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,20 @@ def send_goal(action_name, action_type, goal_values, feedback_callback):

goal = action_module.Goal()

timestamp_fields = []
try:
set_message_fields(goal, goal_dict)
timestamp_fields = set_message_fields(
goal, goal_dict, expand_header_auto=True, expand_time_now=True)
except Exception as ex:
return 'Failed to populate message fields: {!r}'.format(ex)

print('Waiting for an action server to become available...')
action_client.wait_for_server()

stamp_now = node.get_clock().now().to_msg()
for field_setter in timestamp_fields:
field_setter(stamp_now)

print('Sending goal:\n {}'.format(message_to_yaml(goal)))
goal_future = action_client.send_goal_async(goal, feedback_callback)
rclpy.spin_until_future_complete(node, goal_future)
Expand Down Expand Up @@ -175,6 +181,7 @@ def _sigint_cancel_handler(sig, frame):

print('Result:\n {}'.format(message_to_yaml(result.result)))
print('Goal finished with status: {}'.format(_goal_status_to_string(result.status)))

finally:
if action_client is not None:
action_client.destroy()
Expand Down
7 changes: 6 additions & 1 deletion ros2service/ros2service/verb/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ def requester(service_type, service_name, values, period):

request = srv_module.Request()

timestamp_fields = []
try:
set_message_fields(request, values_dictionary)
timestamp_fields = set_message_fields(
request, values_dictionary, expand_header_auto=True, expand_time_now=True)
except Exception as e:
return 'Failed to populate field: {0}'.format(e)

Expand All @@ -106,6 +108,9 @@ def requester(service_type, service_name, values, period):
cli.wait_for_service()

while True:
stamp_now = node.get_clock().now().to_msg()
for field_setter in timestamp_fields:
field_setter(stamp_now)
print('requester: making request: %r\n' % request)
last_call = time.time()
future = cli.call_async(request)
Expand Down

0 comments on commit f3fc36c

Please sign in to comment.