Skip to content

Commit b7ee34f

Browse files
committed
feat(gui): split electrical and mechanical angle to different plots
1 parent ace45d6 commit b7ee34f

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

gui/gui/src/main.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Behaviour {
5252
return;
5353
};
5454

55-
self.motor_state.electrical_angle_rad =
55+
self.motor_state.mechanical_angle_rad =
5656
device.encoder_angle().unwrap() as f32 / 2f32.powi(14);
5757
}
5858
}
@@ -70,6 +70,7 @@ struct MotorState {
7070
rotating_setpoint: Pos2,
7171
two_phase_setpoint: Pos2,
7272
three_phase_setpoint: [f32; 3],
73+
mechanical_angle_rad: f32,
7374
electrical_angle_rad: f32,
7475
angular_vel_radps: f32,
7576
last_time: Instant,
@@ -299,6 +300,22 @@ fn display_graph(ui: &mut egui::Ui, state: &mut MotorState) {
299300
});
300301
});
301302

303+
// Draw mechanical angle
304+
egui::Window::new("Mechanical Angle")
305+
.collapsible(false)
306+
.fixed_pos(ui.min_rect().left_top() + vec2(100., 400.))
307+
.resizable(false)
308+
.frame(window_frame)
309+
.show(ui.ctx(), |ui| {
310+
ui.add(widgets::AnglePlot::new(&mut state.mechanical_angle_rad).settable(false));
311+
ui.horizontal(|ui| {
312+
ui.label(format!(
313+
"Angle: {:.3}°",
314+
state.mechanical_angle_rad.to_degrees()
315+
));
316+
});
317+
});
318+
302319
// Draw electrical angle
303320
egui::Window::new("Electrical Angle")
304321
.collapsible(false)
@@ -346,6 +363,7 @@ fn main() -> Result<(), eframe::Error> {
346363
rotating_setpoint: Pos2::ZERO,
347364
two_phase_setpoint: Pos2::ZERO,
348365
three_phase_setpoint: [0.; 3],
366+
mechanical_angle_rad: 0.,
349367
electrical_angle_rad: 0.,
350368
angular_vel_radps: 0.,
351369
last_time: Instant::now(),

0 commit comments

Comments
 (0)