Clubmax to config

This commit is contained in:
Ruben van de Ven 2025-05-26 20:20:40 +02:00
parent f2bb4f5f92
commit 3e3975eb43
2 changed files with 49 additions and 8 deletions

View file

@ -4,7 +4,7 @@
use bevy::math::Mat3; use bevy::math::Mat3;
use bevy_nannou::prelude::DARK_GRAY; use bevy_nannou::prelude::DARK_GRAY;
use nannou::lyon::geom::euclid::Transform2D; // use nannou::lyon::geom::euclid::Transform2D;
use nannou::{geom::Rect, math::map_range as nannou_map_range}; use nannou::{geom::Rect, math::map_range as nannou_map_range};
use nannou::prelude::*; use nannou::prelude::*;
use nannou_egui::{self, egui, Egui}; use nannou_egui::{self, egui, Egui};
@ -12,6 +12,7 @@ use nannou_laser::DacId;
use nannou_laser::{self as laser, util::map_range}; use nannou_laser::{self as laser, util::map_range};
use serde_json::Result; use serde_json::Result;
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
use trap_rust::trap::laser::TMP_DESK_CLUBMAX;
use trap_rust::trap::tracks::CoordinateSpace; use trap_rust::trap::tracks::CoordinateSpace;
use trap_rust::trap::{laser::{apply_homography_matrix, python_cv_h_into_mat3, LaserModel, TMP_PYTHON_LASER_H, DacConfig}, tracks::{LaserPoints, RenderableLines}}; use trap_rust::trap::{laser::{apply_homography_matrix, python_cv_h_into_mat3, LaserModel, TMP_PYTHON_LASER_H, DacConfig}, tracks::{LaserPoints, RenderableLines}};
use zmq::Socket; use zmq::Socket;
@ -44,6 +45,8 @@ struct Model {
// dimming_factor: f32, // dimming_factor: f32,
lost_alpha: f32, lost_alpha: f32,
connected: bool, connected: bool,
// canvas_transform: Translation2D<f32, ScreenSpace, ScreenSpace>,
// dragging: bool,
} }
struct LaserSettings { struct LaserSettings {
@ -63,12 +66,12 @@ impl Default for LaserSettings {
use laser::stream; use laser::stream;
use laser::stream::frame::InterpolationConfig; use laser::stream::frame::InterpolationConfig;
LaserSettings { LaserSettings {
point_hz: 8000, //stream::DEFAULT_POINT_HZ, point_hz: 30000, //stream::DEFAULT_POINT_HZ,
latency_points: stream::points_per_frame( latency_points: stream::points_per_frame(
stream::DEFAULT_POINT_HZ, stream::DEFAULT_POINT_HZ,
stream::DEFAULT_FRAME_HZ, stream::DEFAULT_FRAME_HZ,
), ) * 4,
frame_hz: 55, //stream::DEFAULT_FRAME_HZ, frame_hz: 35, //stream::DEFAULT_FRAME_HZ,
enable_optimisations: true, enable_optimisations: true,
distance_per_point: InterpolationConfig::DEFAULT_DISTANCE_PER_POINT, distance_per_point: InterpolationConfig::DEFAULT_DISTANCE_PER_POINT,
blank_delay_points: InterpolationConfig::DEFAULT_BLANK_DELAY_POINTS, blank_delay_points: InterpolationConfig::DEFAULT_BLANK_DELAY_POINTS,
@ -181,6 +184,22 @@ fn get_dac_configs() -> DacConfigMap{
homography: python_cv_h_into_mat3(TMP_PYTHON_LASER_H) homography: python_cv_h_into_mat3(TMP_PYTHON_LASER_H)
} }
); );
dac_configs.insert(
DacId::EtherDream {
mac_address: [
122,
39,
223,
73,
5,
227,
],
},
DacConfig{
name: "ED - 192.168.8.101".into(),
homography: python_cv_h_into_mat3(TMP_DESK_CLUBMAX)
}
);
dac_configs dac_configs
} }
@ -199,6 +218,7 @@ fn model(app: &App) -> Model {
.new_window() .new_window()
.size(1024, 768) .size(1024, 768)
// .key_pressed(key_pressed) // .key_pressed(key_pressed)
// .mouse_wheel(canvas_zoom)
.view(view_line_canvas) .view(view_line_canvas)
.build() .build()
.unwrap(); .unwrap();
@ -277,7 +297,8 @@ fn model(app: &App) -> Model {
last_update: Instant::now(), last_update: Instant::now(),
lost_alpha: 1., lost_alpha: 1.,
connected: true, connected: true,
per_laser_config: get_dac_configs() per_laser_config: get_dac_configs(),
// canvas_transform: Transform2D
// dimming_factor: 1., // dimming_factor: 1.,
} }
} }
@ -326,7 +347,7 @@ fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){
const LASER_MIN: f32 = -1.0; const LASER_MIN: f32 = -1.0;
const LASER_MAX: f32 = 1.0; const LASER_MAX: f32 = 1.0;
if position[0] < LASER_MIN || position[0] > LASER_MAX || position[1] < LASER_MIN || position[1] > LASER_MAX{ if position[0] < LASER_MIN || position[0] > LASER_MAX || position[1] < LASER_MIN || position[1] > LASER_MAX{
// TODO apply previous point, as blanked (or formally, lerp to edge) // TODO: apply previous point, as blanked (or formally, lerp to edge)
continue; continue;
} }
@ -345,6 +366,7 @@ fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){
new_points.push(new_point); new_points.push(new_point);
} }
// dbg!(&new_points);
if new_points.len() < pointno { if new_points.len() < pointno {
println!("Cropped Points {} (was: {})", new_points.len(), pointno); println!("Cropped Points {} (was: {})", new_points.len(), pointno);
@ -580,7 +602,7 @@ fn view_line_canvas(app: &App, model: &Model, frame: Frame) {
let scale = 25.; let scale = 25.;
let translate_x = -300.; let translate_x = -300.;
let translate_y = -100.; let translate_y = 100.;
@ -685,3 +707,16 @@ fn style() -> egui::Style {
style.visuals.widgets.noninteractive.fg_stroke.color = egui::Color32::WHITE; style.visuals.widgets.noninteractive.fg_stroke.color = egui::Color32::WHITE;
style style
} }
fn mouse_moved(_app: &App, _model: &mut Model, _pos: Point2) {
}
fn mouse_pressed(_app: &App, _model: &mut Model, _button: MouseButton) {
// _model.dragging
}
fn mouse_released(_app: &App, _model: &mut Model, _button: MouseButton) {}
fn mouse_wheel(_app: &App, _model: &mut Model, _dt: MouseScrollDelta, _phase: TouchPhase) {
// canvas zoom
}

View file

@ -4,6 +4,7 @@ use std::time::Instant;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::tracks::{LaserPoints, RenderableLines}; use super::tracks::{LaserPoints, RenderableLines};
// homography for laserworld in studio
pub const TMP_PYTHON_LASER_H: [[f32;3];3] = [[ 2.47442963e+02, -7.01714050e+01, -9.71749119e+01], pub const TMP_PYTHON_LASER_H: [[f32;3];3] = [[ 2.47442963e+02, -7.01714050e+01, -9.71749119e+01],
[ 1.02328119e+01, 1.47185254e+02, 1.96295638e+02], [ 1.02328119e+01, 1.47185254e+02, 1.96295638e+02],
[-1.20921986e-03, -3.32735973e-02, 1.00000000e+00]]; [-1.20921986e-03, -3.32735973e-02, 1.00000000e+00]];
@ -12,6 +13,10 @@ pub const TMP_PYTHON_LASER_H_FOR_NANNOU: [[f32;3]; 3] = [[ 2.47442963e+02/0xFFF
[ 1.02328119e+01, 1.47185254e+02/0xFFF as f32, 1.96295638e+02], [ 1.02328119e+01, 1.47185254e+02/0xFFF as f32, 1.96295638e+02],
[-1.20921986e-03, -3.32735973e-02, 1.00000000e+00]]; [-1.20921986e-03, -3.32735973e-02, 1.00000000e+00]];
// pub const TMP_DESK_CLUBMAX: [[f32; 3];3] = [[0.003018943396859696, -0.002188214018866917, 4.477472619274084], [0.0006859845340564413, -0.007161248327764752, 18.904283109325856], [2.691266191666664e-05, -0.0002590919318146652, 1.0]];
pub const TMP_DESK_CLUBMAX: [[f32; 3];3] = [[112.4994944830643, -51.10450906207176, 462.38070124241983], [8.808883296848508, -144.0698004299043, 2684.09476106297], [-0.0007453502703082056, -0.035951964534732414, 1.0]];
pub const fn python_cv_h_into_mat3(m: [[f32;3]; 3]) -> Mat3{ pub const fn python_cv_h_into_mat3(m: [[f32;3]; 3]) -> Mat3{
Mat3::from_cols( Mat3::from_cols(
Vec3::new(m[0][0], m[1][0], m[2][0]), Vec3::new(m[0][0], m[1][0], m[2][0]),
@ -77,11 +82,12 @@ pub struct DacConfig{
} }
const LASER_H: Mat3 = python_cv_h_into_mat3(TMP_PYTHON_LASER_H); const LASER_H: Mat3 = python_cv_h_into_mat3(TMP_PYTHON_LASER_H);
const LASER_H_CM: Mat3 = python_cv_h_into_mat3(TMP_DESK_CLUBMAX);
impl Default for DacConfig{ impl Default for DacConfig{
fn default() -> DacConfig{ fn default() -> DacConfig{
//DacConfig { name: "Unknown".into(), homography: Mat3::IDENTITY } //DacConfig { name: "Unknown".into(), homography: Mat3::IDENTITY }
DacConfig { name: "Unknown".into(), homography: LASER_H } DacConfig { name: "Unknown".into(), homography: LASER_H_CM }
} }
} }