Skip to content

Commit 3fbf78c

Browse files
authored
Merge pull request #25 from copper-project/gbin/doc-app-builder-docs
Refresh docs for generated app builder setup
2 parents a06b475 + 1172190 commit 3fbf78c

5 files changed

Lines changed: 28 additions & 42 deletions

File tree

book/src/ch10-main-rs.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ are mostly boilerplate that you write once and rarely touch.
1010
pub mod tasks;
1111

1212
use cu29::prelude::*;
13-
use cu29_helpers::basic_copper_setup;
14-
use std::path::{Path, PathBuf};
13+
use std::path::Path;
1514
use std::thread::sleep;
1615
use std::time::Duration;
1716

@@ -27,24 +26,17 @@ fn main() {
2726
std::fs::create_dir_all(parent).expect("Failed to create logs directory");
2827
}
2928
}
30-
let copper_ctx = basic_copper_setup(
31-
&PathBuf::from(&logger_path),
32-
PREALLOCATED_STORAGE_SIZE,
33-
true,
34-
None,
35-
)
36-
.expect("Failed to setup logger.");
3729
debug!("Logger created at {}.", logger_path);
3830
debug!("Creating application... ");
39-
let mut application = MyProjectApplicationBuilder::new()
40-
.with_context(&copper_ctx)
31+
let mut application = MyProjectApplication::builder()
32+
.with_log_path(logger_path, PREALLOCATED_STORAGE_SIZE)
33+
.expect("Failed to setup logger.")
4134
.build()
4235
.expect("Failed to create application.");
43-
let clock = copper_ctx.clock.clone();
44-
debug!("Running... starting clock: {}.", clock.now());
36+
debug!("Running... starting clock: {}.", application.clock().now());
4537

4638
application.run().expect("Failed to run application.");
47-
debug!("End of program: {}.", clock.now());
39+
debug!("End of program: {}.", application.clock().now());
4840
sleep(Duration::from_secs(1));
4941
}
5042
```
@@ -63,20 +55,21 @@ generated code is injected by the macro.
6355
**`PREALLOCATED_STORAGE_SIZE`** -- How much memory (in bytes) to pre-allocate for the
6456
structured log. 100 MB is a reasonable default.
6557

66-
**`basic_copper_setup()`** -- Initializes the unified logger, the robot clock, and returns
67-
a `copper_ctx` that holds references to both. The parameters are: log file path,
68-
pre-allocated size, whether to also print to console, and an optional custom monitor.
58+
**`MyProjectApplication::builder()`** -- Creates the generated application builder.
59+
You provide the pieces you want to override, such as the clock, config override, or
60+
resource factory.
6961

70-
**`MyProjectApplicationBuilder::new().with_context(&copper_ctx).build()`** -- Wires
62+
**`.with_log_path(...).build()`** -- Wires
7163
everything together: creates each task by calling their `new()` constructors,
7264
pre-allocates all message buffers, and sets up the scheduler.
7365

7466
**`application.run()`** -- Starts the deterministic execution loop. Calls `start()` on
7567
all tasks, then enters the cycle loop (`preprocess` -> `process` -> `postprocess` for
7668
each task, in topological order), and continues until you stop the application (Ctrl+C).
7769

78-
**`copper_ctx.clock.clone()`** -- Note that we clone the clock **after** passing
79-
`copper_ctx` to the builder, to avoid a partial-move error.
70+
**`application.clock()`** -- Returns the runtime clock handle. The builder creates a
71+
default clock unless you override it with `.with_clock(...)`, which is mainly useful in
72+
tests or simulation.
8073

8174
## build.rs -- log index setup
8275

book/src/ch12-monitoring.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Add `cu-consolemon` to your `Cargo.toml`:
1414
```toml
1515
[dependencies]
1616
cu29 = { git = "https://github.com/copper-project/copper-rs" }
17-
cu29-helpers = { git = "https://github.com/copper-project/copper-rs" }
1817
cu-consolemon = { git = "https://github.com/copper-project/copper-rs" }
1918
bincode = { package = "cu-bincode", version = "2.0", default-features = false,
2019
features = ["derive", "alloc"] }
@@ -157,4 +156,3 @@ see without the monitor, but captured inside the TUI. You can scroll through the
157156
with `hjkl` or arrow keys. The bottom bar also shows keyboard shortcuts: `r` to reset
158157
latency statistics, `q` to quit.
159158

160-

book/src/ch13-logging-replay.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Logging and Replaying Data
22

