Real-Time Motion Control in ROS:
Uniting Machinekit HAL with Tormach's
ZA6 Robot
John Morris

Brandon Duarte

Software Engineering

Software EngineeringHeadquartered in Madison WI
100% employee-owned

Our Customers
Hobbyist
Small businesses
Researchers

ZA6 Robot
6kg industrial arm
Natural fit with machine tool products
Powered by ROS and fully open source

“Each new robotic platform we integrate with, we have toevaluate RT expectations and requirements. We would muchrather have that solved out of the box and use thatengineering time building more sophisticated robots!”
Nathan Brooks, CTO

Machinekit HAL cuts machine control development timeMachinekit HAL: Real Time Threading Environment
Real-time threadprogramming
Linux RT thread “flavor”
support●RT_PREEMPT●
and/or POSIX (non-RT)●or Xenomai
Real Time Scheduling●scheduling algorithme.g. POSIX`SCHED_FIFO`●
elevated schedulingpriorityMore real-time
programming
RT <-> non-RTcommunication●
lock-free ring buffers●shm●mutexes
Arch-dependent
programming●Atomic 64-bit access●hi-res timers
Other●`mlockall()`: VM
page faults

Fix real-time jitter sources
OS and hardware tuning●
Intel CPU C-States (powersaving)●CPU frequency scaling(Intel; AMD)
Dedicated RT CPU●`isolcpus`●
cgroup `cpuset`●CPU affinity

Machinekit HAL: Modular components for common tasks
Hardware drivers●
EtherCAT●“hostmot” FPGA f/w●
Beaglebone PRUSS●
Modbus●GPIO
Instrumentation●
halscope●
sampler●streamer●latencybins●
histobins

Motor control●
PID●
PWM generator●
Step/dir generator●
Quadrature

Logic●
and/or/not/xor●
flipflop●
mux/demux●
oneshot●
lut●
timedelayArithmetic & math●ddt/integrator●biquad/lowpass/kalmanfilters●limit1/limit2/limit3●offset/scale●sum/mult●siggenMachinekit HAL: Basic concepts

Machinekit HAL: Basic configuration
1. load “siggen” comp2. load “limit3” comp3. net “cmd” & “fb” signals

4. set up real time thread

5. start the scope!

Save to `demo.hal` and run:`halrun -f demo.hal`

Machinekit HAL: Easy C and Python APIs

Machinekit HAL: Tools for inspecting running systems
halscope

halsampler

halcmdvisualize live data

data logging

update live system`hal_ros_control` cuts robot control development timeros2_control + HAL: Controller Manager in HAL RT thread`ros2_control_node`:
Controller Manager moved
into a HAL RT component

Diagram fromros2_control docs

ros2_control + HAL: Hardware interface

ros2_control systeminterface:
expose command & stateinterfaces through HAL pins

Diagram fromros2_control docs

HAL non-RT components
gripper_io- Publish gripper state to ROS topics- Subscribe to gripper cmd ROS topic- Python, non-RT HAL componentgripper_online

gripper_online

HAL_IN HAL_BIT

std_msgs.msg.Boolgripper_fault

gripper_fault

HAL_IN HAL_BIT

std_msgs.msg.Boolgripper_state

gripper_state

HAL_IN HAL_U32

std_msgs.msg.UInt32

gripper_cmd

gripper_cmd

HAL_OUT HAL_U32

std_msgs.msg.UInt32

ROS topics

HAL pins`hal_ros_control` and ROS: Other interfaces

Basic `hal_ros_control` robot hardware configuration- rate: 1kHz

lcec.read
read ECAT

hal_hw_interface

HAL signals

HAL non-RT components

HAL pins

servo-thread

HAL RT components

Non-RT HAL
HAL pins

Real time HAL thread

HAL functions

Machinekit: HAL+RTAPI

hw_device_mgr- controller manager ROS node
- hardware interface- Drive state management ROS node
- Python, non-RT HAL component

j1_status_word

j1_pos_fbfunct()

HAL_IN HAL_U32

read()
update()write()

j1_control_word

j1_pos_cmd

HAL_OUT HAL_U32

j1_pos_fb
read()

HAL_OUT HAL_FLOAT

read ECAT

j1_status_word

lcec.write

HAL_OUT HAL_U32

write ECAT

j1_pos_cmd
write()

HAL_IN HAL_FLOAT

write ECAT

j1_control_wordHAL_IN HAL_U32

real time
non-real time

- HAL-EtherCAT interface- Read/write RT process data

j1_control_word U32

lcec

j1_status_word U32

ros2_control
hardware_interface
read()/update()/write()

j1_pos_cmd FLOAT

j1_pos_fb FLOAT

HAL_OUT HAL_FLOAT

hal_hw_interface.functspin_timer_cb()
read status word
read ROS command
write control word

HAL_IN HAL_FLOAT

RobotHW::ZA6 Robot: ROS-based, fully open source control stackHAL-ROS Control

https://github.com/tormach/hal_ros_control