Skip to content

Commit 0753edc

Browse files
committed
add mdbook
1 parent f8cfde0 commit 0753edc

20 files changed

+2894
-1120
lines changed

.github/workflows/docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ jobs:
3333
with:
3434
github_token: ${{ secrets.GITHUB_TOKEN }}
3535
publish_dir: ./book/book
36+
clean_exclude: pr-preview/
37+
force_orphan: false

.github/workflows/pr-preview.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: PR Preview
2+
on:
3+
pull_request:
4+
types: [opened, reopened, synchronize, closed]
5+
6+
concurrency:
7+
group: preview-${{ github.ref }}
8+
cancel-in-progress: true
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
preview:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup Rust toolchain
21+
if: github.event.action != 'closed'
22+
uses: dtolnay/rust-toolchain@stable
23+
24+
- name: Build project
25+
if: github.event.action != 'closed'
26+
run: cargo build
27+
28+
- name: Setup mdBook
29+
if: github.event.action != 'closed'
30+
uses: peaceiris/actions-mdbook@v1
31+
with:
32+
mdbook-version: '0.4.40'
33+
34+
- name: Install mdbook-admonish
35+
if: github.event.action != 'closed'
36+
run: cargo install mdbook-admonish
37+
38+
- name: Install mdbook-mermaid
39+
if: github.event.action != 'closed'
40+
run: cargo install mdbook-mermaid
41+
42+
- name: Build mdBook
43+
if: github.event.action != 'closed'
44+
run: mdbook build book
45+
46+
- name: Deploy Preview
47+
uses: rossjrw/pr-preview-action@v1
48+
with:
49+
source-dir: ./book/book
50+
preview-branch: gh-pages
51+
umbrella-dir: pr-preview

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ result*
1010

