Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
added main macro
Browse files Browse the repository at this point in the history
  • Loading branch information
manglemix committed Feb 25, 2024
1 parent f73fa7c commit 74fb43e
Show file tree
Hide file tree
Showing 41 changed files with 745 additions and 691 deletions.
40 changes: 28 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = [
"navigator",
"rig", "tools", "smach", "costmap",
"smooth-diff-drive",
"lunasimbot",
"lunasimbot", "unros-macros", "unros",
]
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion apriltag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
apriltag-inner = { version = "0.4", package = "apriltag" }
apriltag-image = "0.1"
apriltag-nalgebra = "0.1"
unros-core = { path = "../unros-core" }
unros = { path = "../unros" }
rig = { path = "../rig" }
nalgebra = { workspace = true }
fxhash = { workspace = true }
Expand Down
61 changes: 28 additions & 33 deletions apriltag/examples/webcam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,37 @@ use apriltag::AprilTagDetector;
use camera::discover_all_cameras;
use fxhash::FxBuildHasher;
use rig::Robot;
use unros_core::{
use unros::{
anyhow::{self, Context},
default_run_options,
pubsub::Subscriber,
start_unros_runtime,
Application,
};

fn main() -> anyhow::Result<()> {
start_unros_runtime(
|mut app| async {
let rig: Robot = toml::from_str(include_str!("lunabot.toml"))?;
let (mut elements, _) = rig.destructure::<FxBuildHasher>(["camera"])?;
let camera_element = elements.remove("camera").unwrap();
let mut apriltag = AprilTagDetector::new(1108.4, 1280, 960, camera_element.get_ref());
let mut camera = discover_all_cameras()
.context("Failed to discover cameras")?
.next()
.context("No camera found")?;
camera.accept_image_received_sub(apriltag.create_image_subscription());
let mut pose_sub = Subscriber::new(1);
apriltag.add_tag(Default::default(), Default::default(), 0.12, 0);
apriltag.accept_tag_detected_sub(pose_sub.create_subscription());
app.add_task(
|_| async move {
loop {
let pose = pose_sub.recv().await;
println!("{pose}");
}
},
"pose",
);

app.add_node(camera);
app.add_node(apriltag);
Ok(app)
#[unros::main]
async fn main(mut app: Application) -> anyhow::Result<Application> {
let rig: Robot = toml::from_str(include_str!("lunabot.toml"))?;
let (mut elements, _) = rig.destructure::<FxBuildHasher>(["camera"])?;
let camera_element = elements.remove("camera").unwrap();
let mut apriltag = AprilTagDetector::new(1108.4, 1280, 960, camera_element.get_ref());
let mut camera = discover_all_cameras()
.context("Failed to discover cameras")?
.next()
.context("No camera found")?;
camera.accept_image_received_sub(apriltag.create_image_subscription());
let mut pose_sub = Subscriber::new(1);
apriltag.add_tag(Default::default(), Default::default(), 0.12, 0);
apriltag.accept_tag_detected_sub(pose_sub.create_subscription());
app.add_task(
|_| async move {
loop {
let pose = pose_sub.recv().await;
println!("{pose}");
}
},
default_run_options!(),
)
"pose",
);

app.add_node(camera);
app.add_node(apriltag);
Ok(app)
}
8 changes: 2 additions & 6 deletions apriltag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use apriltag_nalgebra::PoseExt;
use fxhash::FxHashMap;
use nalgebra::{Isometry3, Point3, UnitQuaternion, Vector3};
use rig::RobotElementRef;
use unros_core::{
use unros::{
anyhow, async_trait,
pubsub::{Publisher, Subscriber, Subscription},
setup_logging,
Expand Down Expand Up @@ -46,11 +46,7 @@ impl Debug for PoseObservation {

impl Display for PoseObservation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let axis = self
.pose
.rotation
.axis()
.unwrap_or_else(Vector3::x_axis);
let axis = self.pose.rotation.axis().unwrap_or_else(Vector3::x_axis);
write!(f, "Observer pos: ({:.2}, {:.2}, {:.2}), axis: ({:.2}, {:.2}, {:.2}), angle: {:.0}, margin: {:.0}", self.pose.translation.x, self.pose.translation.y, self.pose.translation.z, axis.x, axis.y, axis.z, self.pose.rotation.angle() / PI * 180.0, self.decision_margin)
// write!(f, "Observer pos: ({:.2}, {:.2}, {:.2}), quat: ({:.2}, {:.2}, {:.2}, {:.2}), margin: {:.0}", self.pose.translation.x, self.pose.translation.y, self.pose.translation.z, self.pose.rotation.w, self.pose.rotation.i, self.pose.rotation.j, self.pose.rotation.k, self.decision_margin)
}
Expand Down
2 changes: 1 addition & 1 deletion camera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
nokhwa = { version = "0.10", features = ["input-native"] }
unros-core = { path = "../unros-core" }
unros = { path = "../unros" }
image = { workspace = true }
2 changes: 1 addition & 1 deletion camera/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use nokhwa::{
query,
utils::{CameraIndex, RequestedFormat, RequestedFormatType},
};
use unros_core::{
use unros::{
anyhow::{self, Context},
async_trait, log,
pubsub::{Publisher, Subscription},
Expand Down
53 changes: 24 additions & 29 deletions camera/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
use std::sync::atomic::{AtomicUsize, Ordering};

use camera::discover_all_cameras;
use unros_core::{
use unros::{
anyhow::{self, Context},
default_run_options,
log::info,
pubsub::Subscriber,
start_unros_runtime, tokio,
tokio, Application,
};

fn main() -> anyhow::Result<()> {
start_unros_runtime(
|mut app| async {
let fps = 20;
discover_all_cameras()
.context("Failed to discover cameras")?
.for_each(|mut camera| {
let mut sub = Subscriber::new(8);
camera.accept_image_received_sub(sub.create_subscription());
let frame_count = AtomicUsize::new(0);
let idx = camera.camera_index;
tokio::spawn(async move {
loop {
sub.recv().await;
let frame_count = frame_count.fetch_add(1, Ordering::Relaxed) + 1;
if frame_count % (fps as usize) == 0 {
info!("idx: {idx} -> {frame_count}");
}
}
});
app.add_node(camera);
});
#[unros::main]
async fn main(mut app: Application) -> anyhow::Result<Application> {
let fps = 20;
discover_all_cameras()
.context("Failed to discover cameras")?
.for_each(|mut camera| {
let mut sub = Subscriber::new(8);
camera.accept_image_received_sub(sub.create_subscription());
let frame_count = AtomicUsize::new(0);
let idx = camera.camera_index;
tokio::spawn(async move {
loop {
sub.recv().await;
let frame_count = frame_count.fetch_add(1, Ordering::Relaxed) + 1;
if frame_count % (fps as usize) == 0 {
info!("idx: {idx} -> {frame_count}");
}
}
});
app.add_node(camera);
});

Ok(app)
},
default_run_options!(),
)
Ok(app)
}
2 changes: 1 addition & 1 deletion costmap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
unros-core = { path = "../unros-core" }
unros = { path = "../unros" }
nalgebra = { workspace = true }
image = { workspace = true, optional = false }
spin_sleep = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion costmap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
use nalgebra::{Dyn, Matrix, Point2, Point3, VecStorage};
use ordered_float::NotNan;
use spin_sleep::SpinSleeper;
use unros_core::{
use unros::{
anyhow, async_trait,
pubsub::{Subscriber, Subscription},
rayon::{
Expand Down
2 changes: 1 addition & 1 deletion drive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
unros-core = { path = "../unros-core" }
unros = { path = "../unros" }
serial = { path = "../serial" }
global-msgs = { path = "../global-msgs" }
2 changes: 1 addition & 1 deletion drive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use global_msgs::Steering;
use serial::SerialConnection;
use unros_core::{
use unros::{
anyhow, async_trait,
pubsub::{Publisher, Subscriber, Subscription},
setup_logging, tokio, Node, NodeIntrinsics, RuntimeContext,
Expand Down
2 changes: 1 addition & 1 deletion localization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
unros-core = { path = "../unros-core" }
unros = { path = "../unros" }
nalgebra = { workspace = true }
rig = { path = "../rig" }
# quaternion-core = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion localization/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rand::Rng;
use rand_distr::{Distribution, Normal};
use rig::{RobotBase, RobotElementRef};
use smach::{start_machine, Transition};
use unros_core::{
use unros::{
anyhow, async_trait,
pubsub::{Subscriber, Subscription},
rayon::{
Expand Down
2 changes: 1 addition & 1 deletion lunabot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
unros-core = { path = "../unros-core" }
unros = { path = "../unros" }
telemetry = { path = "../telemetry" }
realsense = { path = "../realsense" }
camera = { path = "../camera" }
Expand Down
Loading

0 comments on commit 74fb43e

Please sign in to comment.