added basic controller
This commit is contained in:
parent
8a972cd660
commit
e717238727
3 changed files with 1105 additions and 191 deletions
1044
interface/Cargo.lock
generated
Normal file
1044
interface/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
13
interface/Cargo.toml
Normal file
13
interface/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "interface"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
tokio = { version = "1.43.0", features = ["full"] }
|
||||
anyhow = "1.0.95"
|
||||
gilrs = "0.11.0"
|
||||
futures = "0.3.31"
|
||||
serde = { version = "1.0.217", features = ["alloc"] }
|
||||
postcard = { version = "1.0.0", features = ["alloc", "use-std"] }
|
||||
42
interface/src/main.rs
Normal file
42
interface/src/main.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use anyhow::Context;
|
||||
use common::Command;
|
||||
use gilrs::{Axis, Gilrs};
|
||||
use tokio::{io::{AsyncWriteExt, BufWriter}, net::TcpStream, time::sleep};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
println!("Hello, world!");
|
||||
|
||||
let gamepads = Gilrs::new().unwrap();
|
||||
let (_, gamepad) = gamepads.gamepads().nth(0).context("no gamepads")?;
|
||||
let ly = gamepad.axis_code(Axis::LeftStickY).context("no left joystick")?;
|
||||
let rx = gamepad.axis_code(Axis::RightStickX).context("no right joystick")?;
|
||||
|
||||
let mut robot = TcpStream::connect("pelican.dyn.wpi.edu:3322").await?;
|
||||
robot.set_nodelay(true)?;
|
||||
|
||||
|
||||
let (_telem, robot_controller) = robot.split();
|
||||
|
||||
let mut robot_controller = BufWriter::new(robot_controller);
|
||||
|
||||
loop {
|
||||
let values = gamepad.state();
|
||||
|
||||
let ly = values.axis_data(ly).context("no left")?.value();
|
||||
let rx = values.axis_data(rx).context("no left")?.value();
|
||||
|
||||
let cmd = Command::Twist(ly, rx);
|
||||
|
||||
let encoded = postcard::to_stdvec(&cmd)?;
|
||||
|
||||
robot_controller.write_u32(encoded.len() as u32).await?;
|
||||
robot_controller.write_all(&encoded).await?;
|
||||
|
||||
robot_controller.flush().await?;
|
||||
|
||||
sleep(Duration::from_micros(3500)).await;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue