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

PathPlanner #6

Merged
merged 29 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
515559d
[Robot] Add pathplanner to drive.
mvog2501 Nov 21, 2023
94697bc
[Robot] Add auto functionality
mvog2501 Nov 21, 2023
d378150
[Robot] Made a more advanced example auto
mvog2501 Nov 22, 2023
4d2274c
[Pathfinding] Add pathfinder
mvog2501 Nov 22, 2023
ff1b5fd
[Pathfinding] Fix build.gradle
rmheuer Nov 22, 2023
132f1af
[ShuffleLog] Add Pathfinding layer back
rmheuer Nov 23, 2023
8d6ad5c
[Robot] Theta* mostly works
rmheuer Nov 24, 2023
f9128a9
[Robot] Handle case where path was not found
rmheuer Nov 26, 2023
fefaff8
[Robot] Don't register both pathfinders
rmheuer Nov 26, 2023
eafeba3
Merge branch 'main' into pathplanner
rmheuer Nov 26, 2023
1500708
[Pathfinding] Rewrite in Rust for performance
rmheuer Nov 27, 2023
ad85a13
[Robot] Fallback if pathfinder does not respond
rmheuer Nov 27, 2023
d49ed14
[ShuffleLog] Fix 2d field view Z-order
rmheuer Nov 27, 2023
35eaf31
[ShuffleLog] Make Field2d layer not crash
rmheuer Nov 27, 2023
cb857c9
[Build] Add task to simulate everything at once
rmheuer Dec 2, 2023
5cf39e9
[Build] Print correct process name
rmheuer Dec 2, 2023
e174397
[Build] Fix deprecated Gradle features
rmheuer Dec 2, 2023
5991374
[MathLib] Don't use GradleRIO plugin
rmheuer Dec 2, 2023
1e956ff
[ShuffleLog] Don't try to deploy to RoboRIO
rmheuer Dec 2, 2023
f74253e
[Build] Add task to deploy to Orange Pi
rmheuer Dec 3, 2023
68fa827
[Pathfinding] Add dynamic shapes
rmheuer Dec 3, 2023
ce2ea8b
[ShuffleLog] Remove path follower test
rmheuer Dec 3, 2023
1106cd4
[ShuffleLog] Show dynamic shapes
rmheuer Dec 3, 2023
12921e9
[Robot] Send dynamic obstacles
rmheuer Dec 3, 2023
b74d5aa
[Robot] Add dynamic circle obstacles
rmheuer Dec 3, 2023
9cd47b1
[Pathfinding] Only regenerate dynamic cells
rmheuer Dec 3, 2023
06e9d2e
[Pathfinding] Only update grid region around changed shape
rmheuer Dec 3, 2023
cf6247f
[Pathfinding] Special case for unrotated rectangles
rmheuer Dec 3, 2023
c9650d0
[Pathfinding] Don't reallocate neighbors vec
rmheuer Dec 4, 2023
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
8 changes: 5 additions & 3 deletions MathLib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
plugins {
id 'java-library'
id "edu.wpi.first.GradleRIO" version "2024.1.1-beta-3"
// id "edu.wpi.first.GradleRIO" version "2024.1.1-beta-3"
}

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

group 'com.swrobotics'
version '2024'
Expand Down
87 changes: 75 additions & 12 deletions Messenger/messenger-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
use bytes::{Buf, BufMut, Bytes, BytesMut};
use tokio::{
io::AsyncWriteExt,
net::TcpStream,
net::{tcp::OwnedWriteHalf, TcpStream},
sync::mpsc::{self, UnboundedReceiver, UnboundedSender},
task::JoinHandle,
};
Expand All @@ -12,8 +12,8 @@ use tokio_util::codec::{Decoder, FramedRead};

#[derive(Debug)]
pub struct Message {
name: String,
data: Bytes,
pub name: String,
pub data: Bytes,
}

struct MessageDecoder;
Expand Down Expand Up @@ -69,6 +69,7 @@ impl Decoder for MessageDecoder {
}

enum ToIoCmd {
Listen(String),
SendMessage(Message),
Disconnect,
}
Expand All @@ -86,11 +87,26 @@ fn pack_message(m: Message) -> BytesMut {
dst
}

