Ball and Beam: Deploy Controller to Hardware

Implement the V-model for control system design, deployment and testing. Model your system in SystemModeler, then design a controller in the Wolfram Language. Use the Microcontroller Kit to generate automated code and deploy it into a microcontroller. Subsequently, validate your standalone model with the control targets. This example shows how to design, deploy and test a PID controller to balance a ball on a beam.

To run this example, you'll need

The latest versions of SystemModeler and Mathematica.

Please make a selection:

Get a
free trial
with download

The Model

The ball and beam arrangement is modeled in SystemModeler to get a linearized state-space representation of the relationship between the position of the ball and the beam angle. This relationship is then used to auto-tune the parameters of the PID controller in the Wolfram Language.

Model the system in SystemModeler

Model the ball and beam arrangement.

Model of the ball and beam arrangement.

Calibrate Components

The various hardware components are calibrated, and their transfer function is obtained. Subsequently, these transfer functions are connected, and a feedback model with the PID controller is designed.

Calibrate your components

Use the ModelPlug library to calibrate the servo, IR sensor and potentiometers.

Schematic representation of the PID controller and the related hardware components.

Deploy to Hardware

Define your machine-specific settings to communicate with the Arduino UNO board and set up the servo library and connections to pins on the Arduino. Finally, define a sampling period and deploy the controller into the Arduino UNO board.

Deploy controller to hardware in the Wolfram Language

Use the Microcontroller Kit to deploy the controller to hardware.

Ball and beam model in action.