Automation and drones
UAT 202 Fundamentals of Automation Technology
Lesson
By the end of this module you will be able to
- Design the battery-swap station's sequence as a state machine with fault handling
- Explain Modbus TCP communication and build a request to read holding registers
- Explain the cascaded controllers in PX4 and ArduPilot flight controllers
- Use ArduPilot relays and grippers to connect a drone with automated equipment
- Compare industrial robot types and teach positions relative to a user frame
Why this matters
A drone that must patrol an area all day needs its battery swapped regularly. Swapping by hand means someone on duty at all times, so an automatic battery-swap station is where industrial automation (sensors, PLCs, actuators) meets the drone system (flight controller, missions and links). This module brings the whole course together.
The sequence as a state machine
A state machine describes a system as a set of states, and the events that move it from one state to another. The SFC language in IEC 61131-3 is designed for this kind of task.
- IDLE: wait for a drone to land
- LOCK: clamp the drone in position when the sensor sees it on the pad
- SWAP: the gripper removes the old battery and inserts a new one
- CHECK: confirm the new battery is seated and its voltage is correct
- RELEASE: unclamp, leaving the drone ready to take off
- FAULT: if any step times out or the emergency stop is pressed, stop all motion and wait for a person to inspect
Example 1 Simulating the station’s state machine
TIMEOUT = {"LOCK": 5, "SWAP": 20, "CHECK": 5, "RELEASE": 5} # maximum seconds per state
NEXT = {("IDLE", "landed"): "LOCK", ("LOCK", "locked"): "SWAP", ("SWAP", "swapped"): "CHECK",
("CHECK", "voltage_ok"): "RELEASE", ("RELEASE", "released"): "IDLE"}
def run(events):
state, entered = "IDLE", 0
for t, event in events:
if event == "estop" or (state in TIMEOUT and t - entered > TIMEOUT[state]):
reason = "E-stop" if event == "estop" else f"timeout in {state}"
print(f"t={t:>3} s {state:<8} -> FAULT ({reason})")
return "FAULT"
new = NEXT.get((state, event))
if new:
print(f"t={t:>3} s {state:<8} -> {new:<8} on '{event}'")
state, entered = new, t
return state
print("final:", run([(0, "landed"), (2, "locked"), (15, "swapped"), (17, "voltage_ok"), (19, "released")]))
print("final:", run([(0, "landed"), (2, "locked"), (30, "swapped")]))
t= 0 s IDLE -> LOCK on 'landed'
t= 2 s LOCK -> SWAP on 'locked'
t= 15 s SWAP -> CHECK on 'swapped'
t= 17 s CHECK -> RELEASE on 'voltage_ok'
t= 19 s RELEASE -> IDLE on 'released'
final: IDLE
t= 0 s IDLE -> LOCK on 'landed'
t= 2 s LOCK -> SWAP on 'locked'
t= 30 s SWAP -> FAULT (timeout in SWAP)
final: FAULT
The first run swaps the battery in 19 s. In the second, the gripper exceeds its 20 s limit, so the station goes to FAULT rather than releasing a drone whose battery may not be seated. Setting a maximum time for every state stops the system hanging without anyone knowing.
Modbus: a common language for devices
The drone mission system must ask the station’s PLC whether it is ready. Modbus is a widely used industrial protocol, storing data as coils (bits) and registers (16-bit values). Under Modbus specification V1.1b3, the TCP variant uses port 502, function 01 reads coils and function 03 reads holding registers. OPC UA (IEC 62541) is a newer standard with richer data structures and security.
Example 2 Building a Modbus TCP request
Read two holding registers starting at address 0 (such as station status and the number of ready batteries) from device 1.
import struct
transaction_id, protocol_id, unit_id = 1, 0, 1
function_code, start_address, quantity = 3, 0, 2
pdu = struct.pack(">BHH", function_code, start_address, quantity) # function + data
mbap = struct.pack(">HHHB", transaction_id, protocol_id, len(pdu) + 1, unit_id)
frame = mbap + pdu
print("request bytes:", frame.hex(" "))
print("length:", len(frame), "bytes; send to TCP port 502")
request bytes: 00 01 00 00 00 06 01 03 00 00 00 02
length: 12 bytes; send to TCP port 502
The first six bytes are the MBAP header (transaction number, protocol and length), followed by the unit number, then function 03, the start address and the quantity. Classic Modbus has no authentication or encryption, so it must stay on an isolated network with controlled access and never be exposed to the internet.
Automation inside the drone
A flight controller uses several nested feedback loops (a cascade). In PX4’s diagrams, the position loop commands velocity, the velocity loop commands attitude, the attitude loop commands rotation rate, and the rate loop commands the motors, with inner loops running faster than outer ones. ArduPilot follows the same principle: an angle P controller produces a desired rate, and a rate PID controller drives the motors.
A drone can also command external equipment. ArduPilot has relays triggered by a transmitter switch or the DO_SET_RELAY mission command, and a servo gripper commanded with DO_GRIPPER, for example to release a load at the destination. This is the same automation studied throughout the course, just on an aircraft.
Industrial robots: types and teaching positions
ISO 8373 defines an industrial robot as an automatically controlled, reprogrammable, multipurpose manipulator programmable in three or more axes. ISO 10218 sets the safety requirements: Part 1 (2025) covers the robot itself, and Part 2 (2025) covers robot applications and robot cells, meaning the robot together with its tooling, fixtures, guarding and the other machines around it. Part 2 now also contains most of the requirements for collaborative applications that used to be in ISO/TS 15066.
Robot types. The International Federation of Robotics (IFR) classifies robots by their mechanical structure:
| Type | Structure | Strengths | Use around the battery station |
|---|---|---|---|
| Articulated | Three or more rotary joints, like a human arm | Reaches around obstacles, works at many angles | Pulling a battery out sideways and pushing it into a charging slot |
| SCARA | Two parallel rotary joints, flexible in the horizontal plane but stiff vertically | Fast, precise pick-and-place on a flat surface | Moving batteries between trays on a table |
| Cartesian (gantry) | Linear axes at right angles (x, y, z) | Simple to program, covers a large rectangular area | Loading a rack of many charging slots |
| Parallel (delta) | Several arms joined to a single tool plate | Very fast with light loads | Sorting small parts; too light for drone batteries |
| Cylindrical | A rotary base plus vertical and radial linear axes | Simple structure for loading machines | Loading a single charger in front of the robot |
A collaborative robot (cobot) has features, such as force and power limiting, that let it work close to people. ISO 10218-2 treats “collaborative” as a property of the whole application, not of the robot alone: a cobot holding a sharp tool can still be dangerous.
Teaching positions. A robot moves between taught points (positions of the tool that are stored in the program). There are three main ways to record them (Groover):
- Teach pendant: a hand-held control unit used in manual mode to jog the robot to each point and store it. The OSHA Technical Manual describes the safeguards: speed is limited to no more than 250 mm/s (10 in/s), and the operator must hold a three-position enabling device in its centre position; letting go or squeezing hard stops the motion
- Lead-through (hand guiding): the operator physically moves the arm, common with cobots
- Offline programming: points are created in simulation software from a CAD model of the cell, then corrected against a few points measured on the real cell
Each point describes where the tool centre point (TCP), for example the centre of the gripper jaws, must be, measured in some frame. The smart choice is to teach points relative to a user frame (also called a work object) attached to the landing pad or fixture, rather than to the robot’s base. If the pad is moved during maintenance, only the three points that define the user frame need re-teaching, and every point in the program follows.
Example 3 A landing pad moved during maintenance
Three points were taught relative to the pad: the battery grip point and two landing-leg clamps. After maintenance the pad is 2 cm and 1 cm off its old position and turned 2° (assumed values). How far would the robot miss if the points had been stored in the robot base frame?
import math
def to_base(frame, p): # frame = (x, y, angle deg) of the pad frame in the robot base frame
fx, fy, deg = frame
a = math.radians(deg)
return (fx + p[0] * math.cos(a) - p[1] * math.sin(a), fy + p[0] * math.sin(a) + p[1] * math.cos(a))
taught = {"battery grip": (0.10, 0.00), "clamp A": (-0.20, 0.15), "clamp B": (-0.20, -0.15)} # m, pad frame
old_pad, new_pad = (0.80, 0.10, 0.0), (0.82, 0.09, 2.0) # pad shifted 2 cm and 1 cm, turned 2 degrees
for name, p in taught.items():
old, new = to_base(old_pad, p), to_base(new_pad, p)
miss = math.dist(old, new) * 1000
print(f"{name:<12} old ({old[0]:.3f}, {old[1]:.3f}) m new ({new[0]:.3f}, {new[1]:.3f}) m miss {miss:4.1f} mm")
T1 = 0.250 # m/s, reduced speed limit in manual (teach) mode
print(f"a 0.60 m move in teach mode takes at least {0.60 / T1:.1f} s")
battery grip old (0.900, 0.100) m new (0.920, 0.093) m miss 21.0 mm
clamp A old (0.600, 0.250) m new (0.615, 0.233) m miss 22.7 mm
clamp B old (0.600, -0.050) m new (0.625, -0.067) m miss 30.5 mm
a 0.60 m move in teach mode takes at least 2.4 s
Stored in the base frame, every point misses by 21–31 mm, enough for the gripper to hit the battery case instead of gripping it, and the points farther from the pad’s origin miss more because of the rotation. Stored in the pad’s user frame, re-teaching the user frame corrects all three points at once. Teaching is also slow: at no more than 250 mm/s, even a 0.6 m move takes 2.4 s, so a program with many points takes a long time to teach and check.
Designing an automation system
A basic automation design works through these questions in order:
- What is the task, and how many times per hour must it run?
- What is the sequence, and how long does each step take (written as a state machine, as earlier in this module)?
- What are the inputs and outputs: every sensor and actuator, which sizes the PLC or microcontroller.
- What about safety: where people can reach, emergency stops, and the safe state on power loss.
- Is there enough capacity at peak demand?
Example 4 A robotic battery-swap station
A robot arm swaps batteries for 6 drones that each fly 20-minute sorties (hypothetical values).
steps = {"land & lock": 20, "remove battery": 25, "insert battery": 25, "self-test": 15, "release": 10} # seconds
cycle = sum(steps.values())
flight_min, drones = 20, 6 # each drone flies 20 min between battery swaps
swaps_per_hour = drones * 60 / flight_min
busy = swaps_per_hour * cycle / 3600
print(f"cycle time {cycle} s, capacity {3600 / cycle:.0f} swaps/h")
print(f"demand {swaps_per_hour:.0f} swaps/h -> robot utilisation {busy:.0%}")
max_drones = int(0.8 * 3600 / cycle * flight_min / 60) # keep 20% headroom so the robot is not fully loaded
print(f"drones one station can serve at <=80% utilisation: {max_drones}")
cycle time 95 s, capacity 38 swaps/h
demand 18 swaps/h -> robot utilisation 48%
drones one station can serve at <=80% utilisation: 10
One cycle takes 95 seconds, so the station can do 38 swaps an hour. Demand of 18 swaps an hour keeps the arm busy about half the time. To stay under 80% utilisation, one station can serve at most 10 drones. This number decides how many stations are needed before any money is spent.
Module lab
Lab: designing the battery-swap station
- Write the station’s state machine in SFC or ST in CODESYS following Figure 1, with a maximum time for every state.
- Test the normal case, a timeout in every state and an emergency stop, comparing with Example 1.
- Enable a Modbus TCP server in CODESYS and read the registers from a computer on the lab’s internal network.
- In ArduPilot SITL, configure a relay and issue
DO_SET_RELAYin a mission, checking its state in the log. - Draw an overall diagram of how the drone, station and mission system communicate, and where emergency stops are needed.
Common mistakes
Watch out
- Not setting a maximum time per state, so the system waits forever for an event that never comes
- Leaving FAULT automatically without a person inspecting
- Exposing Modbus to outside networks when it has no authentication
- Tuning the outer loop of a cascade before the inner loop, when the inner loop must be stable first
- Testing relays or grippers on a real aircraft with propellers fitted
- Teaching robot points only in the base frame, so every point must be re-taught when a fixture moves
Summary
- A state machine describes a sequence as states and events, and needs time limits and a FAULT state
- Modbus TCP uses port 502 and function 03 reads holding registers, on a controlled network
- A flight controller is a cascade of feedback loops from position down to rotation rate
- ArduPilot can command relays and grippers from missions, linking drones with automated equipment
- Industrial robots (ISO 8373) come as articulated, SCARA, Cartesian, parallel and cylindrical types; teach points relative to a user frame, at reduced speed with an enabling device, and follow ISO 10218 for safety
- Design automation from the task, sequence, I/O, safety and capacity
Check your understanding
- The SWAP state has a 20 s limit and was entered at 2 s. If it has not finished at 25 s, what happens?
- Which Modbus function reads holding registers?
- Why should the battery-grip point be taught in a user frame attached to the landing pad?
- In a cascaded controller, which loop runs fastest?
- Which ArduPilot mission command operates a gripper?
Answers
- More than 20 s have passed (23 s), so it goes to FAULT
- Function 03
- If the pad moves, re-teaching the three points that define the user frame corrects every point in the program at once
- The rate loop, the innermost
DO_GRIPPER
Key formulas
| State transition | |
| Station utilisation |
Key references
- Modbus Organization. (2012). MODBUS application protocol specification V1.1b3. link
- PX4 Autopilot. Controller diagrams. PX4 user guide (main). link
- ArduPilot Dev Team. Copter attitude control. ArduPilot developer documentation. link
- ArduPilot Dev Team. Relay switch. ArduPilot Copter documentation. link
- ArduPilot Dev Team. Servo gripper. ArduPilot Copter documentation. link
- International Electrotechnical Commission. (2025). OPC unified architecture – Part 1: Overview and concepts (IEC 62541-1:2025). link
- International Organization for Standardization. (2015). Safety of machinery — Emergency stop function — Principles for design (ISO 13850:2015). link
- International Organization for Standardization. (2021). Robotics – Vocabulary (ISO 8373:2021). link
- International Organization for Standardization. (2025). Robotics – Safety requirements – Part 1: Industrial robots (ISO 10218-1:2025). link
- International Organization for Standardization. (2025). Robotics – Safety requirements – Part 2: Industrial robot applications and robot cells (ISO 10218-2:2025). link
- International Federation of Robotics. Industrial robots: definition and classification. link
- Occupational Safety and Health Administration. Industrial robot systems and industrial robot system safety (OSHA Technical Manual, Section IV, Chapter 4). U.S. Department of Labor. link
- Groover, M. P. (2018). Automation, production systems, and computer-integrated manufacturing (5th ed.). Pearson. link
Further reading
Study the assigned knowledge units in advance, review media and take the module quiz
Topic 2: AI and automated control
Deep dive: from embedded systems to AI robots and ROS
การควบคุมแบบ cascade และการปรับจูน flight controller
Deep dive: MQTT and Eclipse Mosquitto for drone and IoT systems
In class / field
Lab or field practice from worksheets with a safety checklist
Learning evidence: Checked worksheets and quiz results