diff --git a/README.md b/README.md index a53b85c..fc8d361 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ Every coroutine returns `Task` and is launched with `ctx.create_task(...)`. T - [Getting Started](https://otamachan.github.io/rclcpp_async/getting-started/) -- prerequisites, installation, walkthrough - [Guide](https://otamachan.github.io/rclcpp_async/guide/) -- topics, services, actions, concurrency, cancellation, TF +- [API Reference](https://otamachan.github.io/rclcpp_async/api-reference/) -- full list of public types and methods ## Benchmarks diff --git a/docs/api-reference.md b/docs/api-reference.md new file mode 100644 index 0000000..ec1049c --- /dev/null +++ b/docs/api-reference.md @@ -0,0 +1,88 @@ +# API Reference + +## CoContext + +| Method | Returns | Description | +|---|---|---| +| `create_task(task)` | `Task` | Start a coroutine | +| `subscribe(topic, qos)` | `shared_ptr>` | Subscribe to a topic | +| `create_timer(period)` | `shared_ptr` | Create a periodic timer stream | +| `create_service(name, cb)` | `shared_ptr>` | Create a coroutine service server | +| `create_action_server(name, cb)` | `shared_ptr>` | Create a coroutine action server | +| `wait_for_service(client, timeout)` | *awaitable* `Result` | Wait for a service | +| `send_request(client, req)` | *awaitable* `Response` | Call a service | +| `wait_for_action(client, timeout)` | *awaitable* `Result` | Wait for an action server | +| `send_goal(client, goal)` | *awaitable* `Result>` | Send an action goal | +| `sleep(duration)` | *awaitable* `void` | Async sleep | +| `poll_until(pred, interval, timeout)` | `Task>` | Poll until predicate is true or timeout | +| `wait_for(awaitable, timeout)` | `Task>` | Race an awaitable against a timeout | +| `post(fn)` | `void` | Post a callback to the executor thread (thread-safe) | +| `node()` | `Node&` | Access the underlying node | + +## Free Functions + +| Function | Returns | Description | +|---|---|---| +| `create_single_goal_action_server(ctx, name, cb)` | `shared_ptr>` | Single-goal action server with preemption | +| `when_all(awaitables...)` | *awaitable* `tuple` | Await all tasks/awaitables concurrently | +| `when_any(awaitables...)` | *awaitable* `variant` | Race tasks/awaitables, return first result | +| `shield(task)` | *awaitable* `T` | Protect a task from parent cancellation | + +## Task + +| Method | Returns | Description | +|---|---|---| +| `operator bool()` | `bool` | `true` if the task holds a valid coroutine (not moved-from) | +| `done()` | `bool` | `true` if the coroutine has completed (`false` for null tasks) | +| `result()` | `T&` | Get the result of a completed `Task` (rethrows if exception) | +| `cancel()` | `void` | Request cancellation via `CancelledException` | + +## Result + +| Method | Returns | Description | +|---|---|---| +| `ok()` | `bool` | `true` if the operation succeeded | +| `timeout()` | `bool` | `true` if the operation timed out | +| `value` | `std::optional` | The result value (present when `ok()` is `true`) | + +## GoalContext + +| Method | Returns | Description | +|---|---|---| +| `goal()` | `const Goal&` | Access the goal request | +| `is_canceling()` | `bool` | Check if cancellation was requested | +| `publish_feedback(fb)` | `void` | Send feedback to the client | +| `abort()` | `void` | Abort the goal | + +## Event + +| Method | Returns | Description | +|---|---|---| +| `set()` | `void` | Signal the event, resuming all waiters | +| `clear()` | `void` | Reset the event so future `wait()` calls will suspend | +| `wait()` | *awaitable* `void` | Suspends until the event is set | +| `is_set()` | `bool` | Check the current state | + +## Mutex + +| Method | Returns | Description | +|---|---|---| +| `lock()` | *awaitable* `void` | Suspends until the lock is acquired | +| `unlock()` | `void` | Release the lock, resuming the next waiter | +| `is_locked()` | `bool` | Check the current state | + +## Channel + +| Method | Returns | Description | +|---|---|---| +| `send(value)` | `void` | Send a value (thread-safe) | +| `close()` | `void` | Signal end of stream | +| `next()` | *awaitable* `optional` | Receive the next value (`nullopt` when closed) | + +## TfBuffer + +| Method | Returns | Description | +|---|---|---| +| `TfBuffer(ctx)` | -- | Construct with a `CoContext`; starts a listener thread | +| `lookup_transform(target, source)` | `optional` | Sync lookup of latest transform | +| `lookup_transform(target, source, time)` | *awaitable* `TransformStamped` | Async lookup; suspends until available | diff --git a/docs/index.md b/docs/index.md index eb125d3..f44d99f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -53,3 +53,4 @@ The standard `rclcpp::spin()` drives execution -- no special executor needed. - **[Getting Started](getting-started.md)** -- prerequisites, installation, and a walkthrough of the Quick Start example - **[Guide](guide.md)** -- topics, services, actions, concurrency primitives, cancellation, and TF lookups +- **[API Reference](api-reference.md)** -- full list of public types and methods diff --git a/mkdocs.yml b/mkdocs.yml index a7b601b..f04a335 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -6,6 +6,7 @@ nav: - Home: index.md - Getting Started: getting-started.md - Guide: guide.md + - API Reference: api-reference.md theme: name: material