async fn send_listen_message(
write_half: &mut OwnedWriteHalf,
name: &str,
) -> Result<(), std::io::Error> {
let mut data = BytesMut::with_capacity(name.len() + 2);
pack_str(&name, &mut data);
write_half
.write_all(&pack_message(Message {
name: "_Listen".to_string(),
data: data.into(),
}))
.await
}

async fn message_io(
addr: &str,
name: &str,
in_send: &mpsc::UnboundedSender<Message>,
out_recv: &mut mpsc::UnboundedReceiver<ToIoCmd>,
listening: &mut Vec<String>,
) -> Result<(), std::io::Error> {
let stream = TcpStream::connect(addr).await?;
let (read_half, mut write_half) = stream.into_split();
Expand All @@ -100,6 +116,12 @@ async fn message_io(
pack_str(name, &mut name_buf);
write_half.write_all(&name_buf).await?;

println!("Messenger connected");

for name in listening {
send_listen_message(&mut write_half, &name).await?;
}

let mut read = FramedRead::new(read_half, MessageDecoder);

let mut heartbeat_interval = tokio::time::interval(Duration::from_secs(1));
Expand All @@ -111,14 +133,15 @@ async fn message_io(
loop {
tokio::select! {
_ = heartbeat_interval.tick() => {
println!("Writing heartbeat");
write_half.write_all(&packed_heartbeat).await?;
}

result = out_recv.recv() => {match result {
Some(cmd) => match cmd {
ToIoCmd::Listen(name) => {
send_listen_message(&mut write_half, &name).await?;
}
ToIoCmd::SendMessage(msg) => {
println!("Writing message: {:?}", msg);
write_half.write_all(&pack_message(msg)).await?;
}
ToIoCmd::Disconnect => break
Expand All @@ -128,17 +151,18 @@ async fn message_io(

result = read.next() => match result {
Some(res) => {
println!("Read: {:?}", res);
if let Err(_) = in_send.send(res?) {
break
let msg = res?;
if msg.name != "_Heartbeat" {
if let Err(_) = in_send.send(msg) {
break
}
}
}
None => return Err(std::io::Error::from(std::io::ErrorKind::BrokenPipe))
}
}
}

println!("Disconnecting");
write_half
.write_all(&pack_message(Message {
name: "_Disconnect".to_string(),
Expand All @@ -156,15 +180,17 @@ pub struct MessengerClient {
}

impl MessengerClient {
pub async fn new(addr: String, name: String) -> Self {
pub fn new(addr: String, name: String) -> Self {
let (in_send, in_recv) = mpsc::unbounded_channel();
let (out_send, mut out_recv) = mpsc::unbounded_channel();
let io_join = tokio::spawn(async move {
let mut listening = vec![];

loop {
match message_io(&addr, &name, &in_send, &mut out_recv).await {
match message_io(&addr, &name, &in_send, &mut out_recv, &mut listening).await {
// Ok indicates client disconnected cleanly
Ok(_) => break,
Err(e) => println!("Connection failed: {}", e),
Err(e) => println!("Messenger connection failed: {}", e),
}

tokio::time::sleep(Duration::from_secs(1)).await;
Expand All @@ -178,14 +204,51 @@ impl MessengerClient {
}
}

pub fn listen(&mut self, name: &str) {
let _ = self.out_send.send(ToIoCmd::Listen(name.to_string()));
}

pub fn listen_multiple(&mut self, names: Vec<&str>) {
for name in names {
self.listen(name);
}
}

pub fn send_message(&mut self, msg: Message) {
let _ = self.out_send.send(ToIoCmd::SendMessage(msg));
}

pub fn send_empty(&mut self, name: &str) {
self.send_message(Message {
name: name.to_string(),
data: Bytes::new(),
});
}

pub fn poll_recv_message(&mut self) -> Option<Message> {
self.in_recv.try_recv().ok()
}

/// Gets all available incoming messages immediately if any are available,
/// otherwise waits for one to arrive
pub async fn poll_or_await_messages(&mut self) -> Vec<Message> {
match self.poll_recv_message() {
Some(msg) => {
let mut messages = vec![msg];
loop {
match self.poll_recv_message() {
Some(m) => messages.push(m),
None => return messages,
}
}
}
None => match self.in_recv.recv().await {
Some(m) => vec![m],
None => vec![],
},
}
}

pub async fn disconnect(self) {
match self.out_send.send(ToIoCmd::Disconnect) {
Ok(_) => {
Expand Down
Loading