Receive renderablelines from python

This commit is contained in:
Ruben van de Ven 2025-04-11 19:03:47 +02:00
parent 483f021010
commit 0bd763ba5e
4 changed files with 48 additions and 10 deletions

File diff suppressed because one or more lines are too long

View file

@ -43,8 +43,8 @@ fn main() {
.add_plugins(ZmqPlugin { .add_plugins(ZmqPlugin {
// url: "tcp://localhost:5558".to_string(), // url: "tcp://localhost:5558".to_string(),
// url: "tcp://100.109.175.82:99173".to_string(), url: "tcp://100.109.175.82:99174".to_string(),
url: "tcp://127.0.0.1:99173".to_string(), // url: "tcp://127.0.0.1:99173".to_string(),
filter: "".to_string(), filter: "".to_string(),
target: ZmqReceiveTarget::LINES target: ZmqReceiveTarget::LINES
}) })

View file

@ -40,18 +40,18 @@ pub struct Track {
} }
// coordinates in world space. To be converted to laser::Point or a drawable point // coordinates in world space. To be converted to laser::Point or a drawable point
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RenderablePoint{ pub struct RenderablePoint{
pub position: Vec2, pub position: Vec2,
pub color: Color pub color: Srgba
} }
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RenderableLine{ pub struct RenderableLine{
points: Vec<RenderablePoint> points: Vec<RenderablePoint>
} }
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RenderableLines{ pub struct RenderableLines{
pub lines: Vec<RenderableLine> pub lines: Vec<RenderableLine>
} }
@ -88,7 +88,7 @@ impl From<&Track> for RenderableLines{
for position in track.history.iter() { for position in track.history.iter() {
points.push(RenderablePoint{ points.push(RenderablePoint{
position: position.clone(), position: position.clone(),
color: Color::linear_rgba(1.0, 0., 0., 1.0) color: Srgba::new(1.0, 0., 0., 1.0)
}); });
} }
lines.push(RenderableLine{points}) lines.push(RenderableLine{points})

View file

@ -1,7 +1,7 @@
use zmq::Socket; use zmq::Socket;
use serde_json::Result; use serde_json::Result;
use bevy::{ecs::system::SystemState, prelude::*, render::Render}; use bevy::{ecs::system::SystemState, prelude::*, render::Render};
use std::num::NonZero;
use super::{laser::{LaserApi, LaserTimer}, tracks::{Frame, LaserPoints, RenderableLines, Track, TrackBundle}}; use super::{laser::{LaserApi, LaserTimer}, tracks::{Frame, LaserPoints, RenderableLines, Track, TrackBundle}};
@ -46,7 +46,8 @@ fn setup_zmq(world: &mut World, params: &mut SystemState<Res<ZmqSettings>>) {
fn receive_zmq_lines( fn receive_zmq_lines(
subscriber: NonSend<Socket>, subscriber: NonSend<Socket>,
mut lasers: Query<(&mut LaserApi, &mut LaserTimer)>, mut lasers: Query<(&mut LaserApi, &mut LaserTimer)>,
time: Res<Time> time: Res<Time>,
mut exit: EventWriter<AppExit>
) { ) {
let mut items = [ let mut items = [
subscriber.as_poll_item(zmq::POLLIN) subscriber.as_poll_item(zmq::POLLIN)
@ -64,10 +65,15 @@ fn receive_zmq_lines(
Ok(lines) => lines, // if Ok(255), set x to 255 Ok(lines) => lines, // if Ok(255), set x to 255
Err(_e) => { Err(_e) => {
println!("No valid json? {json}"); println!("No valid json? {json}");
println!("{}", _e);
exit.send(AppExit::Error(NonZero::<u8>::new(10).unwrap()));
return return
}, // if Err("some message"), panic with error message "some message" }, // if Err("some message"), panic with error message "some message"
}; };
println!("receive {}", lines.lines.len());
for (laser_api, mut laser_timer) in lasers.iter_mut() { for (laser_api, mut laser_timer) in lasers.iter_mut() {
laser_timer.timer.tick(time.delta()); laser_timer.timer.tick(time.delta());
// let lines = get_laser_lines(version); // let lines = get_laser_lines(version);
@ -80,7 +86,7 @@ fn receive_zmq_lines(
} }
} }
fn receive_zmq_tracks(mut commands: Commands, subscriber: NonSend<Socket>, mut tracks_q: Query<&mut Track>) { fn receive_zmq_tracks(mut commands: Commands, subscriber: NonSend<Socket>, mut tracks_q: Query<&mut Track>, mut exit: EventWriter<AppExit>) {
let mut items = [ let mut items = [
subscriber.as_poll_item(zmq::POLLIN) subscriber.as_poll_item(zmq::POLLIN)
]; ];
@ -97,6 +103,7 @@ fn receive_zmq_tracks(mut commands: Commands, subscriber: NonSend<Socket>, mut t
Ok(msg) => msg, // if Ok(255), set x to 255 Ok(msg) => msg, // if Ok(255), set x to 255
Err(_e) => { Err(_e) => {
println!("No valid json? {json}"); println!("No valid json? {json}");
exit.send(AppExit::Error(NonZero::<u8>::new(10).unwrap()));
return return
}, // if Err("some message"), panic with error message "some message" }, // if Err("some message"), panic with error message "some message"
}; };