Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename client to service_client #117

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/user_ros_essentials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ the following:
from rospy_tutorials.srv import AddTwoInts

rospy.init_node('service_node')
jupyros.client('service_name', AddTwoInts)
jupyros.service_client('service_name', AddTwoInts)

The generated widget will change depending on the message type being passed.

Expand Down
22 changes: 18 additions & 4 deletions jupyros/ros1/ros_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,17 @@ def step_clk(arg):
return vbox


def client(srv_name, srv_type):
def client(*args, **kwargs):
"""
Deprecated client for ROS services.
Use service_client() instead.
"""
from warnings import warn
warn("client() is deprecated. Use service_client() instead.")
return service_client(*args, **kwargs)


def service_client(srv_name, srv_type):
IsabelParedes marked this conversation as resolved.
Show resolved Hide resolved
"""
Create a form widget for message type srv_type.
This function analyzes the fields of srv_type and creates
Expand All @@ -327,7 +337,11 @@ def client(srv_name, srv_type):

@return jupyter widget for display
"""
rospy.wait_for_service(srv_name, timeout=5)
try:
rospy.wait_for_service(srv_name, timeout=5)
except rospy.ROSException:
rospy.logerr(f"Service {srv_name} is unavailable.")
return

widget_list = []
widget_dict = {}
Expand All @@ -343,7 +357,7 @@ def call_srv(arg):
service = rospy.ServiceProxy(srv_name, srv_type)
return service(msg_to_send)
except rospy.ServiceException as e:
print("Service call failed: %s" % e)
rospy.logerr(f"Service call failed: {e}")

call_btn.on_click(call_srv)

Expand Down Expand Up @@ -373,7 +387,7 @@ def action_client(action_name, action_msg, goal_msg, callbacks=None):

# Create actions client and connect to server
a_client = actionlib.SimpleActionClient(action_name, action_msg)
rospy.loginfo(f'[{action_name.upper()}]: Waiting for action server.')
rospy.loginfo(f'[{action_name.upper()}] Waiting for action server.')
server_ok = a_client.wait_for_server(timeout=rospy.Duration(5.0))
if server_ok:
rospy.loginfo(f'[{action_name.upper()}] Connection to server successful.')
Expand Down
2 changes: 1 addition & 1 deletion notebooks/ROS_Services_Clients.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"metadata": {},
"outputs": [],
"source": [
"jupyros.client('add_two_ints', AddTwoInts)"
"jupyros.service_client('add_two_ints', AddTwoInts)"
]
}
],
Expand Down