33
Every time you've run our project so far, Copper has been quietly recording everything.
4-
Look at `main.rs` -- the call to `basic_copper_setup()` initializes a **unified logger**
4+
Look at `main.rs` -- the generated app builder's `.with_log_path(...)` call initializes a **unified logger**
55
that writes to `logs/my-project.copper`. Every cycle, the runtime serializes every message
66
exchanged between tasks (the **CopperList**) and writes it to that file.
77

@@ -259,7 +259,7 @@ hardware or a log file.
259259

260260
Copper's logger is designed for **zero-impact logging** on the critical path. Here's how:
261261

262-
1. **Pre-allocated memory slabs** -- At startup, `basic_copper_setup()` allocates a large
262+
1. **Pre-allocated memory slabs** -- At startup, `.with_log_path(...)` allocates a large
263263
contiguous block of memory (controlled by `PREALLOCATED_STORAGE_SIZE` -- 100 MB in our
264264
project). CopperLists are written into this pre-allocated buffer without any dynamic
265265
allocation.
@@ -350,4 +350,3 @@ to decide what to *exclude* (via `logging: (enabled: false)`) if storage is a co
350350
This "record everything by default" approach is what makes Copper's deterministic replay
351351
possible. Since every message and every timestamp is captured automatically, you can always
352352
go back and reproduce any moment of your robot's execution.
353-

book/src/ch14-missions.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ Update `main.rs` to select a mission:
145145
pub mod tasks;
146146

147147
use cu29::prelude::*;
148-
use cu29_helpers::basic_copper_setup;
149-
use std::path::{Path, PathBuf};
148+
use std::path::Path;
150149
use std::thread::sleep;
151150
use std::time::Duration;
152151

@@ -155,9 +154,9 @@ const PREALLOCATED_STORAGE_SIZE: Option<usize> = Some(1024 * 1024 * 100);
155154
#[copper_runtime(config = "copperconfig.ron")]
156155
struct MyProjectApplication {}
157156

158-
// Import the per-mission builders
159-
use normal::MyProjectApplicationBuilder as NormalBuilder;
160-
use direct::MyProjectApplicationBuilder as DirectBuilder;
157+
// Import the per-mission application types
158+
use normal::MyProjectApplication as NormalApp;
159+
use direct::MyProjectApplication as DirectApp;
161160

162161
fn main() {
163162
// Pick the mission from the first command-line argument (default: "normal")
@@ -171,28 +170,26 @@ fn main() {
171170
std::fs::create_dir_all(parent).expect("Failed to create logs directory");
172171
}
173172
}
174-
let copper_ctx = basic_copper_setup(
175-
&PathBuf::from(&logger_path),
176-
PREALLOCATED_STORAGE_SIZE,
177-
true,
178-
None,
179-
)
180-
.expect("Failed to setup logger.");
173+
let clock = RobotClock::default();
181174
debug!("Logger created at {}.", logger_path);
182175

183176
match mission.as_str() {
184177
"normal" => {
185178
debug!("Starting mission: normal");
186-
let mut app = NormalBuilder::new()
187-
.with_context(&copper_ctx)
179+
let mut app = NormalApp::builder()
180+
.with_clock(clock.clone())
181+
.with_log_path(logger_path, PREALLOCATED_STORAGE_SIZE)
182+
.expect("Failed to setup logger.")
188183
.build()
189184
.expect("Failed to create application.");
190185
app.run().expect("Failed to run application.");
191186
}
192187
"direct" => {
193188
debug!("Starting mission: direct");
194-
let mut app = DirectBuilder::new()
195-
.with_context(&copper_ctx)
189+
let mut app = DirectApp::builder()
190+
.with_clock(clock.clone())
191+
.with_log_path(logger_path, PREALLOCATED_STORAGE_SIZE)
192+
.expect("Failed to setup logger.")
196193
.build()
197194
.expect("Failed to create application.");
198195
app.run().expect("Failed to run application.");

book/src/ch15-workspace.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ resolver = "2"
7070

7171
[workspace.dependencies]
7272
cu29 = { path = "../../core/cu29" }
73-
cu29-helpers = { path = "../../core/cu29_helpers" }
7473
cu29-export = { path = "../../core/cu29_export" }
7574
bincode = { package = "cu-bincode", version = "2.0", default-features = false, features = ["derive", "alloc"] }
7675
serde = { version = "*", features = ["derive"] }

0 commit comments

Comments
 (0)