Controller
Sampled state feedback and force saturation run alongside the plant model.
states → −K → saturation → forceTHE RAPID PROTOTYPING LAB
Balance a pendulum. Follow the controller from simulation to generated code, real-time I/O, and a physical test bench.
A CONNECTED ENGINEERING WORKFLOW
Reuse the control algorithm.
Adapt the execution platform and interfaces.
START WITH THE DYNAMICS
An unstable equilibrium makes the engineering visible: sample timing, state feedback, actuator saturation, and the difference between an equation and a working controller.
CHANGE THE EXPERIMENT
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.
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.
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
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.
Sampled state feedback and force saturation run alongside the plant model.
states → −K → saturation → forceSI-unit states and force command; no physical I/O.
The nonlinear cart-pole equations reproduce motion and return the state vector.
force → dynamics → statesEvidence 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
Keep the plant, controller, and hardware adapters separate. Target-specific I/O, scheduling, build tools, and calibration complete the path to the bench.
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
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.
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.
Capture and interpret bus traffic, decode signals using DBC definitions, check message timing, and troubleshoot communications between controllers, sensors, and test equipment.
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 workflowOPEN THE IMPLEMENTATION
Inspect the browser model, reproduce the controller design in MATLAB, and compare a compact C reference. Each artifact has an explicit role.
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.
Loading source…
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.
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.
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
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.