@@ -129,6 +129,30 @@ impl DynamixelProtocolHandler {
129129 }
130130 }
131131
132+ /// Factory reset instruction.
133+ ///
134+ /// Reset the Control Table of DYNAMIXEL to the factory default values.
135+ /// Please note that conserving ID and/or Baudrate is only supported on protocol v2.
136+ pub fn factory_reset (
137+ & self ,
138+ serial_port : & mut dyn serialport:: SerialPort ,
139+ id : u8 ,
140+ conserve_id_only : bool ,
141+ conserve_id_and_baudrate : bool ,
142+ ) -> Result < ( ) > {
143+ match & self . protocol {
144+ ProtocolKind :: V1 ( p) => {
145+ if conserve_id_only || conserve_id_and_baudrate {
146+ return Err ( Box :: new ( CommunicationErrorKind :: Unsupported ) ) ;
147+ }
148+ p. factory_reset ( serial_port, id, conserve_id_only, conserve_id_and_baudrate)
149+ }
150+ ProtocolKind :: V2 ( p) => {
151+ p. factory_reset ( serial_port, id, conserve_id_only, conserve_id_and_baudrate)
152+ }
153+ }
154+ }
155+
132156 /// Reads raw register bytes.
133157 ///
134158 /// Sends a read instruction to the motor and wait for the status packet in response.
@@ -350,6 +374,20 @@ trait Protocol<P: Packet> {
350374 Ok ( self . read_status_packet ( port, id) . is_ok ( ) )
351375 }
352376
377+ fn factory_reset (
378+ & self ,
379+ port : & mut dyn SerialPort ,
380+ id : u8 ,
381+ conserve_id_only : bool ,
382+ conserve_id_and_baudrate : bool ,
383+ ) -> Result < ( ) > {
384+ self . send_instruction_packet (
385+ port,
386+ P :: factory_reset_packet ( id, conserve_id_only, conserve_id_and_baudrate) . as_ref ( ) ,
387+ ) ?;
388+ self . read_status_packet ( port, id) . map ( |_| ( ) )
389+ }
390+
353391 fn read ( & self , port : & mut dyn SerialPort , id : u8 , addr : u8 , length : u8 ) -> Result < Vec < u8 > > {
354392 self . send_instruction_packet ( port, P :: read_packet ( id, addr, length) . as_ref ( ) ) ?;
355393 self . read_status_packet ( port, id)
0 commit comments