Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
* Better error handling
* Move common typedef's to common.h
* Return Python tuples from C functions instead of lists or custom Python object
* Bugfix: pass Capsule objects for QoS profiles when creating an action client
  • Loading branch information
jacobperron committed Jan 25, 2019
1 parent 9c53704 commit 7ce5e74
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 81 deletions.
28 changes: 14 additions & 14 deletions rclpy/rclpy/action_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import time
import threading
import time
import uuid

from action_msgs.msg import GoalStatus
Expand All @@ -26,7 +26,7 @@
from rclpy.qos import qos_profile_action_status_default
from rclpy.qos import qos_profile_default, qos_profile_services_default
from rclpy.task import Future
from rclpy.waitable import Waitable
from rclpy.waitable import NumberOfEntities, Waitable

from unique_identifier_msgs.msg import UUID

Expand Down Expand Up @@ -109,11 +109,11 @@ def __init__(
node.handle,
action_type,
action_name,
goal_service_qos_profile,
result_service_qos_profile,
cancel_service_qos_profile,
feedback_sub_qos_profile,
status_sub_qos_profile
goal_service_qos_profile.get_c_qos_profile(),
result_service_qos_profile.get_c_qos_profile(),
cancel_service_qos_profile.get_c_qos_profile(),
feedback_sub_qos_profile.get_c_qos_profile(),
status_sub_qos_profile.get_c_qos_profile()
)

self._is_ready = False
Expand Down Expand Up @@ -258,7 +258,13 @@ async def execute(self, taken_data):

def get_num_entities(self):
"""Return number of each type of entity used in the wait set."""
return _rclpy_action.rclpy_action_wait_set_get_num_entities(self.client_handle)
num_entities = _rclpy_action.rclpy_action_wait_set_get_num_entities(self.client_handle)
return NumberOfEntities(
num_entities[0],
num_entities[1],
num_entities[2],
num_entities[3],
num_entities[4])

def add_to_wait_set(self, wait_set):
"""Add entities to wait set."""
Expand Down Expand Up @@ -287,19 +293,15 @@ def unblock(future):
nonlocal event
event.set()

print("sending goal {} with args {}".format(goal, kwargs))
send_goal_future = self.send_goal_async(goal, kwargs)
send_goal_future.add_done_callback(unblock)

print('waiting for goal reponse...')
event.wait()
print('goal reponse received')
if send_goal_future.exception() is not None:
raise send_goal_future.exception()

goal_handle = send_goal_future.result()

print('waiting for get result')
result = self.get_result(goal_handle)

return result
Expand All @@ -322,7 +324,6 @@ def send_goal_async(self, goal, feedback_callback=None, goal_uuid=None):
has been accepted or rejected.
:rtype: :class:`rclpy.task.Future` instance
"""
print("sending goal")
goal.action_goal_id = self._generate_random_uuid() if goal_uuid is None else goal_uuid
sequence_number = _rclpy_action.rclpy_action_send_goal_request(self.client_handle, goal)
if sequence_number in self._pending_goal_requests:
Expand All @@ -338,7 +339,6 @@ def send_goal_async(self, goal, feedback_callback=None, goal_uuid=None):
self._pending_goal_requests[sequence_number] = future
self._sequence_number_to_goal_id[sequence_number] = goal.action_goal_id
future.add_done_callback(self._remove_pending_goal_request)
print("goal sent")

return future

Expand Down
5 changes: 0 additions & 5 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ static void catch_function(int signo)
}
}

typedef void * create_ros_message_signature (void);
typedef void destroy_ros_message_signature (void *);
typedef bool convert_from_py_signature (PyObject *, void *);
typedef PyObject * convert_to_py_signature (void *);

void
_rclpy_context_capsule_destructor(PyObject * capsule)
{
Expand Down
Loading

0 comments on commit 7ce5e74

Please sign in to comment.