Skip to content

Commit fb8e703

Browse files
committed
[WIP] Start defining server/client execute functions
This is just the basic layout. I'm trying to avoid defining the `take_*` functions that rclcpp has to link taking messages to executing on them. I'm not sure if that's actually worthwhile yet. This area should also be revisited once it's functional to see whether portions can be moved into the non-polymorphic subfunctions. Doing so could reduce compile times by avoiding excessive monomorphization.
1 parent f48a590 commit fb8e703

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

rclrs/src/action/client.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ where
139139
num_entities,
140140
})
141141
}
142+
143+
fn execute_feedback(&self) -> Result<(), RclrsError> {
144+
todo!()
145+
}
146+
147+
fn execute_status(&self) -> Result<(), RclrsError> {
148+
todo!()
149+
}
150+
151+
fn execute_goal_response(&self) -> Result<(), RclrsError> {
152+
todo!()
153+
}
154+
155+
fn execute_cancel_response(&self) -> Result<(), RclrsError> {
156+
todo!()
157+
}
158+
159+
fn execute_result_response(&self) -> Result<(), RclrsError> {
160+
todo!()
161+
}
142162
}
143163

144164
impl<T> ActionClientBase for ActionClient<T>
@@ -154,6 +174,12 @@ where
154174
}
155175

156176
fn execute(&self, mode: ReadyMode) -> Result<(), RclrsError> {
157-
todo!()
177+
match mode {
178+
ReadyMode::Feedback => self.execute_feedback(),
179+
ReadyMode::Status => self.execute_status(),
180+
ReadyMode::GoalResponse => self.execute_goal_response(),
181+
ReadyMode::CancelResponse => self.execute_cancel_response(),
182+
ReadyMode::ResultResponse => self.execute_result_response(),
183+
}
158184
}
159185
}

rclrs/src/action/server.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
action::{CancelResponse, GoalResponse, GoalUuid, ServerGoalHandle},
3-
error::ToResult,
3+
error::{RclReturnCode, ToResult},
44
rcl_bindings::*,
55
wait::WaitableNumEntities,
66
Clock, Node, RclrsError, ENTITY_LIFECYCLE_MUTEX,
@@ -158,6 +158,50 @@ where
158158
accepted_callback: Box::new(accepted_callback),
159159
})
160160
}
161+
162+
fn execute_goal_request(&self) -> Result<(), RclrsError> {
163+
// Take pending goal request
164+
let (request_id, request) = {
165+
let mut request_id = rmw_request_id_t {
166+
writer_guid: [0; 16],
167+
sequence_number: 0,
168+
};
169+
type RmwMsg<T> =
170+
<<T as rosidl_runtime_rs::Action>::Goal as rosidl_runtime_rs::Message>::RmwMsg;
171+
let mut request_rmw = RmwMsg::<T>::default();
172+
let handle = &*self.handle.lock();
173+
let take_result = unsafe {
174+
// SAFETY: The three pointers are valid/initialized
175+
rcl_action_take_goal_request(
176+
handle,
177+
&mut request_id,
178+
&mut request_rmw as *mut RmwMsg<T> as *mut _,
179+
)
180+
};
181+
match take_result.try_into().unwrap() {
182+
RclReturnCode::Ok => (),
183+
// Spurious wakeup – this may happen even when a waitset indicated that this
184+
// service was ready, so it shouldn't be an error.
185+
RclReturnCode::ServiceTakeFailed => return Ok(()),
186+
_ => return take_result.ok(),
187+
}
188+
let request = todo!("Convert request_rmw to expected type");
189+
(request_id, request)
190+
};
191+
todo!()
192+
}
193+
194+
fn execute_cancel_request(&self) -> Result<(), RclrsError> {
195+
todo!()
196+
}
197+
198+
fn execute_result_request(&self) -> Result<(), RclrsError> {
199+
todo!()
200+
}
201+
202+
fn execute_goal_expired(&self) -> Result<(), RclrsError> {
203+
todo!()
204+
}
161205
}
162206

163207
impl<T> ActionServerBase for ActionServer<T>
@@ -173,6 +217,11 @@ where
173217
}
174218

175219
fn execute(&self, mode: ReadyMode) -> Result<(), RclrsError> {
176-
todo!()
220+
match mode {
221+
ReadyMode::GoalRequest => self.execute_goal_request(),
222+
ReadyMode::CancelRequest => self.execute_cancel_request(),
223+
ReadyMode::ResultRequest => self.execute_result_request(),
224+
ReadyMode::GoalExpired => self.execute_goal_expired(),
225+
}
177226
}
178227
}

0 commit comments

Comments
 (0)