1111
# mdBook build output
1212
/book/book/
13+
/book/*.js
14+
/book/*.css

book/book.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@ edition = "2024"
1212
[build]
1313
build-dir = "book"
1414

15+
[preprocessor.admonish]
16+
command = "mdbook-admonish"
17+
assets_version = "3.1.0" # do not edit: managed by `mdbook-admonish install`
18+
19+
[preprocessor.mermaid]
20+
command = "mdbook-mermaid"
21+
1522
[output.html]
1623
default-theme = "light"
1724
preferred-dark-theme = "navy"
1825
git-repository-url = "https://github.com/ZettaScaleLabs/ros-z"
1926
edit-url-template = "https://github.com/ZettaScaleLabs/ros-z/edit/main/{path}"
27+
additional-css = ["mdbook-admonish.css", "book/mdbook-admonish.css"]
28+
additional-js = ["mermaid.min.js", "mermaid-init.js"]
2029

2130
[output.html.fold]
2231
enable = true

book/src/chapters/actions.md

Lines changed: 134 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,150 @@
11
# Actions
22

3-
Actions provide a mechanism for long-running tasks in ROS 2, with the ability to:
3+
**Actions enable long-running tasks with progress feedback and cancellation support, perfect for operations that take seconds or minutes to complete.** Unlike services that return immediately, actions provide streaming feedback while executing complex workflows.
44

5-
- Send goals to an action server
6-
- Receive feedback during execution
7-
- Cancel goals in progress
8-
- Get final results
5+
```admonish tip
6+
Use actions for robot navigation, trajectory execution, or any operation where you need progress updates and the ability to cancel mid-execution. Use services for quick request-response operations.
7+
```
98

10-
## Overview
9+
## Action Lifecycle
1110

12-
Actions are useful for tasks that:
11+
```mermaid
12+
stateDiagram-v2
13+
[*] --> Idle
14+
Idle --> Accepted: Send Goal
15+
Accepted --> Executing: Start Processing
16+
Executing --> Executing: Send Feedback
17+
Executing --> Succeeded: Complete
18+
Executing --> Canceled: Cancel Request
19+
Executing --> Aborted: Error Occurs
20+
Succeeded --> [*]
21+
Canceled --> [*]
22+
Aborted --> [*]
23+
```
1324

14-
- Take a long time to complete
15-
- Need to provide progress updates
16-
- May need to be cancelled
25+
## Components
1726

18-
Common examples include:
27+
| Component | Type | Purpose |
28+
|-----------|------|---------|
29+
| **Goal** | Input | Defines the desired outcome |
30+
| **Feedback** | Stream | Progress updates during execution |
31+
| **Result** | Output | Final outcome when complete |
32+
| **Status** | State | Current execution state |
1933

20-
- Navigation to a goal
21-
- Gripper control
22-
- Long computations
34+
## Communication Pattern
2335

24-
## Components
36+
```mermaid
37+
sequenceDiagram
38+
participant C as Client
39+
participant S as Server
40+
41+
C->>S: Send Goal
42+
S->>C: Goal Accepted
43+
loop During Execution
44+
S->>C: Feedback Update
45+
end
46+
alt Success
47+
S->>C: Result (Success)
48+
else Canceled
49+
C->>S: Cancel Request
50+
S->>C: Result (Canceled)
51+
else Error
52+
S->>C: Result (Aborted)
53+
end
54+
```
55+
56+
## Use Cases
57+
58+
**Robot Navigation:**
59+
60+
- Goal: Target position and orientation
61+
- Feedback: Current position, distance remaining, obstacles detected
62+
- Result: Final position, success/failure reason
63+
64+
**Gripper Control:**
65+
66+
- Goal: Desired grip force and position
67+
- Feedback: Current force, contact detection
68+
- Result: Grip achieved, object secured
69+
70+
**Long Computations:**
71+
72+
- Goal: Computation parameters
73+
- Feedback: Progress percentage, intermediate results
74+
- Result: Final computed value, execution time
75+
76+
```admonish info
77+
Actions excel when operations take more than a few seconds and users need visibility into progress. For sub-second operations, prefer services for simplicity.
78+
```
79+
80+
## Implementation Status
81+
82+
```admonish note
83+
Action support in ros-z is under active development. The core infrastructure is in place, and examples are available in the repository. Check the latest API documentation for implementation details.
84+
```
85+
86+
## Example Patterns
87+
88+
**Action Server:**
89+
90+
```rust,ignore
91+
let action_server = node
92+
.create_action_server::<Fibonacci>("/fibonacci")
93+
.build()?;
94+
95+
loop {
96+
let goal = action_server.accept_goal()?;
97+
98+
// Send periodic feedback
99+
for i in 0..goal.order {
100+
action_server.send_feedback(FeedbackMsg {
101+
current: i,
102+
sequence: compute_partial(i)
103+
})?;
104+
}
105+
106+
// Send final result
107+
action_server.send_result(ResultMsg {
108+
sequence: compute_final(goal.order)
109+
})?;
110+
}
111+
```
112+
113+
**Action Client:**
114+
115+
```rust,ignore
116+
let action_client = node
117+
.create_action_client::<Fibonacci>("/fibonacci")
118+
.build()?;
119+
120+
let goal_handle = action_client.send_goal(GoalMsg {
121+
order: 10
122+
}).await?;
123+
124+
while let Some(feedback) = goal_handle.feedback().await {
125+
println!("Progress: {}", feedback.current);
126+
}
25127
26-
An action consists of:
128+
let result = goal_handle.get_result().await?;
129+
println!("Final: {:?}", result.sequence);
130+
```
27131

28-
1. **Goal**: The desired outcome
29-
2. **Feedback**: Progress updates during execution
30-
3. **Result**: The final outcome
132+
```admonish warning
133+
Always implement timeout mechanisms for action clients. Long-running actions can fail or hang, and clients need graceful degradation strategies.
134+
```
31135

32-
## Implementation
136+
## Comparison with Other Patterns
33137

34-
Action support in ros-z is under active development. Check the examples directory and API documentation for the latest implementation details.
138+
| Pattern | Duration | Feedback | Cancellation | Use Case |
139+
|---------|----------|----------|--------------|----------|
140+
| **Pub-Sub** | Continuous | No | N/A | Sensor data streaming |
141+
| **Service** | < 1 second | No | No | Quick queries |
142+
| **Action** | Seconds to minutes | Yes | Yes | Long-running tasks |
35143

36-
## Example Use Cases
144+
## Resources
37145

38-
- Robot navigation with progress updates
39-
- Trajectory execution with real-time feedback
40-
- Complex multi-step operations
146+
- **[ROS 2 Actions Documentation](https://docs.ros.org/en/rolling/Tutorials/Intermediate/Writing-an-Action-Server-Client/Py.html)** - Official ROS 2 action guide
147+
- **[ros-z Examples](https://github.com/ZettaScaleLabs/ros-z/tree/main/ros-z/examples)** - Working action implementations
148+
- **[Services](./services.md)** - Simpler request-response pattern
41149

42-
For concrete examples, see the ros-z examples directory.
150+
**Action implementation is evolving. Check the ros-z repository for the latest examples and API updates.**

0 commit comments

Comments
 (0)