Skip to content

Commit

Permalink
Prelude but in cu29::prelude (#141)
Browse files Browse the repository at this point in the history
* Split cu29 to cu29 (prelude) and cu29_runtime (actual impl)

* large porting to the new prelude

* cargo fmt

* Added readme change for prelude.
  • Loading branch information
gbin authored Dec 10, 2024
1 parent a32422b commit 8029113
Show file tree
Hide file tree
Showing 65 changed files with 229 additions and 328 deletions.
29 changes: 16 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"core/cu29_log",
"core/cu29_log_derive",
"core/cu29_log_runtime",
"core/cu29_runtime",
"core/cu29_soa_derive",
"core/cu29_traits",
"core/cu29_unifiedlog",
Expand Down Expand Up @@ -48,6 +49,7 @@ default-members = [
"core/cu29_log",
"core/cu29_log_derive",
"core/cu29_log_runtime",
"core/cu29_runtime",
"core/cu29_soa_derive",
"core/cu29_traits",
"core/cu29_unifiedlog",
Expand All @@ -71,19 +73,20 @@ no_individual_tags = true
[workspace.dependencies]

# Copper Core
cu29 = { path = "core/cu29" , version = "0.5.1"}
cu29-clock = { path = "core/cu29_clock" , version = "0.5.1"}
cu29-derive = { path = "core/cu29_derive" , version = "0.5.1"}
cu29-export = { path = "core/cu29_export" , version = "0.5.1"}
cu29-helpers = { path = "core/cu29_helpers" , version = "0.5.1"}
cu29-intern-strs = { path = "core/cu29_intern_strs" , version = "0.5.1"}
cu29-log = { path = "core/cu29_log" , version = "0.5.1"}
cu29-log-derive = { path = "core/cu29_log_derive" , version = "0.5.1"}
cu29-log-runtime = { path = "core/cu29_log_runtime" , version = "0.5.1"}
cu29-soa-derive = { path = "core/cu29_soa_derive" , version = "0.5.1"}
cu29-traits = { path = "core/cu29_traits" , version = "0.5.1"}
cu29-unifiedlog = { path = "core/cu29_unifiedlog" , version = "0.5.1"}
cu29-value = { path = "core/cu29_value" , version = "0.5.1"}
cu29 = { path = "core/cu29", version = "0.5.1" }
cu29-clock = { path = "core/cu29_clock", version = "0.5.1" }
cu29-derive = { path = "core/cu29_derive", version = "0.5.1" }
cu29-export = { path = "core/cu29_export", version = "0.5.1" }
cu29-helpers = { path = "core/cu29_helpers", version = "0.5.1" }
cu29-intern-strs = { path = "core/cu29_intern_strs", version = "0.5.1" }
cu29-log = { path = "core/cu29_log", version = "0.5.1" }
cu29-log-derive = { path = "core/cu29_log_derive", version = "0.5.1" }
cu29-log-runtime = { path = "core/cu29_log_runtime", version = "0.5.1" }
cu29-runtime = { path = "core/cu29_runtime", version = "0.5.1" }
cu29-soa-derive = { path = "core/cu29_soa_derive", version = "0.5.1" }
cu29-traits = { path = "core/cu29_traits", version = "0.5.1" }
cu29-unifiedlog = { path = "core/cu29_unifiedlog", version = "0.5.1" }
cu29-value = { path = "core/cu29_value", version = "0.5.1" }

# Payload definitions
cu-sensor-payloads = { path = "components/payloads/cu_sensor_payloads", version = "0.5.0" }
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ The source code for this demo is available in the [examples/cu_rp_balancebot](ex
2. **Runtime generation**: The current implementation works for up to middle size robots (~a couple dozen of tasks).
3. **Log reader**: You can reread the logs generated by Copper from your robot, sim or resim.
4. **Structured log reader**: debug logs are indexed and string interned at compile time for maximum efficiency.
5. **Components**: We have a growing number of drivers, algorithms and standard interfaces, if you have implemented a new
5. **Components**: We have a growing number of drivers, algorithms and standard interfaces, if you have implemented a
new
component, ping us and we will add it to the list!
6. **log replay / resim**: You can deterministically replay/resim a log. If all you tasks are deterministic, you will
get the exact same result as a real log on the robot or from the sim.
Expand Down Expand Up @@ -136,6 +137,9 @@ Then, on your main.rs:

```rust,ignore
// Import the prelude to get all the macros and traits you need.
use cu29::prelude::*;
// Your application will be a struct that will hold the runtime, loggers etc.
// This proc macro is where all the runtime generation happens. You can see the code generated by the macro at
// compile time.
Expand Down Expand Up @@ -234,14 +238,17 @@ examples/ros_caterpillar
You can try them out by either just logging on a desktop, or with GPIOs on a RPi.
You should see a couple order of magnitude difference in performance.

Copper has been designed for performance first. Not unlike a game engine, we use a data oriented approach to minimize latency
Copper has been designed for performance first. Not unlike a game engine, we use a data oriented approach to minimize
latency
and maximize throughput.

### Safety

As Copper is written in Rust, it is memory safe and thread safe by design. It is also designed to be easy to use and avoid common pitfalls.
As Copper is written in Rust, it is memory safe and thread safe by design. It is also designed to be easy to use and
avoid common pitfalls.

As we progress on this project we plan on implementing more and more early warnings to help you avoid "the death by a thousand cuts" that can happen in a complex system.
As we progress on this project we plan on implementing more and more early warnings to help you avoid "the death by a
thousand cuts" that can happen in a complex system.

### Release Notes

Expand All @@ -256,7 +263,8 @@ You can find the release notes [here](https://github.com/copper-project/copper-r
Here are some of the features we plan to implement next (in ~order of priority), if you are interested in contributing
on any of those, please let us know!:

- [ ] **Parallel Copper Lists**: Today Copper is single-threaded; this should enable concurrent Copper Lists to be executed
- [ ] **Parallel Copper Lists**: Today Copper is single-threaded; this should enable concurrent Copper Lists to be
executed
at the same time with no contention.
- [ ] **ROS/DDS interfacing**: Build a pair of sink and source to connect to existing ROS systems, helping users migrate
their infra bit by bit.
Expand Down
5 changes: 0 additions & 5 deletions components/sinks/cu_iceoryx2_sink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@ description = "Copper sink task for Iceoryx2."
[dependencies]
iceoryx2 = { version = "0.4.1" }
cu29 = { workspace = true }
cu29-traits = { workspace = true }
cu29-log-derive = { workspace = true }
cu29-log = { workspace = true }

cu29-log-runtime = { workspace = true } # needed
11 changes: 3 additions & 8 deletions components/sinks/cu_iceoryx2_sink/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use cu29::clock::RobotClock;
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuMsgPayload};
use cu29::cutask::{CuSinkTask, Freezable};
use cu29::input_msg;
use cu29_log_derive::debug;
use cu29_traits::{CuError, CuResult};
use cu29::prelude::*;
use iceoryx2::node::NodeBuilder;
use iceoryx2::port::publisher::Publisher;
use iceoryx2::prelude::*;
Expand All @@ -18,7 +13,7 @@ where
P: CuMsgPayload, // TODO: Maybe with something a little more generic we can be ROS2 compatible
{
service_name: ServiceName,
node: Node<ipc::Service>,
node: iceoryx2::prelude::Node<ipc::Service>,
service: Option<PortFactory<ipc::Service, CuMsg<P>, ()>>,
publisher: Option<Publisher<ipc::Service, CuMsg<P>, ()>>,
}
Expand All @@ -44,7 +39,7 @@ where

let service_name = ServiceName::new(service_name.as_str())
.map_err(|e| CuError::new_with_cause("Failed to create service name.", e))?;
let node: Node<ipc::Service> = NodeBuilder::new()
let node: iceoryx2::prelude::Node<ipc::Service> = NodeBuilder::new()
.create::<ipc::Service>()
.map_err(|e| CuError::new_with_cause("Failed to create node.", e))?;

Expand Down
9 changes: 1 addition & 8 deletions components/sinks/cu_rp_gpio/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
use bincode::{Decode, Encode};
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuSinkTask, Freezable};
use cu29::input_msg;
use cu29::CuResult;
use cu29::prelude::*;
use serde::{Deserialize, Serialize};

#[cfg(mock)]
use cu29_log_derive::debug;

use cu29::clock::RobotClock;
#[cfg(hardware)]
use {
cu29::CuError,
Expand Down
6 changes: 0 additions & 6 deletions components/sinks/cu_rp_sn754410/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ repository.workspace = true

[dependencies]
cu29 = { workspace = true }
cu29-log = { workspace = true }
cu29-log-runtime = { workspace = true } # needed
cu29-log-derive = { workspace = true }
cu29-traits = { workspace = true }
bincode = { workspace = true }
serde = { workspace = true }

[dev-dependencies]
cu29-derive = { workspace = true }
cu29-unifiedlog = { workspace = true } # needed
cu29-helpers = { workspace = true }

[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
10 changes: 1 addition & 9 deletions components/sinks/cu_rp_sn754410/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ use bincode::de::Decoder;
use bincode::enc::Encoder;
use bincode::error::{DecodeError, EncodeError};
use bincode::{Decode, Encode};
use cu29::clock::{CuTime, RobotClock};
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuSinkTask, Freezable};
use cu29::{input_msg, CuResult};
use cu29::prelude::*;
use serde::{Deserialize, Serialize};

use cu29_log_derive::debug;

#[cfg(hardware)]
use cu29_traits::CuError;

#[cfg(hardware)]
use rppal::pwm::{Channel, Polarity, Pwm};

Expand Down
4 changes: 1 addition & 3 deletions components/sinks/cu_rp_sn754410/tests/sn754410_tester.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use cu29::cutask::CuSinkTask;
use cu29_derive::copper_runtime;
use cu29::prelude::*;
use cu29_helpers::basic_copper_setup;
use cu29_log_derive::debug;
use std::path::PathBuf;

#[copper_runtime(config = "tests/copperconfig.ron")]
Expand Down
6 changes: 0 additions & 6 deletions components/sources/cu_ads7883/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ repository.workspace = true

[dependencies]
cu29 = { workspace = true }
cu29-log = { workspace = true }
cu29-log-runtime = { workspace = true } # needed
cu29-log-derive = { workspace = true }
bincode = { workspace = true }
serde = { workspace = true }

[target.'cfg(target_os = "linux")'.dependencies]
spidev = "0.6.0"

[dev-dependencies]
cu29-derive = { workspace = true }
cu29-unifiedlog = { workspace = true } # needed
cu29-traits = { workspace = true } # needed
cu29-helpers = { workspace = true }

[build-dependencies]
Expand Down
9 changes: 1 addition & 8 deletions components/sources/cu_ads7883/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
mod mock;

use bincode::{Decode, Encode};
use cu29::clock::RobotClock;
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuSrcTask, Freezable};
use cu29::{output_msg, CuError, CuResult};
use cu29_log_derive::debug;
use cu29::prelude::*;
use serde::{Deserialize, Serialize};

#[cfg(hardware)]
Expand Down Expand Up @@ -171,9 +167,6 @@ impl<'cl> CuSrcTask<'cl> for ADS7883 {

pub mod test_support {
use super::*;
use cu29::cutask::CuSinkTask;
use cu29::input_msg;
use cu29_log_derive::debug;

pub struct ADS78883TestSink;

Expand Down
7 changes: 1 addition & 6 deletions components/sources/cu_ads7883/tests/ads7883_tester.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use cu29::clock::RobotClock;
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuSinkTask, Freezable};
use cu29::{input_msg, CuResult};
use cu29_derive::copper_runtime;
use cu29::prelude::*;
use cu29_helpers::basic_copper_setup;
use cu29_log_derive::debug;
use cu_ads7883_new::ADSReadingPayload;
use std::path::PathBuf;

Expand Down
3 changes: 1 addition & 2 deletions components/sources/cu_hesai/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
cu29-clock = { workspace = true }
cu29 = { workspace = true }
cu-sensor-payloads = { workspace = true }
bytemuck = { version = "1.20.0", features = ["derive"] }
uom = { workspace = true }
chrono = { version = "0.4.38" }
cu29 = { workspace = true }
socket2 = { version = "0.5.8", features = ["all"] }

# [dev-dependencies]
Expand Down
6 changes: 1 addition & 5 deletions components/sources/cu_hesai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ pub mod parser;

use crate::parser::{generate_default_elevation_calibration, RefTime};
use chrono::Utc;
use cu29::config::ComponentConfig;
use cu29::cutask::CuMsg;
use cu29::cutask::{CuSrcTask, Freezable};
use cu29::{output_msg, CuError, CuResult};
use cu29_clock::{CuDuration, CuTime, CuTimeRange, RobotClock, Tov};
use cu29::prelude::*;
use cu_sensor_payloads::{PointCloud, PointCloudSoa};
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
use std::io::ErrorKind;
Expand Down
4 changes: 2 additions & 2 deletions components/sources/cu_hesai/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use chrono::{DateTime, MappedLocalTime, TimeZone, Utc};
use cu29_clock::{CuDuration, CuTime};
use cu29::prelude::{CuDuration, CuTime};
use std::error::Error;
use std::fmt;
use std::fmt::{Debug, Formatter};
Expand Down Expand Up @@ -505,7 +505,7 @@ pub fn generate_default_elevation_calibration() -> [Angle; 32] {

mod tests {
use super::*;
use cu29_clock::RobotClock;
use cu29::prelude::RobotClock;
use pcap::Capture;

#[test]
Expand Down
4 changes: 0 additions & 4 deletions components/sources/cu_iceoryx2_src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ repository.workspace = true
[dependencies]
iceoryx2 = { version = "0.4.1" }
cu29 = { workspace = true }
cu29-traits = { workspace = true }
cu29-log-derive = { workspace = true }
cu29-log = { workspace = true }
cu29-log-runtime = { workspace = true } # needed
12 changes: 3 additions & 9 deletions components/sources/cu_iceoryx2_src/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use cu29::clock::RobotClock;
use cu29::config::ComponentConfig;
use cu29::cutask::Freezable;
use cu29::cutask::{CuMsg, CuMsgPayload, CuSrcTask};
use cu29::output_msg;
use cu29_log_derive::debug;
use cu29_traits::{CuError, CuResult};
use cu29::prelude::*;
use iceoryx2::node::NodeBuilder;
use iceoryx2::port::subscriber::Subscriber;
use iceoryx2::prelude::*;
Expand All @@ -17,7 +11,7 @@ where
P: CuMsgPayload,
{
service_name: ServiceName,
node: Node<ipc::Service>,
node: iceoryx2::prelude::Node<ipc::Service>,
service: Option<PortFactory<ipc::Service, CuMsg<P>, ()>>,
subscriber: Option<Subscriber<ipc::Service, CuMsg<P>, ()>>,
}
Expand All @@ -44,7 +38,7 @@ where
let service_name = ServiceName::new(service_name.as_str())
.map_err(|e| CuError::new_with_cause("Failed to create service name.", e))?;

let node: Node<ipc::Service> = NodeBuilder::new()
let node: iceoryx2::prelude::Node<ipc::Service> = NodeBuilder::new()
.create::<ipc::Service>()
.map_err(|e| CuError::new_with_cause("Failed to create node.", e))?;

Expand Down
5 changes: 1 addition & 4 deletions components/sources/cu_wt901/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use bincode::de::Decoder;
use bincode::enc::Encoder;
use bincode::error::{DecodeError, EncodeError};
use bincode::{Decode, Encode};
use cu29::clock::RobotClock;
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuSrcTask, Freezable};
use cu29::{output_msg, CuResult};
use cu29::prelude::*;
#[cfg(hardware)]
use embedded_hal::i2c::I2c;
#[cfg(hardware)]
Expand Down
7 changes: 1 addition & 6 deletions components/sources/cu_wt901/tests/wt901_tester.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use cu29::clock::RobotClock;
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuSinkTask, Freezable};
use cu29::{input_msg, CuResult};
use cu29_derive::copper_runtime;
use cu29::prelude::*;
use cu29_helpers::basic_copper_setup;
use cu29_log_derive::debug;
use cu_wt901::PositionalReadingsPayload;
use std::path::PathBuf;
use std::thread::sleep;
Expand Down
4 changes: 0 additions & 4 deletions components/tasks/cu_pid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ repository.workspace = true

[dependencies]
cu29 = { workspace = true }
cu29-log = { workspace = true }
cu29-log-derive = { workspace = true }
cu29-log-runtime = { workspace = true } # needed
cu29-traits = { workspace = true }
bincode = { workspace = true }
8 changes: 1 addition & 7 deletions components/tasks/cu_pid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ use bincode::de::Decoder;
use bincode::enc::Encoder;
use bincode::error::{DecodeError, EncodeError};
use bincode::{Decode, Encode};
use cu29::clock::{CuDuration, CuTime, RobotClock, Tov};
use cu29::config::ComponentConfig;
use cu29::cutask::{CuMsg, CuMsgPayload};
use cu29::cutask::{CuTask, Freezable};
use cu29::{input_msg, output_msg, CuResult};
use cu29_log_derive::debug;
use cu29_traits::CuError;
use cu29::prelude::*;
use std::marker::PhantomData;

/// Output of the PID controller.
Expand Down
Loading

0 comments on commit 8029113

Please sign in to comment.