two types of command at the same time (sputters, lags, then dies)

This commit is contained in:
Andy Killorin 2025-02-13 15:57:34 -05:00
commit b131ad8957
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -14,10 +14,12 @@ async fn main() -> anyhow::Result<()> {
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 lb = gamepad.button_code(gilrs::Button::LeftTrigger2).context("no lb")?;
let lb = gamepad.button_code(gilrs::Button::LeftTrigger).context("no lb")?;
let a = gamepad.button_code(gilrs::Button::South).context("no a")?;
let mut last_a = false;
let mut robot = TcpStream::connect("pelican.dyn.wpi.edu:3322").await?;
let server = "130.215.211.79:3322";
let mut robot = TcpStream::connect(server).await?;
robot.set_nodelay(true)?;
let (telem, robot_controller) = robot.into_split();
@ -66,16 +68,27 @@ async fn main() -> anyhow::Result<()> {
}
let cmd = Command::Twist(ly, rx);
println!("twist");
let encoded = postcard::to_stdvec(&cmd)?;
robot_controller.write_u32(encoded.len() as u32).await?;
robot_controller.write_all(&encoded).await?;
if a != last_a {
let black = Vector3::repeat(0u8);
let green = Vector3::new(254u8, 0, 254);
let cmd = Command::SetLed(if a {green} else {black});
let encoded = postcard::to_stdvec(&cmd)?;
robot_controller.write_u32(encoded.len() as u32).await?;
robot_controller.write_all(&encoded).await?;
println!("led");
}
last_a = a;
if let Err(e) = robot_controller.flush().await {
println!("flush fail: {e}, reconnecting");
robot = TcpStream::connect("pelican.dyn.wpi.edu:3322").await?;
robot = TcpStream::connect(server).await?;
robot.set_nodelay(true)?;
let (telem, robot) = robot.into_split();
@ -85,16 +98,7 @@ async fn main() -> anyhow::Result<()> {
robot_controller = BufWriter::new(robot);
};
let black = Vector3::repeat(0u8);
let green = Vector3::new(100u8, 0, 0);
let cmd = Command::SetLed(if a {green} else {black});
let encoded = postcard::to_stdvec(&cmd)?;
robot_controller.write_u32(encoded.len() as u32).await?;
robot_controller.write_all(&encoded).await?;
sleep(Duration::from_micros(350)).await;
robot_controller.flush().await?;
sleep(Duration::from_micros(3500)).await;
sleep(Duration::from_millis(65)).await;
}
}