From 219f461aaf98227e10e005e5ad3babba30ba2621 Mon Sep 17 00:00:00 2001 From: Pierre Rouanet Date: Fri, 18 Aug 2023 14:52:48 +0200 Subject: [PATCH] Update multiple_motors_controller.rs --- src/multiple_motors_controller.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/multiple_motors_controller.rs b/src/multiple_motors_controller.rs index d949d05..5b896a2 100644 --- a/src/multiple_motors_controller.rs +++ b/src/multiple_motors_controller.rs @@ -1,6 +1,9 @@ use crate::{coherency::CoherentResult, motor_controller::Result, MotorController, PID}; pub trait MultipleMotorsController { + /// Name of the controller (used for Debug trait) + fn name(&self) -> &'static str; + /// Check if the motor is ON or OFF fn is_torque_on(&self) -> Result; /// Enable/Disable the torque @@ -50,6 +53,14 @@ pub trait MultipleMotorsController { fn set_pid_gains(&mut self, pid: [PID; N]) -> Result<()>; } +impl std::fmt::Debug for dyn MultipleMotorsController { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("MultipleMotorsController") + .field("name", &self.name()) + .finish() + } +} + #[derive(Debug)] pub struct MultipleMotorsControllerWrapper { controllers: [Box; N], @@ -62,6 +73,10 @@ impl MultipleMotorsControllerWrapper { } impl MultipleMotorsController for MultipleMotorsControllerWrapper { + fn name(&self) -> &'static str { + "MultipleMotorsController" + } + fn is_torque_on(&self) -> Result { self.controllers.iter().map(|c| c.is_torque_on()).coherent() }