Haztek Controls

THE RAPID PROTOTYPING LAB

One model.
A path to
real hardware.

Balance a pendulum. Follow the controller from simulation to generated code, real-time I/O, and a physical test bench.

A CONNECTED ENGINEERING WORKFLOW

Model & designMATLAB / Simulink
Simulate & comparePlant + controller
Generate & integrateC / C++ + target I/O
Deploy & calibrateSpeedgoat · Raptor · dSPACE
Measure & verifyTiming · tracking · limits

Reuse the control algorithm.
Adapt the execution platform and interfaces.

ILLUSTRATIVE ENGINEERING DEMO Browser simulation · no hardware connection · no measured target results

START WITH THE DYNAMICS

A small plant.
A complete control problem.

An unstable equilibrium makes the engineering visible: sample timing, state feedback, actuator saturation, and the difference between an equation and a working controller.

INVERTED PENDULUM / NONLINEAR PLANTReady
Cart and inverted pendulumAn animated cart moves along a rail to balance a point mass above its pivot. The angle is measured from upright.−0.75 mCART TRAVEL+0.75 mt = 0.00 sθ = 0° UPRIGHT
Angle8.0°
Position0.000 m
Command0.00 N
Controller period5 ms
ANGLE / DEG10 SECOND EXPERIMENT
Pendulum angle over time, clipped to plus or minus 20 degrees200−200 s5 s10 s

CHANGE THE EXPERIMENT

Catch the lean.

The cart accelerates under the mass, then returns toward the origin. Increase the initial lean or restrict the actuator to see where this balance controller runs out of authority.

Preparing simulation…

A push adds 2 N for 100 ms at t = 2 s. Slider changes reset the experiment. The 5 ms value is simulated controller time, not a browser timing guarantee.

Model assumptions, equations & controller

Point mass, massless rod

Cart mass M = 0.8 kg; pendulum mass m = 0.2 kg; pivot-to-mass length l = 0.35 m; cart viscous friction b = 0.08 N·s/m; gravity g = 9.81 m/s². Positive θ leans toward positive cart travel.

No swing-up, sensor noise, motor dynamics, backlash, or estimator. All four states are available to the controller. The experiment stops at ±0.75 m travel or ±60° tilt; these are illustrative limits.

The model behind the animation

D = M + m sin²(θ)
ẍ = [u − b ẋ + ml θ̇² sin(θ)
     − mg sin(θ) cos(θ)] / D
θ̈ = [g sin(θ) − ẍ cos(θ)] / l

state = [x, ẋ, θ, θ̇]ᵀ
u[k] = clamp(−K state[k], −Fmax, Fmax)

Pole placement uses the upright linearization with design poles −1.5, −2, −4, −5 rad/s. The nonlinear plant uses 1 ms RK4 integration; the controller updates every 5 ms with a zero-order hold. Linear stability does not establish a global balance region.

MOVE THE EXECUTION BOUNDARY

What runs where?

The algorithm stays recognizable as the test changes. Select a stage to see what is simulated, what is real, and which interfaces need to be engineered.

DEVELOPMENT COMPUTER

Controller

Sampled state feedback and force saturation run alongside the plant model.

states → −K → saturation → force
Model signals

SI-unit states and force command; no physical I/O.

DEVELOPMENT COMPUTER

Plant model

The nonlinear cart-pole equations reproduce motion and return the state vector.

force → dynamics → states

Evidence to collect: angle recovery, rail travel, saturation, and repeatable disturbance response across a defined test envelope.

This switch explains an architecture. The live experiment above remains a browser simulation in every mode.

THREE DEPLOYMENT PATHS

Same control intent.
Different target integration.

Keep the plant, controller, and hardware adapters separate. Target-specific I/O, scheduling, build tools, and calibration complete the path to the bench.

MODEL TO REAL-TIME APPLICATION

Speedgoat + Simulink Real-Time

Official workflow reference

    The bench is part of the system.

    Encoders and state estimation · motor drive and force/current scaling · analog, digital or CAN I/O · deterministic task scheduling · rail and tilt limits · watchdog and emergency stop · calibration and logged measurements

    Illustrative workflows, not claims of completed deployments, certification, or vendor partnership. Hardware, I/O options, software releases, and licenses must be selected together. A shared algorithm does not make target binaries or I/O configuration interchangeable.

    TOOLS & PLATFORMS

    From virtual vehicle
    to instrumented bench.

    Connect vehicle simulation, controller development, and CAN communications. These tools complement MATLAB/Simulink and the real-time prototyping workflow, with interfaces selected for the project.

    Vehicle simulation

    Develop repeatable virtual driving scenarios and evaluate controller behavior with vehicle and environment models. Connect scenario inputs, control decisions, and system responses before moving to a physical test.

    Integrate vehicle-dynamics models with Simulink to evaluate control strategies, compare responses across maneuvers, and understand how vehicle behavior affects controller performance.

    CAN integration
    & diagnostics

    CAN tools

    Capture and interpret bus traffic, decode signals using DBC definitions, check message timing, and troubleshoot communications between controllers, sensors, and test equipment.

    PCAN-Explorer

    Platform reference

    Monitor CAN messages, transmit test traffic, visualize signals, and record communication traces. Use the observed bus behavior to investigate integration issues and compare commands with reported responses.

    Engineering outputs: repeatable simulation scenarios, controller-response comparisons, interpreted CAN traces, and documented signal interfaces.

    Explore the real-time hardware workflow

    OPEN THE IMPLEMENTATION

    From equations
    to an execution step.

    Inspect the browser model, reproduce the controller design in MATLAB, and compare a compact C reference. Each artifact has an explicit role.

    The controller model boundary

    Conceptual discrete controller: state input passes through a negative K matrix gain and force saturation to a force output. All blocks execute at a five millisecond sample period.state[4]Gain: −KSaturation: ±Fmaxforce [N]Discrete controller · Ts = 0.005 s

    Scroll the diagram horizontally to inspect each block.

    Conceptual Simulink subsystem structure. The plant stays outside the generated controller; target adapters provide the state input and consume the force command. A real rig also needs estimation and supervision.

    Download source
    pendulum-model.mjs
    Loading source…

    Where autocode fits

    In Simulink, isolate the controller as a discrete subsystem: state input, matrix gain, saturation, force output. Retain this interface while the deployment wrapper supplies sensors, scheduling, and actuator commands.

    Generate, then verify

    Use the selected target’s supported build workflow to generate and compile the application. Compare generated-controller outputs against the model using the same input vectors (SIL/PIL where supported), then validate timing and I/O on hardware.

    What these files demonstrate

    The JavaScript is the running browser model. MATLAB reproduces the gain design and checks sampled linear stability. The C file is handwritten equivalent control logic, not generated output. No Simulink .slx model or target binary is included.

    CLOSE THE ENGINEERING LOOP

    The deliverable is more
    than a balanced pendulum.

    A model you can inspect. Plant assumptions, controller structure, sample times, and units.

    A build you can reproduce. Versioned model and parameters, target configuration, toolchain versions, and generated-code traceability.

    A result you can measure. Model-to-code agreement, worst-case execution time, sample jitter, calibrated I/O, and limit-handling evidence.

    Discuss your prototyping setupExplore the filtering and PID demos