Skip to content

Group x430

Modules > 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 .

const struct x430_hooks x430_sim_hooks;

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.

int x430_bus_attach (
    struct x430_bus * bus,
    struct x430_device * device
) 

Takes the bus lock.

Parameters:

  • bus Bus.
  • device Device, not attached to any bus.

Return value:


function x430_bus_find

Attached device with the primary ID id (lock-free).

int x430_bus_find (
    const struct x430_bus * bus,
    uint8_t id,
    struct x430_device ** device
) 

Parameters:

  • bus Bus.
  • id DYNAMIXEL ID.
  • device Set to the device, or to NULL when no device has that ID.

Return value:


function x430_bus_handle_packet

Handle one decoded instruction packet, for applications that run their own DXL2-C link.

int x430_bus_handle_packet (
    struct x430_bus * bus,
    const struct dxl2_packet * packet
) 

Takes the bus lock; runs the hooks.

Parameters:

  • bus Bus.
  • packet Packet decoded by DXL2-C. Status packets are ignored.

Return value:


function x430_bus_init

Initialize a bus.

int x430_bus_init (
    struct x430_bus * bus,
    const struct x430_bus_config * config
) 

Calls no callback except x430_port::millis.

Parameters:

  • bus Bus.
  • config Configuration; copied (the port it points at is not).

Return value:


function x430_bus_lock

Take the bus lock ( x430_port::lock ; nothing without it).

int x430_bus_lock (
    struct x430_bus * bus
) 

Use it around the live register updates of the application.

Parameters:

  • bus Bus.

Return value:


function x430_bus_poll

Periodic service: Bus Watchdog of every device.

int x430_bus_poll (
    struct x430_bus * bus
) 

Call every few milliseconds (the watchdog unit is 20 ms). Takes the bus lock.

Parameters:

  • bus Bus.

Return value:


function x430_bus_receive

Feed received bytes in any chunking; answers every complete instruction packet.

int x430_bus_receive (
    struct x430_bus * bus,
    const uint8_t * data,
    size_t length
) 

Takes the bus lock; runs the hooks.

Parameters:

  • bus Bus.
  • data Received bytes (may be NULL when length is 0).
  • length Number of bytes.

Return value:


function x430_bus_unlock

Release the bus lock ( x430_port::unlock ).

int x430_bus_unlock (
    struct x430_bus * bus
) 

Parameters:

  • bus Bus.

Return value:


function x430_device_action

ACTION: execute the registered write.

int x430_device_action (
    struct x430_device * device,
    uint8_t * error
) 

Parameters:

  • device Device.
  • error Protocol result; DXL2_ERR_INSTRUCTION when nothing is registered.

Return value:


function x430_device_backup

Control Table BACKUP: store, or restore with the torque off.

int x430_device_backup (
    struct x430_device * device,
    uint8_t option,
    uint8_t * error
) 

Parameters:

Return value:


function x430_device_clear

CLEAR with option X430_CLEAR_MULTI_TURN _(event_X430_EVENT_CLEAR_MULTI_TURN ).

int x430_device_clear (
    struct x430_device * device,
    uint8_t option,
    uint8_t * error
) 

Parameters:

  • device Device.
  • option X430_CLEAR_MULTI_TURN.
  • error Protocol result: DXL2_ERR_RESULT_FAIL while moving, DXL2_ERR_DATA_RANGE for another option.

Return value:


function x430_device_factory_reset

FACTORY_RESET, then like REBOOT; event X430_EVENT_FACTORY_RESET .

int x430_device_factory_reset (
    struct x430_device * device,
    uint8_t option,
    uint8_t * error
) 

Parameters:

Return value:


function x430_device_flush_events

Deliver deferred events ( X430_EVENT_BAUD_RATE ) after the status packet.

int x430_device_flush_events (
    struct x430_device * device
) 

The bus calls it; call it after x430_device_write() of your own.

Parameters:

  • device Device.

Return value:


function x430_device_get

Value of the register that starts at address (lock-free).

int x430_device_get (
    const struct x430_device * device,
    uint16_t address,
    int32_t * value
) 

Parameters:

  • device Device.
  • address First address of a register.
  • value Sign-extended value.

Return value:


function x430_device_id

Current ID (7) of the device (lock-free).

int x430_device_id (
    const struct x430_device * device,
    uint8_t * id
) 

Parameters:

  • device Device.
  • id ID.

Return value:


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).

int x430_device_init (
    struct x430_device * device,
    const struct x430_device_config * config
) 

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:

  • device Device, not attached to a bus.
  • config Configuration; copied (the hooks it points at are not).

Return value:


function x430_device_raise_hardware_error

Report hardware errors (Hardware Error Status bits, lock-free).

int x430_device_raise_hardware_error (
    struct x430_device * device,
    uint8_t bits
) 

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:

  • device Device.
  • bits ::X430_HW_ERROR_* bits.

Return value:


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:

  • device Device.
  • address First address.
  • length Bytes to read.
  • data Destination of length bytes.
  • error Protocol result: DXL2_ERR_NONE, DXL2_ERR_DATA_LENGTH (length 0) or DXL2_ERR_ACCESS (beyond the table).

Return value:


function x430_device_reboot

REBOOT: RAM area reset, errors cleared, Startup Configuration applied, event X430_EVENT_REBOOT .

int x430_device_reboot (
    struct x430_device * device
) 

Parameters:

  • device Device.

Return value:


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:

Return value:


function x430_device_set

Store a value into the register at address , ignoring access rights (lock-free).

int x430_device_set (
    struct x430_device * device,
    uint16_t address,
    int32_t value
) 

For live registers (Present Position, Moving, ...): no hook is called, no range is checked.

Parameters:

  • device Device.
  • address First address of a register.
  • value Value; truncated to the register size.

Return value:


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:

Return value:


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:

  • sim Simulator.
  • device Device it simulates (may be initialized later).
  • config Configuration, NULL for the defaults.

Return value:


function x430_sim_step

Advance the simulation by elapsed_ms one-millisecond steps and refresh the live registers.

int x430_sim_step (
    struct x430_sim * sim,
    uint32_t elapsed_ms
) 

Takes the bus lock of the device when it is attached. The time is proportional to elapsed_ms: call it periodically.

Parameters:

  • sim Simulator.
  • elapsed_ms Time since the previous call [ms].

Return value: