13#ifndef DYNAMIXEL_TYPES_HPP
14#define DYNAMIXEL_TYPES_HPP
22#include "dynamixel_version.h"
39enum class [[nodiscard]]
Error : uint8_t {
72 return "NotInitialized";
74 return "InvalidArgument";
80 return "DeviceIdMismatch";
92 return "InvalidReply";
94 return "EchoMismatch";
98 return "NotPermitted";
118 [[nodiscard]]
constexpr bool ok() const noexcept {
119 return error == Error::Ok;
122 constexpr explicit operator bool() const noexcept {
132 return {v, Error::Ok};
150 [[nodiscard]]
constexpr bool ok() const noexcept {
151 return error == Error::Ok;
154 constexpr explicit operator bool() const noexcept {
415 c.gap_timeout_us = 2'000;
426 c.gap_timeout_us = 40'000;
476 const bool enums_ok =
477 detail::IsEnumerator(config.protocol) && detail::IsEnumerator(config.echo) &&
478 detail::IsEnumerator(config.alert_policy) && detail::IsEnumerator(config.status_return);
479 const bool baud_ok = (config.baud >=
kMinBaud) && (config.baud <=
kMaxBaud);
480 const bool timeouts_ok =
484 const bool waits_ok =
486 const bool retries_ok = config.retries <=
kMaxRetries;
487 return (enums_ok && baud_ok && timeouts_ok && waits_ok && retries_ok) ?
Error::Ok
507 info.error_byte = error_byte;
508 const auto bits =
static_cast<uint32_t
>(error_byte);
511 info.rejected = (bits & 0x7FU) != 0U;
526 const uint32_t number =
static_cast<uint32_t
>(error_byte) & 0x7FU;
562 [[nodiscard]]
constexpr const Config&
Get() const& noexcept {
566 void Get() const&& = delete;
574 return DYNAMIXEL_VERSION_STRING;
578 return DYNAMIXEL_VERSION_MAJOR;
582 return DYNAMIXEL_VERSION_MINOR;
586 return DYNAMIXEL_VERSION_PATCH;
A configuration proven valid at build time.
Definition dynamixel_types.hpp:550
consteval CheckedConfig(const Config &config) noexcept
Check config at build time.
Definition dynamixel_types.hpp:556
constexpr const Config & Get() const &noexcept
Definition dynamixel_types.hpp:562
void Get() const &&=delete
Not on a temporary: the reference would dangle (KB-CPP20-044).
Compile-time helpers of the DYNAMIXEL driver: typed integer literals, exact hook matching,...
Control tables of the DYNAMIXEL servo families, the model catalogue and the unit scales.
constexpr uint8_t kMaxIdV1
The largest valid servo ID of protocol 1.0.
Definition dynamixel_types.hpp:363
constexpr uint32_t kMaxSettleUs
Longest settle time after a reboot or factory reset the driver accepts: 10 seconds.
Definition dynamixel_types.hpp:370
constexpr Error Validate(const Config &config) noexcept
Check a configuration without touching the bus.
Definition dynamixel_types.hpp:475
void ConfigIsInvalid() noexcept
Reached only when a CheckedConfig is built from an invalid configuration: it is never defined,...
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition dynamixel_types.hpp:67
ClearOption
The option of a Clear instruction (protocol 2.0).
Definition dynamixel_types.hpp:216
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition dynamixel_types.hpp:581
constexpr const char * GetDriverVersion() noexcept
Definition dynamixel_types.hpp:573
constexpr uint8_t kMaxRetries
The most repeats of an idempotent instruction Config::retries allows.
Definition dynamixel_types.hpp:377
constexpr uint32_t kMaxBaud
Highest bit rate the driver accepts (the e-Manual lists up to 4.5 Mbit/s, the P series 10....
Definition dynamixel_types.hpp:375
constexpr Protocol2Error ErrorNumber(uint8_t error_byte) noexcept
The protocol 2.0 error number of an error byte.
Definition dynamixel_types.hpp:525
constexpr Config LegacyBusPreset() noexcept
The legacy bus: protocol 1.0 at 1 Mbit/s with the single-wire loopback of a half-duplex adapter.
Definition dynamixel_types.hpp:435
Protocol2Error
Protocol 2.0 error numbers (bits 6..0 of the error byte of a status packet).
Definition dynamixel_types.hpp:228
Protocol
The packet format of the bus: one per DYNAMIXEL object, because every servo on a bus shares it.
Definition dynamixel_types.hpp:182
constexpr uint32_t kMinTimeoutUs
Shortest and longest reply wait the driver accepts, microseconds (KB-CPP20-058).
Definition dynamixel_types.hpp:366
StatusReturn
How much a servo answers (the Status Return Level register, values 0 to 2).
Definition dynamixel_types.hpp:202
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition dynamixel_types.hpp:39
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition dynamixel_types.hpp:577
ResetOption
The option byte of a Factory Reset instruction (protocol 2.0).
Definition dynamixel_types.hpp:209
constexpr Config FastBusPreset() noexcept
Calls on a bus of servos that all answer: the shortest sensible setup for a first test.
Definition dynamixel_types.hpp:412
LogLevel
Severity passed to the optional Log() hook.
Definition dynamixel_types.hpp:173
constexpr uint8_t kAlertBit
Protocol 2.0 alert bit of the error byte.
Definition dynamixel_types.hpp:263
constexpr uint32_t kMaxTimeoutUs
Longest timeout the driver accepts: one second.
Definition dynamixel_types.hpp:368
EchoMode
Whether the transmitted bytes come back on the receive line (a single-wire loopback).
Definition dynamixel_types.hpp:189
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition dynamixel_types.hpp:585
constexpr uint8_t kMaxIdV2
The largest valid servo ID of protocol 2.0.
Definition dynamixel_types.hpp:361
constexpr uint8_t kBroadcastId
The broadcast ID: an instruction to it reaches every servo and none answers.
Definition dynamixel_types.hpp:359
BackupOption
The option of a Control Table Backup instruction (protocol 2.0).
Definition dynamixel_types.hpp:222
constexpr Config UsbAdapterPreset() noexcept
A bus on a USB adapter whose receive buffer is flushed in 16 ms steps.
Definition dynamixel_types.hpp:423
constexpr uint32_t kMinBaud
Lowest and highest bit rate the driver accepts for Config::baud.
Definition dynamixel_types.hpp:372
constexpr ReplyInfo Classify(Protocol protocol, uint8_t id, uint8_t error_byte) noexcept
Decode the error byte of a status packet.
Definition dynamixel_types.hpp:504
AlertPolicy
What a reply with a hardware alert means for the call.
Definition dynamixel_types.hpp:195
@ Errors
Clear registered errors (Y series only in the e-Manual).
@ MultiTurn
Reset the present position to one turn (0 to 4095); only while stopped.
@ DataLimitError
The value is outside a configured limit.
@ ResultFail
The instruction could not be processed.
@ DataRangeError
The value is outside the register's range.
@ CrcError
The servo's CRC check of the instruction failed.
@ DataLengthError
The data is shorter than the register.
@ InstructionError
Undefined instruction, or Action without a Reg Write.
@ AccessError
Read-only, write-only or undefined address, or an EEPROM write with torque on.
@ V1
Protocol 1.0: header FF FF, one-byte length, additive checksum, error flags.
@ PingOnly
Only ping instructions are answered.
@ All
Every instruction addressed to one servo is answered. Factory default.
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ DeviceIdMismatch
The reply came from another ID than the one addressed, or the model differs.
@ Crc
The CRC-16 (protocol 2.0) or checksum (protocol 1.0) of a reply did not match.
@ Bus
A port hook returned false.
@ InvalidReply
A reply the protocol refuses: header, length, instruction or parameter count.
@ DeviceFault
The servo reported a hardware alert and AlertPolicy::Fail is set.
@ NotInitialized
EnsureInitialized() has not succeeded, or Deinitialize() ran since.
@ EchoMismatch
The transmitted bytes were not read back as sent (collision or wiring).
@ Unsupported
The hook, protocol or family does not offer this call.
@ NotPermitted
A destructive instruction without Config::allow_destructive.
@ DeviceError
The servo rejected the instruction: see GetLastReply() for the error number.
@ Timeout
No complete reply within the deadline (nothing, or a truncated packet).
@ LineFault
The line carried only 0x00 or only 0xFF: stuck low, stuck high or floating.
@ Busy
Reserved by the shared set; this driver has no pending state.
@ KeepIdAndBaud
Reset all except ID and baud rate.
@ KeepId
Reset all except ID.
@ Warning
Something unexpected that the driver recovered from.
@ Info
Lifecycle events: initialised, resynchronised.
@ Debug
Detail for bring-up.
@ Loopback
TX and RX are tied: every sent byte is read back and compared.
@ None
Separate lines or a direction-controlled transceiver: nothing is echoed.
@ Restore
Restore the EEPROM from the backup; the servo reboots.
@ Store
Store the control table in the backup area (torque must be off).
@ Fail
The call returns DeviceFault and discards the data; the alert is latched too.
constexpr uint8_t kInputVoltage
Input voltage out of range.
Definition dynamixel_types.hpp:268
constexpr uint8_t kOverheating
Temperature above the limit.
Definition dynamixel_types.hpp:269
constexpr uint8_t kMotorEncoder
Motor encoder malfunction (X430, X540, MX(2.0)).
Definition dynamixel_types.hpp:270
constexpr uint8_t kOverload
Persistent load above the maximum output.
Definition dynamixel_types.hpp:272
constexpr uint8_t kElectricalShock
Electrical shock or too little power.
Definition dynamixel_types.hpp:271
constexpr uint8_t kAngleLimit
Goal position outside the angle limits (command fault).
Definition dynamixel_types.hpp:244
constexpr uint8_t kRange
An instruction value out of range (command fault).
Definition dynamixel_types.hpp:247
constexpr uint8_t kChecksum
The instruction's checksum was wrong (command fault).
Definition dynamixel_types.hpp:248
constexpr uint8_t kOverload
Load beyond what the torque limit controls (condition).
Definition dynamixel_types.hpp:250
constexpr uint8_t kInputVoltage
Input voltage out of the configured range (condition).
Definition dynamixel_types.hpp:242
constexpr uint8_t kCommandFaults
Flags that mean the instruction was not carried out.
Definition dynamixel_types.hpp:255
constexpr uint8_t kOverheating
Internal temperature above the limit (condition).
Definition dynamixel_types.hpp:246
constexpr uint8_t kInstruction
Definition dynamixel_types.hpp:252
constexpr uint8_t kConditions
Flags that report the servo's condition, not the instruction.
Definition dynamixel_types.hpp:258
The DYNAMIXEL driver: everything it declares lives here; internals in detail.
Definition dynamixel.hpp:35
@ ReadOnly
R: a write is an access error.
Family
A servo family: one control table layout (several models share it).
Definition dynamixel_tables.hpp:30
@ Generic
Unknown or unlisted model: raw addresses only.
@ None
No baud register in the table (generic).
One device of a Bulk Read request.
Definition dynamixel_types.hpp:315
uint16_t address
First control-table address.
Definition dynamixel_types.hpp:317
uint16_t length
Bytes to read.
Definition dynamixel_types.hpp:318
One device of a Bulk Write request.
Definition dynamixel_types.hpp:322
uint16_t address
First control-table address.
Definition dynamixel_types.hpp:324
std::span< const uint8_t > data
The bytes to write there (at least one).
Definition dynamixel_types.hpp:325
Everything the driver needs to know about the bus.
Definition dynamixel_types.hpp:385
uint32_t baud
Bit rate of the UART; applied through SetBaudRate() when the port has it.
Definition dynamixel_types.hpp:387
bool allow_destructive
Permit Factory Reset, Backup Restore and writes to the ID with broadcast.
Definition dynamixel_types.hpp:404
uint32_t baud_change_wait_us
Wait after a servo's baud rate changed.
Definition dynamixel_types.hpp:394
EchoMode echo
Single-wire loopback verification.
Definition dynamixel_types.hpp:397
AlertPolicy alert_policy
What a hardware alert in a reply does to the call.
Definition dynamixel_types.hpp:398
uint8_t retries
Repeats of a ping or read after a bad or missing reply, 0 to kMaxRetries.
Definition dynamixel_types.hpp:395
uint32_t reboot_wait_us
Definition dynamixel_types.hpp:392
Protocol protocol
Packet format of every servo on the bus.
Definition dynamixel_types.hpp:386
uint32_t reply_timeout_us
Longest wait for the first byte of a reply (kMinTimeoutUs to kMaxTimeoutUs).
Definition dynamixel_types.hpp:389
StatusReturn status_return
How much the servos answer (applies to the whole bus).
Definition dynamixel_types.hpp:400
uint32_t broadcast_timeout_us
Wait for each reply of a broadcast ping (the servos answer in ID order).
Definition dynamixel_types.hpp:402
uint32_t gap_timeout_us
Longest wait for the next byte inside a packet.
Definition dynamixel_types.hpp:391
The per-device outcome of a Sync Read, Bulk Read or Fast read.
Definition dynamixel_types.hpp:307
bool alert
The alert or condition flag of this device's error byte.
Definition dynamixel_types.hpp:311
uint8_t error_byte
The raw error byte when a packet arrived.
Definition dynamixel_types.hpp:310
Error result
Ok, or why this device's data is not valid.
Definition dynamixel_types.hpp:309
Position, velocity, effort, voltage and temperature of a servo, read in one transfer.
Definition dynamixel_types.hpp:329
uint16_t voltage_dv
Input voltage in 0.1 V.
Definition dynamixel_types.hpp:341
int32_t velocity
Present Velocity (or Speed) in counts (Info(family).mrpm_per_count).
Definition dynamixel_types.hpp:338
EffortKind
What effort holds.
Definition dynamixel_types.hpp:331
@ LoadPermille
Present Load in 0.1 percent of the maximum torque (signed: negative is clockwise).
@ None
The family has neither load nor current.
@ CurrentCounts
Present Current in the model's unit (ModelInfo::current_ua).
EffortKind effort_kind
Meaning of effort.
Definition dynamixel_types.hpp:340
int32_t effort
Present Load or Present Current, see effort_kind.
Definition dynamixel_types.hpp:339
int32_t position
Present Position in counts.
Definition dynamixel_types.hpp:337
uint8_t temperature_c
Internal temperature in degrees Celsius.
Definition dynamixel_types.hpp:342
The identity a ping returns.
Definition dynamixel_types.hpp:291
uint8_t firmware
Firmware Version register.
Definition dynamixel_types.hpp:294
Family family
The control table family of model (Generic when unlisted).
Definition dynamixel_types.hpp:295
uint16_t model
Model Number register.
Definition dynamixel_types.hpp:293
An error byte, decoded.
Definition dynamixel_types.hpp:282
bool rejected
Definition dynamixel_types.hpp:286
bool alert
Protocol 2.0 alert bit, or a protocol 1.0 condition flag.
Definition dynamixel_types.hpp:285
uint8_t error_byte
The raw error byte of the status packet.
Definition dynamixel_types.hpp:284
uint8_t id
The ID the reply came from; the first device for a broadcast ping.
Definition dynamixel_types.hpp:283
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition dynamixel_types.hpp:167
static constexpr Result Success() noexcept
Definition dynamixel_types.hpp:159
constexpr bool ok() const noexcept
Definition dynamixel_types.hpp:150
The value of a call, or why there is none.
Definition dynamixel_types.hpp:113
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition dynamixel_types.hpp:139
static constexpr Result Success(T v) noexcept
A successful result.
Definition dynamixel_types.hpp:131
constexpr bool ok() const noexcept
Definition dynamixel_types.hpp:118
A servo on the bus: its ID and its control-table family.
Definition dynamixel_types.hpp:300
Family family
Selects the typed registers; Generic allows raw addresses only.
Definition dynamixel_types.hpp:302
What the driver counted since ResetStats().
Definition dynamixel_types.hpp:346
uint32_t timeouts
Replies that did not arrive in time.
Definition dynamixel_types.hpp:349
uint32_t retries
Repeats of an idempotent instruction after a bad or missing reply.
Definition dynamixel_types.hpp:348
uint32_t transactions
Instruction packets sent.
Definition dynamixel_types.hpp:347
uint32_t device_errors
Status packets with a rejecting error byte.
Definition dynamixel_types.hpp:354
uint32_t crc_errors
Packets dropped for a wrong CRC or checksum.
Definition dynamixel_types.hpp:350
uint32_t echo_errors
Loopback echoes that differed.
Definition dynamixel_types.hpp:353
uint32_t alerts
Status packets with an alert or condition flag.
Definition dynamixel_types.hpp:355
uint32_t garbage_bytes
Received bytes skipped while looking for a header.
Definition dynamixel_types.hpp:351
uint32_t line_faults
Stuck or floating line detections.
Definition dynamixel_types.hpp:352