Group x430¶
Device-side emulation of DYNAMIXEL X430 actuators over Protocol 2.0: the firmware moves any motor, the host sees an X430-compatible device. More...
Modules¶
| Type | Name |
|---|---|
| module | Configuration Build-time configuration: Kconfig symbols or plain compiler definitions. |
| module | Definitions Status codes, options, events and the addresses, operating modes and bit fields of the X430 Control Table. |
| module | Model descriptor Types of the generated Control Table (one model per build). |
| module | Types Callbacks, configuration structures and the opaque instances. |
Public Attributes¶
| Type | Name |
|---|---|
| const struct x430_hooks | x430_sim_hooks Hooks implementing the simulated actuator: pass them with x430_device_config::user_data pointing at an initializedx430_sim . |
Public Functions¶
| Type | Name |
|---|---|
| int | x430_bus_attach (struct x430_bus * bus, struct x430_device * device) Attach an initialized device to an initialized bus. |
| int | x430_bus_find (const struct x430_bus * bus, uint8_t id, struct x430_device ** device) Attached device with the primary ID id (lock-free). |
| int | x430_bus_handle_packet (struct x430_bus * bus, const struct dxl2_packet * packet) Handle one decoded instruction packet, for applications that run their own DXL2-C link. |
| int | x430_bus_init (struct x430_bus * bus, const struct x430_bus_config * config) Initialize a bus. |
| int | x430_bus_lock (struct x430_bus * bus) Take the bus lock ( x430_port::lock ; nothing without it). |
| int | x430_bus_poll (struct x430_bus * bus) Periodic service: Bus Watchdog of every device. |
| int | x430_bus_receive (struct x430_bus * bus, const uint8_t * data, size_t length) Feed received bytes in any chunking; answers every complete instruction packet. |
| int | x430_bus_unlock (struct x430_bus * bus) Release the bus lock ( x430_port::unlock ). |
| int | x430_device_action (struct x430_device * device, uint8_t * error) ACTION: execute the registered write. |
| int | x430_device_backup (struct x430_device * device, uint8_t option, uint8_t * error) Control Table BACKUP: store, or restore with the torque off. |
| int | x430_device_clear (struct x430_device * device, uint8_t option, uint8_t * error) CLEAR with option X430_CLEAR_MULTI_TURN _(event_X430_EVENT_CLEAR_MULTI_TURN ). |
| int | x430_device_factory_reset (struct x430_device * device, uint8_t option, uint8_t * error) FACTORY_RESET, then like REBOOT; event X430_EVENT_FACTORY_RESET . |
| int | x430_device_flush_events (struct x430_device * device) Deliver deferred events ( X430_EVENT_BAUD_RATE ) after the status packet. |
| int | x430_device_get (const struct x430_device * device, uint16_t address, int32_t * value) Value of the register that starts at address (lock-free). |
| int | x430_device_id (const struct x430_device * device, uint8_t * id) Current ID (7) of the device (lock-free). |
| int | x430_device_init (struct x430_device * device, const struct x430_device_config * config) Initialize a device: factory values, stored EEPROM area (nvm_read), the RAM area and the Startup Configuration (which may call the write hook). |
| int | x430_device_raise_hardware_error (struct x430_device * device, uint8_t bits) Report hardware errors (Hardware Error Status bits, lock-free). |
| int | x430_device_read (struct x430_device * device, uint16_t address, uint16_t length, uint8_t * data, uint8_t * error) READ semantics: read hook, Indirect Data, Realtime Tick. |
| int | x430_device_reboot (struct x430_device * device) REBOOT: RAM area reset, errors cleared, Startup Configuration applied, event X430_EVENT_REBOOT . |
| int | x430_device_reg_write (struct x430_device * device, uint16_t address, uint16_t length, const uint8_t * data, uint8_t options, uint8_t * error) REG_WRITE: validate a write and register it for ACTION. |
| int | x430_device_set (struct x430_device * device, uint16_t address, int32_t value) Store a value into the register at address , ignoring access rights (lock-free). |
| int | x430_device_write (struct x430_device * device, uint16_t address, uint16_t length, const uint8_t * data, uint8_t options, uint8_t * error) WRITE semantics: checks every touched register, then calls the write hook and stores in address order; stores the EEPROM area when it changed. |
| int | x430_sim_init (struct x430_sim * sim, struct x430_device * device, const struct x430_sim_config * config) Prepare a simulator for device . |
| int | x430_sim_step (struct x430_sim * sim, uint32_t elapsed_ms) Advance the simulation by elapsed_ms one-millisecond steps and refresh the live registers. |
Detailed Description¶
Parts. A bus (x430_bus) decodes the instructions of one serial line with DXL2-C and answers for its devices (x430_device). A device holds the Control Table of the model selected at build time and enforces the rules of the real actuator; the application connects it to its motor through x430_hooks. The optional simulator (x430_sim) replaces the motor.
Execution model. Everything runs in one task context (an RX thread or the main loop), never in an interrupt: x430_bus_receive() with the bytes from the UART, x430_bus_poll() every few milliseconds (Bus Watchdog), and the live register updates of the application between x430_bus_lock() and x430_bus_unlock(). Hooks run inside x430_bus_receive() with the bus lock held.
Platform access is done only through x430_bus_config::write (the bytes of a status packet), the optional x430_port (lock, millisecond clock, delay) and the hooks of each device.
Initialization. Every function except the three *_init() functions returns X430_ERR_STATE for an instance without a successful initialization and calls no hook. An initialization checks every argument before it changes the instance: a refused initialization leaves the instance as it was.
Public Attributes Documentation¶
variable x430_sim_hooks¶
Hooks implementing the simulated actuator: pass them with x430_device_config::user_data pointing at an initializedx430_sim .
All members are NULL when X430_FEATURE_SIMULATOR is 0.
Public Functions Documentation¶
function x430_bus_attach¶
Attach an initialized device to an initialized bus.
Takes the bus lock.
Parameters:
busBus.deviceDevice, not attached to any bus.
Return value:
- X430_OK Attached.
- X430_ERR_PARAM NULL pointer.
- X430_ERR_STATE Bus or device not initialized, or the device is attached.
- X430_ERR_CONFIG Bus full (X430_MAX_DEVICES) or the ID is used on the bus.
function x430_bus_find¶
Attached device with the primary ID id (lock-free).
Parameters:
busBus.idDYNAMIXEL ID.deviceSet to the device, or to NULL when no device has that ID.
Return value:
- X430_OK Found.
- X430_ERR_PARAM NULL pointer, or no attached device has the ID.
- X430_ERR_STATE Bus not initialized.
function x430_bus_handle_packet¶
Handle one decoded instruction packet, for applications that run their own DXL2-C link.
Takes the bus lock; runs the hooks.
Parameters:
busBus.packetPacket decoded by DXL2-C. Status packets are ignored.
Return value:
- X430_OK (NULL pointer), X430_ERR_STATE (bus not initialized), X430_ERR_HAL (the writer failed).
function x430_bus_init¶
Initialize a bus.
Calls no callback except x430_port::millis.
Parameters:
busBus.configConfiguration; copied (the port it points at is not).
Return value:
- X430_OK Bus ready.
- X430_ERR_PARAM NULL pointer or no writer.
function x430_bus_lock¶
Take the bus lock ( x430_port::lock ; nothing without it).
Use it around the live register updates of the application.
Parameters:
busBus.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_bus_poll¶
Periodic service: Bus Watchdog of every device.
Call every few milliseconds (the watchdog unit is 20 ms). Takes the bus lock.
Parameters:
busBus.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_bus_receive¶
Feed received bytes in any chunking; answers every complete instruction packet.
Takes the bus lock; runs the hooks.
Parameters:
busBus.dataReceived bytes (may be NULL whenlengthis 0).lengthNumber of bytes.
Return value:
- X430_OK Bytes processed.
- X430_ERR_PARAM NULL bus, or NULL data with a non-zero length.
- X430_ERR_STATE Bus not initialized.
- X430_ERR_HAL The writer failed for at least one status packet.
function x430_bus_unlock¶
Release the bus lock ( x430_port::unlock ).
Parameters:
busBus.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_action¶
ACTION: execute the registered write.
Parameters:
deviceDevice.errorProtocol result; DXL2_ERR_INSTRUCTION when nothing is registered.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_backup¶
Control Table BACKUP: store, or restore with the torque off.
Parameters:
deviceDevice.optionX430_BACKUP_STORE or X430_BACKUP_RESTORE.errorProtocol result.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized), X430_ERR_UNSUPPORTED (X430_FEATURE_BACKUP is 0).
function x430_device_clear¶
CLEAR with option X430_CLEAR_MULTI_TURN _(event_X430_EVENT_CLEAR_MULTI_TURN ).
Parameters:
deviceDevice.optionX430_CLEAR_MULTI_TURN.errorProtocol result: DXL2_ERR_RESULT_FAIL while moving, DXL2_ERR_DATA_RANGE for another option.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_factory_reset¶
FACTORY_RESET, then like REBOOT; event X430_EVENT_FACTORY_RESET .
Parameters:
deviceDevice.optionX430_FACTORY_RESET_ALL, X430_FACTORY_RESET_EXCEPT_ID or X430_FACTORY_RESET_EXCEPT_ID_BAUD.errorProtocol result; DXL2_ERR_DATA_RANGE for another option.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_flush_events¶
Deliver deferred events ( X430_EVENT_BAUD_RATE ) after the status packet.
The bus calls it; call it after x430_device_write() of your own.
Parameters:
deviceDevice.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_get¶
Value of the register that starts at address (lock-free).
Parameters:
deviceDevice.addressFirst address of a register.valueSign-extended value.
Return value:
- X430_OK Value read.
- X430_ERR_PARAM NULL pointer, or no register starts at
address. - X430_ERR_STATE Device not initialized.
function x430_device_id¶
Current ID (7) of the device (lock-free).
Parameters:
deviceDevice.idID.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_init¶
Initialize a device: factory values, stored EEPROM area (nvm_read), the RAM area and the Startup Configuration (which may call the write hook).
Initialize a device before x430_bus_attach(), never while a bus serves it: the content of the instance before the call is not trusted (it may be the garbage of a stack instance), so an attachment cannot be detected.
Parameters:
deviceDevice, not attached to a bus.configConfiguration; copied (the hooks it points at are not).
Return value:
- X430_OK Device ready.
- X430_ERR_PARAM NULL pointer or ID above 252.
function x430_device_raise_hardware_error¶
Report hardware errors (Hardware Error Status bits, lock-free).
The bits stay set until REBOOT. Bits enabled in Shutdown (63) switch the torque off (event X430_EVENT_TORQUE_SHUTDOWN) and keep it off until REBOOT.
Parameters:
deviceDevice.bits::X430_HW_ERROR_* bits.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_read¶
READ semantics: read hook, Indirect Data, Realtime Tick.
int x430_device_read (
struct x430_device * device,
uint16_t address,
uint16_t length,
uint8_t * data,
uint8_t * error
)
Parameters:
deviceDevice.addressFirst address.lengthBytes to read.dataDestination oflengthbytes.errorProtocol result: DXL2_ERR_NONE, DXL2_ERR_DATA_LENGTH (length 0) or DXL2_ERR_ACCESS (beyond the table).
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_reboot¶
REBOOT: RAM area reset, errors cleared, Startup Configuration applied, event X430_EVENT_REBOOT .
Parameters:
deviceDevice.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_reg_write¶
REG_WRITE: validate a write and register it for ACTION.
int x430_device_reg_write (
struct x430_device * device,
uint16_t address,
uint16_t length,
const uint8_t * data,
uint8_t options,
uint8_t * error
)
Parameters:
deviceDevice.addressFirst address.lengthBytes, at most X430_REG_WRITE_SIZE.datalengthbytes.optionsX430_WRITE_SECONDARY.errorProtocol result.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_device_set¶
Store a value into the register at address , ignoring access rights (lock-free).
For live registers (Present Position, Moving, ...): no hook is called, no range is checked.
Parameters:
deviceDevice.addressFirst address of a register.valueValue; truncated to the register size.
Return value:
- X430_OK Value stored.
- X430_ERR_PARAM NULL pointer, or no register starts at
address. - X430_ERR_STATE Device not initialized.
function x430_device_write¶
WRITE semantics: checks every touched register, then calls the write hook and stores in address order; stores the EEPROM area when it changed.
int x430_device_write (
struct x430_device * device,
uint16_t address,
uint16_t length,
const uint8_t * data,
uint8_t options,
uint8_t * error
)
Parameters:
deviceDevice.addressFirst address.lengthBytes to write.datalengthbytes.optionsX430_WRITE_SECONDARY, X430_WRITE_VALIDATE_ONLY.errorProtocol result: DXL2_ERR_NONE or the DXL2_ERR_* of the first failure.
Return value:
- X430_OK (NULL), X430_ERR_STATE (not initialized).
function x430_sim_init¶
Prepare a simulator for device .
int x430_sim_init (
struct x430_sim * sim,
struct x430_device * device,
const struct x430_sim_config * config
)
Call it before x430_device_init() of a device whose hooks are x430_sim_hooks and whose user data is sim.
Parameters:
simSimulator.deviceDevice it simulates (may be initialized later).configConfiguration, NULL for the defaults.
Return value:
- X430_OK (NULL sim or device), X430_ERR_UNSUPPORTED (X430_FEATURE_SIMULATOR is 0).
function x430_sim_step¶
Advance the simulation by elapsed_ms one-millisecond steps and refresh the live registers.
Takes the bus lock of the device when it is attached. The time is proportional to elapsed_ms: call it periodically.
Parameters:
simSimulator.elapsed_msTime since the previous call [ms].
Return value:
- X430_OK (NULL), X430_ERR_STATE (simulator or device not initialized), X430_ERR_UNSUPPORTED (X430_FEATURE_SIMULATOR is 0).