Skip to content

Commit

Permalink
clean up dumb stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Nov 3, 2024
1 parent f2eb02d commit 4a63a92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 91 deletions.
4 changes: 2 additions & 2 deletions kscaleos/kscaleos/src/bin/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use kscaleos::hello_world;
use kscaleos::main as kscaleos_main;

fn main() {
hello_world();
kscaleos_main();
}
8 changes: 0 additions & 8 deletions kscaleos/kscaleos/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use robstride::MotorType;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs;

#[derive(Serialize, Deserialize, Debug)]
pub struct MotorConfig {
Expand All @@ -28,10 +27,3 @@ pub struct LimbConfig {
pub struct Config {
pub limbs: HashMap<Limb, LimbConfig>,
}

impl Config {
pub fn new(config_path: &str) -> Self {
let file = fs::File::open(config_path).expect("Failed to open config file");
serde_yaml::from_reader(file).expect("Failed to parse config YAML")
}
}
81 changes: 4 additions & 77 deletions kscaleos/kscaleos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,83 +1,10 @@
use robstride::{MotorType, MotorsSupervisor};
use std::collections::HashMap;
use std::sync::{Arc, RwLock};

mod config;
mod runner;
mod state;

fn main() {
let config = config::Config::new("config.yaml");
let state = Arc::new(RwLock::new(State::new()));

// Four motor supervisors, one for each limb.
let mut motor_supervisors = vec![];
for i in 0..4 {
let port_name = format!("/dev/ttyCH341USB{}", i);

let motor_infos = match i {
// Left arm.
0 => HashMap::from([
(1, MotorType::Type03),
(2, MotorType::Type03),
(3, MotorType::Type02),
(4, MotorType::Type02),
(5, MotorType::Type01),
]),
// Right arm.
1 => HashMap::from([
(1, MotorType::Type03),
(2, MotorType::Type03),
(3, MotorType::Type02),
(4, MotorType::Type02),
(5, MotorType::Type01),
]),
// Left leg.
2 => HashMap::from([
(1, MotorType::Type04),
(2, MotorType::Type03),
(3, MotorType::Type03),
(4, MotorType::Type03),
(5, MotorType::Type01),
]),
// Right leg.
3 => HashMap::from([
(1, MotorType::Type04),
(2, MotorType::Type03),
(3, MotorType::Type03),
(4, MotorType::Type03),
(5, MotorType::Type01),
]),
_ => {
panic!("Invalid limb index: {}", i);
}
};

let motor_supervisor =
MotorsSupervisor::new(port_name.as_str(), &motor_infos, false, 1000.0, true).unwrap();
motor_supervisors.push(motor_supervisor);
}
}

struct State {}

impl State {
fn new() -> Self {}

fn update(&mut self, _input: SensorData, _commands: Commands) {
// Update state logic
}
}

fn read_sensors() -> SensorData {
// Read from camera and motors
SensorData { /* fields */ }
}
use runner::run;
use std::sync::{Arc, RwLock};

fn send_commands(_commands: Commands) {
// Interface with motor drivers
pub fn main() {
run(Arc::new(RwLock::new(state::State::new())));
}

struct SensorData {/* fields */}

struct Commands {/* fields */}
7 changes: 3 additions & 4 deletions kscaleos/kscaleos/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use std::{

use crate::state::State;

pub fn run(state: Arc<RwLock<State>>) {
pub fn run(_state: Arc<RwLock<State>>) {
loop {
let state = state.read().unwrap();
println!("Running main control loop... State: {:?}", state);
thread::sleep(Duration::from_millis(10));
println!("Running main control loop...");
thread::sleep(Duration::from_millis(100));
}
}

0 comments on commit 4a63a92

Please sign in to comment.