-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
143 additions
and
8 deletions.
There are no files selected for viewing
42 changes: 41 additions & 1 deletion
42
examples/minimal_action_server/src/minimal_action_server.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,51 @@ | ||
use std::env; | ||
use std::sync::Arc; | ||
use std::thread; | ||
|
||
use anyhow::{Error, Result}; | ||
|
||
type Fibonacci = example_interfaces::action::Fibonacci; | ||
type GoalHandleFibonacci = rclrs::ServerGoalHandle<Fibonacci>; | ||
|
||
fn handle_goal( | ||
_uuid: &rclrs::GoalUUID, | ||
goal: Arc<example_interfaces::action::rmw::Fibonacci_Goal>, | ||
) -> rclrs::GoalResponse { | ||
println!("Received goal request with order {}", goal.order); | ||
if goal.order > 9000 { | ||
rclrs::GoalResponse::Reject | ||
} else { | ||
rclrs::GoalResponse::AcceptAndExecute | ||
} | ||
} | ||
|
||
fn handle_cancel(_goal_handle: Arc<GoalHandleFibonacci>) -> rclrs::CancelResponse { | ||
println!("Got request to cancel goal"); | ||
rclrs::CancelResponse::Accept | ||
} | ||
|
||
fn execute(goal_handle: Arc<GoalHandleFibonacci>) { | ||
println!("Executing goal"); | ||
thread::sleep(std::time::Duration::from_millis(100)); | ||
} | ||
|
||
fn handle_accepted(goal_handle: Arc<GoalHandleFibonacci>) { | ||
thread::spawn(move || { | ||
execute(goal_handle); | ||
}); | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
let context = rclrs::Context::new(env::args())?; | ||
|
||
let node = rclrs::create_node(&context, "minimal_action_server")?; | ||
let mut node = rclrs::create_node(&context, "minimal_action_server")?; | ||
|
||
let _action_server = node.create_action_server::<example_interfaces::action::Fibonacci>( | ||
"fibonacci", | ||
handle_goal, | ||
handle_cancel, | ||
handle_accepted, | ||
); | ||
|
||
rclrs::spin(&node).map_err(|err| err.into()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
#include <rcl/graph.h> | ||
#include <rcl/rcl.h> | ||
#include <rcl_action/types.h> | ||
#include <rcl_action/goal_handle.h> | ||
#include <rcl_yaml_param_parser/parser.h> | ||
#include <rcutils/error_handling.h> | ||
#include <rmw/types.h> | ||
#include <rosidl_typesupport_introspection_c/field_types.h> | ||
#include <rosidl_typesupport_introspection_c/message_introspection.h> | ||
|
||
const size_t rmw_gid_storage_size_constant = RMW_GID_STORAGE_SIZE; | ||
const size_t rcl_action_uuid_size_constant = UUID_SIZE; |