dynamixel2/instructions/factory_reset.rs
1use super::{instruction_id, packet_id};
2use crate::{Bus, Response};
3
4/// The kind of factory reset to perform.
5#[repr(u8)]
6#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
7pub enum FactoryResetKind {
8 /// Reset all settings, including the motor ID and baud rate.
9 ResetAll = 0xFF,
10
11 /// Reset all settings except for the motor ID.
12 KeepId = 0x01,
13
14 /// Reset all settings except for the motor ID and baud rate.
15 KeepIdAndBaudRate = 0x02,
16}
17
18impl<ReadBuffer, WriteBuffer> Bus<ReadBuffer, WriteBuffer>
19where
20 ReadBuffer: AsRef<[u8]> + AsMut<[u8]>,
21 WriteBuffer: AsRef<[u8]> + AsMut<[u8]>,
22{
23 /// Reset the settings of a motor to the factory defaults.
24 ///
25 /// This will reset all registers to the factory default, including the EEPROM registers.
26 /// The only exceptions are the ID and baud rate settings, which may be kept depending on the `kind` argument.
27 ///
28 /// You may specify [`crate::instructions::packet_id::BROADCAST`] as motor ID.
29 /// If you do, none of the devices will reply with a response, and this function will not wait for any.
30 ///
31 /// If you want to broadcast this instruction, it may be more convenient to use [`Self::broadcast_factory_reset()`] instead.
32 ///
33 /// Starting with version 42 of the firmware for the MX-series and X-series,
34 /// motors ignore a broadcast reset command with `FactoryResetKind::ResetAll`.
35 /// Motors with older firmware may still execute the command,
36 /// which would cause multiple motors on the bus to have the same ID.
37 /// At that point, communication with those motors is not possible anymore.
38 /// The only way to restore communication is to physically disconnect all but one motor at a time and re-assign unique IDs.
39 /// Or use the ID Inspection Tool in the Dynamixel Wizard 2.0
40 pub fn factory_reset(&mut self, motor_id: u8, kind: FactoryResetKind) -> Result<Response<()>, crate::TransferError> {
41 self.write_instruction(motor_id, instruction_id::FACTORY_RESET, 1, |buffer| buffer[0] = kind as u8)?;
42 Ok(super::read_response_if_not_broadcast(self, motor_id)?)
43 }
44
45 /// Reset the settings of all connected motors to the factory defaults.
46 ///
47 /// This will reset all registers to the factory default, including the EEPROM registers.
48 /// The only exceptions are the ID and baud rate settings, which may be kept depending on the `kind` argument.
49 ///
50 /// Starting with version 42 of the firmware for the MX-series and X-series,
51 /// motors ignore a broadcast reset command with `FactoryResetKind::ResetAll`.
52 /// Motors with older firmware may still execute the command,
53 /// which would cause multiple motors on the bus to have the same ID.
54 /// At that point, communication with those motors is not possible anymore.
55 /// The only way to restore communication is to physically disconnect all but one motor at a time and re-assign unique IDs.
56 pub fn broadcast_factory_reset(&mut self, kind: FactoryResetKind) -> Result<(), crate::WriteError> {
57 self.write_instruction(packet_id::BROADCAST, instruction_id::FACTORY_RESET, 1, |buffer| {
58 buffer[0] = kind as u8
59 })?;
60 Ok(())
61 }
62}