Automated monitoring systems are increasingly vital in industrial construction environments to ensure personnel adhere to safety protocols, specifically regarding the use of protective gear like hard hats. This project outlines the development of a mobile inspection unit designed to detect helmet compliance using machine vision. The device utilizes a custom robotic platform powered by an ESP32-S3 microcontroller and Mecanum wheels for omnidirectional movement, enabling it to navigate complex terrain. Visual processing is handled by a K210-based MaixDuino module running a YOLOv2 object detection model, which identifies workers without proper head protection and reports violations to a cloud platform.
System Architecture and Hardware Selection
The system is divided into three primary modules: the main control unit, the remote controller, and the visual processing unit. The main controller is an ESP32-S3-DevKitC-1, chosen for its high-performance capabilities and integrated Wi-Fi/Bluetooth support. It manages the motor drivers, controls the servo-based pan-tilt mechanism, and communicates with the remote. The remote control functionality is delegated to an ESP32-C3-LCDkit. This board features an integrated LCD screen, rotary encoder, and an infrared receiver. It captures commands from a standard IR remote, processes user inputs, and transmits control signals to the S3 main controller. Communication between the two ESP32 chips utilizes the ESP-NOW protocol, ensuring low-latency, peer-to-peer data transmission suitable for real-time robot control. For the vision subsystem, a MaixDuino development board is employed. It is built around the K210 AI processor, which offers 1 TOPS of computing power, making it ideal for edge AI applications. The K210 captures video feeds, runs inference to detect safety helmets, and streams video via TCP to a ground station computer.Chassis and Hardware Design
The robot's chassis is custom-designed using PCB software to house the electronics. Power management involves stepping down a 7.2V battery supply to 5V using a 78M05 regulator and further to 3.3V using an AMS1117 LDO. The motor driver stage consists of TB6612FNG chips, capable of driving the four N20 motors required for the Mecanum wheel configuration. A 2-degree-of-freedom (2-DOF) pan-tilt mechanism, designed in SolidWorks and 3D-printed, holds the camera module, allowing the vision system to scan different angles. This mechanism is actuated by two MG90S servos.Motion Control Implementation
The Mecanum wheels allow the robot to move forward, backward, strafe, and rotate. This requires independent speed control for each of the four motors. The ESP32-S3 generates PWM signals to drive the TB6612FNG drivers. The logic for setting motor speed and direction involves mapping integer speed values to PWM duty cycles and setting the appropriate logic levels on the driver input pins. A refactored approach to the motor control logic encapsulates the setup and driving functions. The following code demonstrates how to initialize the PWM channels and a modular function to drive a single motor, which simplifies the main loop.// Define Motor Structure
struct MotorPins {
int pinA;
int pinB;
int pwmChannel;
};
// Motor Configuration
const int MAX_PWM = 4000;
const int PWM_FREQ = 1000;
const int PWM_RES = 13; // 13-bit resolution
void initMotorSystem() {
// Configure PWM for all channels
for (int i = 0; i < 4; i++) {
ledcSetup(i, PWM_FREQ, PWM_RES);
ledcWrite(i, 0);
}
// Attach pins (example for Motor 1)
ledcAttachPin(M1_PWM_PIN, 0);
pinMode(M1_INA, OUTPUT);
pinMode(M1_INB, OUTPUT);
// Repeat for Motors 2, 3, and 4...
}
void driveMotor(MotorPins m, int speed) {
// Clamp speed to valid range
speed = constrain(speed, -MAX_PWM, MAX_PWM);
// Determine direction
if (speed > 0) {
digitalWrite(m.pinA, HIGH);
digitalWrite(m.pinB, LOW);
} else if (speed < 0) {
digitalWrite(m.pinA, LOW);
digitalWrite(m.pinB, HIGH);
} else {
digitalWrite(m.pinA, LOW);
digitalWrite(m.pinB, LOW);
}
// Write absolute speed to PWM
ledcWrite(m.pwmChannel, abs(speed));
}
Visual Detection and Model Training
The helmet detection capability relies on a YOLOv2 model trained on the MaixHub platform. The workflow involves collecting a dataset of images containing people with and without hard hats, annotating them, and training the model for the K210's KPU neural network processor. To facilitate data collection, a script running on the MaixDuino captures images and saves them to an SD card. The following MicroPython code snippet illustrates the core logic for capturing and saving an image upon a button press.import sensor, image, lcd, time
from Maix import GPIO
from fpioa_manager import fm
# Initialize Sensor and LCD
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
lcd.init()
# Register Button
fm.register(16, fm.fpioa.GPIOHS0)
btn = GPIO(GPIO.GPIOHS0, GPIO.PULL_UP)
count = 0
while True:
img = sensor.snapshot()
lcd.display(img)
if btn.value() == 0: # Button pressed
time.sleep_ms(50) # Debounce
if btn.value() == 0:
# Save image to SD card
filename = "/sd/capture_{}.jpg".format(count)
img.save(filename, quality=95)
lcd.draw_string(lcd.width()//2, lcd.height()//2, "Saved!", lcd.RED)
print("Image saved:", filename)
count += 1
time.sleep_ms(500) # Wait for release
Once trained, the model is deployed to the device. When the camera detects a person without a helmet, the system flags the event.
Cloud Integration
To enable remote monitoring and data logging, the robot uploads detection results to the OneNet IoT platform. This is achieved via HTTP POST requests. When a violation is detected, the captured image is sent to the cloud server.import requests
def upload_image_to_onenet(file_path, product_id, device_name, api_key):
url = "https://iot-api.heclouds.com/device/file-upload"
headers = {
'Authorization': api_key
}
payload = {
'product_id': product_id,
'device_name': device_name
}
files = {
'file': open(file_path, 'rb')
}
try:
response = requests.post(url, headers=headers, data=payload, files=files)
print("Server Response:", response.text)
except Exception as e:
print("Upload failed:", e)
This integration allows site managers to view real-time data and historical records of safety compliance violations directly through the cloud dashboard, enhancing the overall safety management workflow on construction sites.