Skip to main content

ServoDefinition

Struct ServoDefinition 

Source
pub struct ServoDefinition {
    pub name: &'static str,
    pub protocol: u8,
    pub info: ServoInfo,
    pub registers: &'static [RegisterInfo],
    pub models: &'static [(&'static str, u16)],
}
Expand description

A servo definition as a value: its name, the protocol it speaks, what it states about itself and its registers.

Every servo module has its own as DEFINITION; on Python, the static definition() of each controller class returns it.

Fields§

§name: &'static str§protocol: u8

The Dynamixel protocol version the servo speaks: 1 or 2.

§info: ServoInfo§registers: &'static [RegisterInfo]§models: &'static [(&'static str, u16)]

The servo models this definition covers, as (name, model number).

Implementations§

Source§

impl ServoDefinition

Source

pub fn register(&self, name: &str) -> Option<RegisterInfo>

Look up a register by name, as spelled in registers.

Source

pub fn read_register( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, id: u8, name: &str, ) -> Result<i64, Box<dyn Error>>

Read register name of motor id as an integer, decoded from this definition’s word order and the register’s sign encoding.

Source

pub fn read_register_with_error( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, id: u8, name: &str, ) -> Result<(i64, StatusError), Box<dyn Error>>

Same as read_register, plus the status packet’s error field.

Source

pub fn write_register( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, id: u8, name: &str, value: i64, ) -> Result<(), Box<dyn Error>>

Write value to register name of motor id, laid out in this definition’s word order and the register’s sign encoding. A value that does not fit the register fails before anything reaches the bus.

Source

pub fn write_register_with_error( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, id: u8, name: &str, value: i64, ) -> Result<StatusError, Box<dyn Error>>

Same as write_register, plus the status packet’s error field.

Source

pub fn sync_read_register( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, ids: &[u8], name: &str, ) -> Result<Vec<i64>, Box<dyn Error>>

Sync read register name from ids, each value decoded like read_register.

A servo whose firmware has no Sync Read (supports_sync_read false: the Feetech SCS series) is read one id at a time instead, in the order asked. The values come back the same way, but from one transaction per id rather than one for the bus.

Source

pub fn sync_read_register_with_error( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, ids: &[u8], name: &str, ) -> Result<Vec<(i64, StatusError)>, Box<dyn Error>>

Same as sync_read_register, plus each motor’s error field.

Source

pub fn sync_write_register( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, ids: &[u8], name: &str, values: &[i64], ) -> Result<(), Box<dyn Error>>

Sync write values to register name of ids, one value per id, each encoded like write_register.

Source

pub fn scan( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, ids: &[u8], ) -> Result<BTreeMap<u8, u16>, Box<dyn Error>>

Which of ids answer, with their model number read as this definition lays it out.

One Model Number read per id, so presence and identity cost a single round trip. An absent id costs a timeout, so the sweep runs under one sized to the baud rate, see scan_timeout, and puts the port’s timeout back afterwards. An id that answers with anything the protocol cannot parse counts as absent.

Source

pub fn broadcast_scan( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, ids: &[u8], ) -> Result<BTreeMap<u8, u16>, Box<dyn Error>>

Which of ids answer, with their model number read as this definition lays it out: one broadcast ping, then a Model Number read of each id asked that answered, under the port’s own timeout.

The ping listens for its whole window however few ids are asked (broadcast_ping_window, about 0.8 s at 1 Mbps), so this pays off over many ids, where scan costs a timeout per absent id, and behind a USB adapter whose latency timer outlasts the short timeout scan uses. A servo that does not answer a broadcast ping (supports_broadcast_ping) is refused before anything is sent.

Source

pub fn change_id( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, id: u8, new_id: u8, ) -> Result<(), Box<dyn Error>>

Give motor id the id new_id.

The id is kept in EEPROM, which a motor only writes with its torque off, and a Feetech motor only with its lock open: both are done first, and left that way. The motor answers the write from its old id; an answer refusing it fails with a StatusPacketError.

Source

pub fn change_baudrate( &self, dph: &DynamixelProtocolHandler, port: &mut dyn SerialPort, id: u8, baudrate: u32, ) -> Result<(), Box<dyn Error>>

Set motor id to talk at baudrate, one of the rates in this definition’s baudrates, written as the value its baud rate register takes for it.

The EEPROM is opened first, as for change_id. The motor answers the write at its old rate, then switches; port stays at the old rate, so switch it too (set_baud_rate) to keep talking to the motor.

Source

pub fn refuses(&self, status: StatusError) -> bool

Whether status, the error field of an answer, says the servo refused the instruction: an error number on protocol v2, an instruction, checksum or range error on protocol v1, never on a servo whose status only reports alarms. The other bits are conditions the motor reports while it carries the instruction out, as an overload or the v2 alert bit.

Trait Implementations§

Source§

impl Clone for ServoDefinition

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ServoDefinition

Source§

impl Debug for ServoDefinition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ServoDefinition

Source§

impl Hash for ServoDefinition

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ServoDefinition

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ServoDefinition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.