Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove vestigial generics #52

Merged
merged 1 commit into from
Nov 4, 2023
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
76 changes: 21 additions & 55 deletions src/missions/action.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use async_trait::async_trait;
use core::fmt::Debug;
use std::{marker::PhantomData, sync::Arc, thread};
use std::{sync::Arc, thread};
use tokio::{join, runtime::Handle, sync::Mutex};
use uuid::Uuid;

Expand Down Expand Up @@ -42,14 +42,13 @@ pub trait ActionMod<Input: Send + Sync>: Action {
* An action that runs one of two actions depending on if its conditional reference is true or false.
*/
#[derive(Debug)]
pub struct ActionConditional<U, V: Action, W: Action, X: Action> {
pub struct ActionConditional<V: Action, W: Action, X: Action> {
condition: V,
true_branch: W,
false_branch: X,
_phantom_u: PhantomData<U>,
}

impl<U, V: Action, W: Action, X: Action> Action for ActionConditional<U, V, W, X> {
impl<V: Action, W: Action, X: Action> Action for ActionConditional<V, W, X> {
fn dot_string(&self) -> DotString {
let true_str = self.true_branch.dot_string();
let false_str = self.false_branch.dot_string();
Expand Down Expand Up @@ -85,13 +84,12 @@ impl<U, V: Action, W: Action, X: Action> Action for ActionConditional<U, V, W, X
/**
* Implementation for the ActionConditional struct.
*/
impl<U, V: Action, W: Action, X: Action> ActionConditional<U, V, W, X> {
impl<V: Action, W: Action, X: Action> ActionConditional<V, W, X> {
pub const fn new(condition: V, true_branch: W, false_branch: X) -> Self {
Self {
condition,
true_branch,
false_branch,
_phantom_u: PhantomData,
}
}
}
Expand All @@ -105,7 +103,7 @@ impl<
V: ActionExec<Output = bool>,
W: ActionExec<Output = U>,
X: ActionExec<Output = U>,
> ActionExec for ActionConditional<U, V, W, X>
> ActionExec for ActionConditional<V, W, X>
{
type Output = U;
async fn execute(&mut self) -> Self::Output {
Expand Down Expand Up @@ -295,14 +293,12 @@ impl<
}

#[derive(Debug)]
pub struct ActionSequence<T, U, V, W> {
pub struct ActionSequence<V, W> {
first: V,
second: W,
_phantom_t: PhantomData<T>,
_phantom_u: PhantomData<U>,
}

impl<T, U, V: Action, W: Action> Action for ActionSequence<T, U, V, W> {
impl<V: Action, W: Action> Action for ActionSequence<V, W> {
fn dot_string(&self) -> DotString {
let first_str = self.first.dot_string();
let second_str = self.second.dot_string();
Expand All @@ -322,26 +318,15 @@ impl<T, U, V: Action, W: Action> Action for ActionSequence<T, U, V, W> {
}
}

impl<T, U, V, W> ActionSequence<T, U, V, W> {
impl<V, W> ActionSequence<V, W> {
pub const fn new(first: V, second: W) -> Self {
Self {
first,
second,
_phantom_t: PhantomData,
_phantom_u: PhantomData,
}
Self { first, second }
}
}

#[async_trait]
impl<
T: Send + Sync,
U: Send + Sync,
X: Send + Sync,
Y: Send + Sync,
V: ActionExec<Output = Y>,
W: ActionExec<Output = X>,
> ActionExec for ActionSequence<T, U, V, W>
impl<X: Send + Sync, Y: Send + Sync, V: ActionExec<Output = Y>, W: ActionExec<Output = X>>
ActionExec for ActionSequence<V, W>
{
type Output = (Y, X);
async fn execute(&mut self) -> Self::Output {
Expand All @@ -350,14 +335,12 @@ impl<
}

#[derive(Debug)]
pub struct ActionParallel<T: Send + Sync, U: Send + Sync, V: Action, W: Action> {
pub struct ActionParallel<V: Action, W: Action> {
first: Arc<Mutex<V>>,
second: Arc<Mutex<W>>,
_phantom_t: PhantomData<T>,
_phantom_u: PhantomData<U>,
}

impl<T: Send + Sync, U: Send + Sync, V: Action, W: Action> Action for ActionParallel<T, U, V, W> {
impl<V: Action, W: Action> Action for ActionParallel<V, W> {
fn dot_string(&self) -> DotString {
let first_str = self.first.blocking_lock().dot_string();
let second_str = self.second.blocking_lock().dot_string();
Expand Down Expand Up @@ -389,26 +372,22 @@ impl<T: Send + Sync, U: Send + Sync, V: Action, W: Action> Action for ActionPara
}
}

impl<T: Send + Sync, U: Send + Sync, V: Action, W: Action> ActionParallel<T, U, V, W> {
impl<V: Action, W: Action> ActionParallel<V, W> {
pub fn new(first: V, second: W) -> Self {
Self {
first: Arc::from(Mutex::from(first)),
second: Arc::from(Mutex::from(second)),
_phantom_t: PhantomData,
_phantom_u: PhantomData,
}
}
}

#[async_trait]
impl<
T: 'static + Send + Sync,
U: 'static + Send + Sync,
Y: 'static + Send + Sync,
X: 'static + Send + Sync,
V: 'static + ActionExec<Output = Y>,
W: 'static + ActionExec<Output = X>,
> ActionExec for ActionParallel<T, U, V, W>
> ActionExec for ActionParallel<V, W>
{
type Output = (Y, X);
async fn execute(&mut self) -> Self::Output {
Expand All @@ -429,14 +408,12 @@ impl<
}

#[derive(Debug)]
pub struct ActionConcurrent<T, U, V: Action, W: Action> {
pub struct ActionConcurrent<V: Action, W: Action> {
first: V,
second: W,
_phantom_t: PhantomData<T>,
_phantom_u: PhantomData<U>,
}

impl<T, U, V: Action, W: Action> Action for ActionConcurrent<T, U, V, W> {
impl<V: Action, W: Action> Action for ActionConcurrent<V, W> {
fn dot_string(&self) -> DotString {
let first_str = self.first.dot_string();
let second_str = self.second.dot_string();
Expand Down Expand Up @@ -468,26 +445,15 @@ impl<T, U, V: Action, W: Action> Action for ActionConcurrent<T, U, V, W> {
}
}

impl<T, U, V: Action, W: Action> ActionConcurrent<T, U, V, W> {
impl<V: Action, W: Action> ActionConcurrent<V, W> {
pub const fn new(first: V, second: W) -> Self {
Self {
first,
second,
_phantom_t: PhantomData,
_phantom_u: PhantomData,
}
Self { first, second }
}
}

#[async_trait]
impl<
T: Send + Sync,
U: Send + Sync,
X: Send + Sync,
Y: Send + Sync,
V: ActionExec<Output = Y>,
W: ActionExec<Output = X>,
> ActionExec for ActionConcurrent<T, U, V, W>
impl<X: Send + Sync, Y: Send + Sync, V: ActionExec<Output = Y>, W: ActionExec<Output = X>>
ActionExec for ActionConcurrent<V, W>
{
type Output = (Y, X);
async fn execute(&mut self) -> Self::Output {
Expand Down
19 changes: 8 additions & 11 deletions src/missions/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ pub fn descend_and_go_forward<
// time in seconds that each action will wait until before continuing onto the next action.
let dive_duration = 5.0;
let forward_duration = 5.0;
ActionSequence::<T, T, _, _>::new(
ActionSequence::new(
WaitArm::new(context),
ActionSequence::<T, T, _, _>::new(
ActionSequence::<T, T, _, _>::new(
ActionSequence::new(
ActionSequence::new(
Descend::new(context, depth),
DelayAction::new(dive_duration),
),
ActionSequence::<T, T, _, _>::new(
ActionSequence::<T, T, _, _>::new(
ActionSequence::new(
ActionSequence::new(
StraightMovement::new(context, depth, true),
DelayAction::new(forward_duration),
),
Expand All @@ -89,12 +89,9 @@ pub fn gate_run<
let model = Buoy::default();
println!("OUTER MODEL LOAD");

ActionSequence::<T, T, _, _>::new(
ActionConcurrent::<T, T, _, _>::new(
descend_and_go_forward(context),
StartBno055::new(context),
),
ActionWhile::new(TupleSecond::new(ActionSequence::<T, T, _, _>::new(
ActionSequence::new(
ActionConcurrent::new(descend_and_go_forward(context), StartBno055::new(context)),
ActionWhile::new(TupleSecond::new(ActionSequence::new(
ActionChain::new(
VisionNormOffset::<T, Buoy<OnnxModel>, f64>::new(context, model),
AdjustMovement::new(context, depth),
Expand Down
16 changes: 8 additions & 8 deletions src/missions/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub fn initial_descent<
>(
context: &T,
) -> impl ActionExec + '_ {
ActionSequence::<T, T, _, _>::new(
ActionConcurrent::<T, T, _, _>::new(WaitArm::new(context), Descend::new(context, -0.5)),
WaitArm::new(context), //ActionConcurrent::<T, T, _, _>::new(WaitArm::new(context), Descend::new(context, -1.0)),
ActionSequence::new(
ActionConcurrent::new(WaitArm::new(context), Descend::new(context, -0.5)),
WaitArm::new(context), //ActionConcurrent::new(WaitArm::new(context), Descend::new(context, -1.0)),
)
}

Expand All @@ -31,17 +31,17 @@ pub fn initial_descent<
/// Runs two nested actions in order: Waiting for arm and descending in
/// parallel, followed by waiting for arm and descending concurrently.
pub fn always_wait<T: Send + Sync>(context: &T) -> impl Action + '_ {
ActionConditional::<T, _, _, _>::new(
ActionConditional::new(
AlwaysTrue::new(),
WaitArm::new(context),
Descend::new(context, -0.5),
)
}

pub fn sequence_conditional<T: Send + Sync>(context: &T) -> impl Action + '_ {
ActionSequence::<T, T, _, _>::new(
ActionSequence::<T, T, _, _>::new(WaitArm::new(context), Descend::new(context, -1.0)),
ActionConditional::<T, _, _, _>::new(
ActionSequence::new(
ActionSequence::new(WaitArm::new(context), Descend::new(context, -1.0)),
ActionConditional::new(
AlwaysTrue::new(),
WaitArm::new(context),
Descend::new(context, -0.5),
Expand All @@ -50,7 +50,7 @@ pub fn sequence_conditional<T: Send + Sync>(context: &T) -> impl Action + '_ {
}

pub fn race_conditional<T: Send + Sync>(context: &T) -> impl Action + '_ {
ActionConditional::<T, _, _, _>::new(
ActionConditional::new(
AlwaysTrue::new(),
WaitArm::new(context),
RaceAction::new(Descend::new(context, -0.5), DelayAction::new(1.0)),
Expand Down
Loading