← back to work

PWM output optimization with the Grey Wolf Optimizer

Swarm-intelligence optimizer correcting PWM motor error, recovered from the original report.

Problem

A motor's actual output angle didn't match the expected value, and the gap (the error angle) needed correcting via the PWM duty cycle. Framed as an optimization problem and solved with the Grey Wolf Optimizer, a swarm-intelligence algorithm modeled on wolf pack hunting hierarchy. Built for underwater vehicle motor control, referencing prior Kocaeli University research on object tracking in underwater vehicles.

Approach

Framed the correction as minimizing S where P - E = S (expected value minus error value). Wolves in the optimizer represent candidate duty-cycle adjustments; each iteration, the population is re-ranked by fitness, the top three (alpha, beta, gamma) are kept, and every other wolf's position is updated to move toward a point influenced by those three. pwm_optimize wraps the general optimizer around the specific problem, taking an expected angle and measured error and returning the duty cycle adjustment and resulting motor voltages.

Result

The optimizer converges correctly against a Rastrigin benchmark function (the standard sanity check before applying it to the real problem), and produces sensible duty cycle and motor voltage corrections for the report's example error values.

A note on this write-up

The original project files didn't survive, the code published here was recovered by transcribing it directly from the written report, which included the full implementation verbatim. It's the real submitted code, recovered rather than rewritten.

What I'd do differently

The report itself is candid that most of the project's time went into problem framing rather than implementation, turning "the motor points the wrong way" into something an optimizer can act on was the actual work. The fitness function used (Rastrigin) is a generic benchmark rather than one derived from the real system's error behavior, a real deployment would need that gap closed.