Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Every coroutine returns `Task<T>` 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

Expand Down
88 changes: 88 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# API Reference

## CoContext

| Method | Returns | Description |
|---|---|---|
| `create_task(task)` | `Task<T>` | Start a coroutine |
| `subscribe<MsgT>(topic, qos)` | `shared_ptr<TopicStream<MsgT>>` | Subscribe to a topic |
| `create_timer(period)` | `shared_ptr<TimerStream>` | Create a periodic timer stream |
| `create_service<SrvT>(name, cb)` | `shared_ptr<Service<SrvT>>` | Create a coroutine service server |
| `create_action_server<ActT>(name, cb)` | `shared_ptr<Server<ActT>>` | Create a coroutine action server |
| `wait_for_service(client, timeout)` | *awaitable* `Result<void>` | Wait for a service |
| `send_request<SrvT>(client, req)` | *awaitable* `Response` | Call a service |
| `wait_for_action(client, timeout)` | *awaitable* `Result<void>` | Wait for an action server |
| `send_goal<ActT>(client, goal)` | *awaitable* `Result<shared_ptr<GoalStream>>` | Send an action goal |
| `sleep(duration)` | *awaitable* `void` | Async sleep |
| `poll_until(pred, interval, timeout)` | `Task<Result<void>>` | Poll until predicate is true or timeout |
| `wait_for(awaitable, timeout)` | `Task<Result<T>>` | 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<ActT>(ctx, name, cb)` | `shared_ptr<Server<ActT>>` | Single-goal action server with preemption |
| `when_all(awaitables...)` | *awaitable* `tuple<Ts...>` | Await all tasks/awaitables concurrently |
| `when_any(awaitables...)` | *awaitable* `variant<Ts...>` | 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<T>` (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<T>` | 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<T>` | 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<TransformStamped>` | Sync lookup of latest transform |
| `lookup_transform(target, source, time)` | *awaitable* `TransformStamped` | Async lookup; suspends until available |
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ nav:
- Home: index.md
- Getting Started: getting-started.md
- Guide: guide.md
- API Reference: api-reference.md

theme:
name: material
Expand Down