Skip to content

Commit

Permalink
More debugging (#21)
Browse files Browse the repository at this point in the history
* more debugging

* more debugging

* fixed some issues

* fix types
  • Loading branch information
codekansas authored Oct 12, 2024
1 parent 98d3496 commit 2cac0e6
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 93 deletions.
4 changes: 2 additions & 2 deletions actuator/rust/bindings/bindings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PyRobstrideMotorFeedback:


class PyRobstrideMotors:
def __new__(cls,port_name:str, motor_infos:typing.Mapping[int, str]): ...
def __new__(cls,port_name,motor_infos,verbose = ...): ...
def send_get_mode(self) -> dict[int, str]:
...

Expand All @@ -53,7 +53,7 @@ class PyRobstrideMotors:


class PyRobstrideMotorsSupervisor:
def __new__(cls,port_name:str, motor_infos:typing.Mapping[int, str]): ...
def __new__(cls,port_name:str, motor_infos:typing.Mapping[int, str], verbose:bool): ...
def set_position(self, motor_id:int, position:float) -> None:
...

Expand Down
10 changes: 6 additions & 4 deletions actuator/rust/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use robstride::{
};
use std::collections::HashMap;
use std::time::Duration;

#[gen_stub_pyclass]
#[pyclass]
struct PyRobstrideMotors {
Expand All @@ -19,7 +20,8 @@ struct PyRobstrideMotors {
#[pymethods]
impl PyRobstrideMotors {
#[new]
fn new(port_name: String, motor_infos: HashMap<u8, String>) -> PyResult<Self> {
#[pyo3(signature = (port_name, motor_infos, verbose = false))]
fn new(port_name: String, motor_infos: HashMap<u8, String>, verbose: bool) -> PyResult<Self> {
let motor_infos = motor_infos
.into_iter()
.map(|(id, type_str)| {
Expand All @@ -28,7 +30,7 @@ impl PyRobstrideMotors {
})
.collect::<PyResult<HashMap<u8, RobstrideMotorType>>>()?;

let motors = RobstrideMotors::new(&port_name, &motor_infos)
let motors = RobstrideMotors::new(&port_name, &motor_infos, verbose)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?;

Ok(PyRobstrideMotors { inner: motors })
Expand Down Expand Up @@ -225,7 +227,7 @@ struct PyRobstrideMotorsSupervisor {
#[pymethods]
impl PyRobstrideMotorsSupervisor {
#[new]
fn new(port_name: String, motor_infos: HashMap<u8, String>) -> PyResult<Self> {
fn new(port_name: String, motor_infos: HashMap<u8, String>, verbose: bool) -> PyResult<Self> {
let motor_infos = motor_infos
.into_iter()
.map(|(id, type_str)| {
Expand All @@ -234,7 +236,7 @@ impl PyRobstrideMotorsSupervisor {
})
.collect::<PyResult<HashMap<u8, RobstrideMotorType>>>()?;

let controller = RobstrideMotorsSupervisor::new(&port_name, &motor_infos)
let controller = RobstrideMotorsSupervisor::new(&port_name, &motor_infos, verbose)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?;

Ok(PyRobstrideMotorsSupervisor { inner: controller })
Expand Down
1 change: 1 addition & 0 deletions actuator/rust/robstride/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ serialport = "4.5.1"
ctrlc = "3.4.5"
lazy_static = "1.4.0"
spin_sleep = "1.2.1"
clap = { version = "4.3", features = ["derive"] }
17 changes: 16 additions & 1 deletion actuator/rust/robstride/src/bin/supervisor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use clap::Parser;
use robstride::{motor_type_from_str, MotorType, MotorsSupervisor};
use std::collections::HashMap;
use std::io::{self, Write};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long, help = "Enable verbose output")]
verbose: bool,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();

print!("Enter the TEST_ID (u8): ");
io::stdout().flush()?;
let mut input = String::new();
Expand Down Expand Up @@ -32,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let motor_type = motor_type_from_str(motor_type_input.as_str())?;
let motor_infos: HashMap<u8, MotorType> = HashMap::from([(test_id, motor_type)]);
let controller = MotorsSupervisor::new(&port_name, &motor_infos)?;
let controller = MotorsSupervisor::new(&port_name, &motor_infos, args.verbose)?;

println!("Motor Controller Test CLI");
println!("Available commands:");
Expand All @@ -44,6 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!(" zero / z");
println!(" get_feedback / g");
println!(" pause / w");
println!(" reset / r");
println!(" quit / q");

loop {
Expand Down Expand Up @@ -116,6 +127,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
controller.toggle_pause();
println!("Toggled pause state");
}
"reset" | "r" => {
controller.reset();
println!("Reset motors");
}
"quit" | "q" => {
controller.stop();
println!("Exiting...");
Expand Down
Loading

0 comments on commit 2cac0e6

Please sign in to comment.