96static_assert(
sizeof(ServoSetpointWire) == 80,
"X5 setpoint wire ABI changed");
97static_assert(
sizeof(ServoFeedbackWire) == 40,
"X5 feedback wire ABI changed");
98static_assert(
sizeof(ServoSetpointFrame) == 656,
"X5 setpoint frame ABI changed");
99static_assert(
sizeof(ServoFeedbackFrame) == 336,
"X5 feedback frame ABI changed");
100static_assert(std::is_trivially_copyable<ServoSetpointFrame>::value,
101 "X5 setpoint frame must be trivially copyable");
102static_assert(std::is_trivially_copyable<ServoFeedbackFrame>::value,
103 "X5 feedback frame must be trivially copyable");
275 if(values ==
nullptr || count == 0 || count >
MaxAxes)
279 frame.
axis_count =
static_cast<std::uint32_t
>(count);
280 for(std::size_t index = 0; index < count; ++index) {
288 frame.
axes[index] = wire;
294 std::size_t count, std::uint64_t &tick)
300 for(std::size_t index = 0; index < count; ++index)
303 for(std::size_t index = 0; index < count; ++index)
312 if(values ==
nullptr || count == 0 || count >
MaxAxes)
316 frame.
axis_count =
static_cast<std::uint32_t
>(count);
317 for(std::size_t index = 0; index < count; ++index) {
323 frame.
axes[index] = wire;
329 std::size_t count, std::uint64_t &tick)
335 for(std::size_t index = 0; index < count; ++index)
338 for(std::size_t index = 0; index < count; ++index)
373 std::atomic<std::uint32_t>
state{0};
380static_assert(std::atomic<std::uint32_t>::is_always_lock_free,
381 "X5 requires lock-free uint32 atomics");
382static_assert(std::atomic<std::uint64_t>::is_always_lock_free,
383 "X5 requires lock-free uint64 atomics");
384static_assert(std::is_standard_layout<TransportHeader>::value,
385 "X5 transport header must have stable member order");
386static_assert(
sizeof(TransportHeader) == 128,
"X5 transport header ABI changed");
387static_assert(offsetof(TransportHeader, generation) == 48,
388 "X5 transport header generation offset changed");
389static_assert(offsetof(TransportHeader, state) == 64,
390 "X5 transport header state offset changed");
391static_assert(offsetof(TransportHeader, phase_tick) == 88,
392 "X5 transport header phase offset changed");
396 static_assert(Depth > 0,
"X5 transport depth must be positive");
403 bool initialize(std::size_t axis_count, std::uint64_t period_ns, std::uint64_t generation)
405 if(axis_count == 0 || axis_count >
MaxAxes || period_ns == 0 || generation == 0) {
409 std::memory_order_relaxed);
413 header.region_bytes =
static_cast<std::uint32_t
>(
sizeof(*this));
415 header.axis_count =
static_cast<std::uint32_t
>(axis_count);
416 header.transport_depth =
static_cast<std::uint32_t
>(Depth);
422 header.generation = generation;
423 header.period_ns = period_ns;
425 std::memory_order_relaxed);
426 header.executor_heartbeat.store(0, std::memory_order_relaxed);
427 header.bus_heartbeat.store(0, std::memory_order_relaxed);
428 header.phase_tick.store(0, std::memory_order_relaxed);
433 std::memory_order_release);
439 const std::uint32_t raw_state =
header.state.load(std::memory_order_acquire);
476 std::uint32_t raw =
static_cast<std::uint32_t
>(expected);
477 return header.state.compare_exchange_strong(raw,
static_cast<std::uint32_t
>(desired),
478 std::memory_order_acq_rel,
479 std::memory_order_acquire);
486 header.last_error.store(
static_cast<std::uint32_t
>(error), std::memory_order_release);
488 std::memory_order_release);
492static_assert(
sizeof(ServoIpcRegion<8>) == 9344,
"X5 default transport region ABI changed");
constexpr std::uint32_t LimitSwitchNeg
constexpr std::uint32_t CommunicationReady
bool valid_feedback_wire(const ServoFeedbackWire &wire)
void decode_feedback_value(const ServoFeedbackWire &wire, ServoFeedback &target)
constexpr std::uint32_t DigitalInputMask
constexpr std::uint32_t ReadyForPowerOn
constexpr std::uint32_t LimitSwitchPos
void decode_setpoint(const ServoSetpointWire &wire, ServoSetpoints &target)
constexpr std::uint32_t AxisInfoMask
bool valid_setpoint_wire(const ServoSetpointWire &wire)
bool valid_direction(axis::Direction direction)
bool valid_feedback_source(const ServoFeedback &source)
constexpr std::uint32_t Warning
bool valid_setpoint_source(const ServoSetpoints &source)
ServoSetpointWire encode_setpoint(const ServoSetpoints &source)
ServoFeedbackWire encode_feedback_value(const ServoFeedback &source)
constexpr std::uint32_t HomeAbsSwitch
bool encode_setpoints(std::uint64_t tick, const ServoSetpoints *values, std::size_t count, ServoSetpointFrame &frame)
bool decode_feedback(const ServoFeedbackFrame &frame, ServoFeedback *values, std::size_t count, std::uint64_t &tick)
bool encode_feedback(std::uint64_t tick, const ServoFeedback *values, std::size_t count, ServoFeedbackFrame &frame)
constexpr std::uint32_t TransportAbiVersion
constexpr std::size_t MaxAxes
constexpr std::uint32_t TransportMagic
bool decode_setpoints(const ServoSetpointFrame &frame, ServoSetpoints *values, std::size_t count, std::uint64_t &tick)
bool digital_inputs[DigitalInputCount]
static constexpr std::size_t DigitalInputCount
axis::AxisModel::AxisInfoInputs info
axis::Direction torque_direction
double torque_velocity_limit
double torque_deceleration_limit
double torque_acceleration_limit
ServoFeedbackWire axes[MaxAxes]
std::uint32_t digital_inputs
bool transition(TransportState expected, TransportState desired)
rt::IpcDoubleBuffer< TransportStatusSnapshot > status
void set_error(TransportError error)
TransportState state() const
bool initialize(std::size_t axis_count, std::uint64_t period_ns, std::uint64_t generation)
rt::IpcSpscRing< ServoSetpointFrame, Depth > setpoints
AttachStatus attach_status() const
rt::IpcSpscRing< ServoFeedbackFrame, Depth > feedback
ServoSetpointWire axes[MaxAxes]
double torque_acceleration_limit
std::int32_t torque_direction
std::uint32_t torque_mode
double torque_velocity_limit
double torque_deceleration_limit
std::uint64_t setpoints_published
std::uint64_t feedback_dropped
std::uint64_t last_feedback_tick
std::uint64_t feedback_consumed
std::uint64_t setpoint_starvation
std::uint64_t setpoints_consumed
std::uint64_t feedback_published
std::uint64_t last_setpoint_tick