Model-Based Design For Embedded Control Systems: White Paper
Model-Based Design For Embedded Control Systems: White Paper
Model-Based Design For Embedded Control Systems: White Paper
Model-Based Design
for Embedded Control Systems
Model-Based Design for Embedded Control Systems
I magine that your team is developing controls to actuate part of a robotic system. The system is driven by an
electric motor with velocity control. Before you begin the design, you want to address some key questions—
for example:
• How do we size the motors?
• What if the requirements change?
• How can we optimize the design to ensure the desired performance?
• How can we test the design thoroughly while minimizing risk?
Whether you’re developing controls for an industrial robot, a wind turbine, a production machine, an autonomous
vehicle, an excavator, or an electric servo drive, if your team is manually writing code and using document-based
requirements capture, the only way to answer these questions will be through trial and error or testing on a physical
prototype. And if a single requirement changes, the entire system will have to be recoded and rebuilt, delaying the
project by days, or even weeks.
Using Model-Based Design with MATLAB® and Simulink®, instead of handwritten code and documents, you create a
system model—in the case of the industrial robot, a model comprising the robot arm, the motors, and the controller
design. You can simulate the model at any point to get an instant view of system behavior and to test out multiple
what-if scenarios without risk, without delay, and without reliance on costly hardware.
This white paper introduces Model-Based Design and provides tips and best practices for getting started. Using real-
world examples, it shows how teams across industries have adopted Model-Based Design to reduce development
time, minimize component integration issues, and deliver higher-quality products.
W H I T E PA P E R | 2
Model-Based Design for Embedded Control Systems
As this scenario shows, Model-Based Design uses the same elements as traditional development workflows, but with
two key differences:
• Many of the time-consuming or error-prone steps in the workflow—for example, code generation—are
automated.
• A system model is at the heart of development, from requirements capture through design, implementation,
and testing.
RESEARCH REQUIREMENTS
DESIGN
IMPLEMENTATION
INTEGRATION
W H I T E PA P E R | 3
Model-Based Design for Embedded Control Systems
The Embraer Legacy 500 is the first midsized business jet with intelligent flight controls and full fly-by-wire technology. This
technology, which replaces mechanical controls in the flight control system (FCS), enables more control surfaces to be actu-
ated simultaneously, leading to smoother flights, reduced pilot workloads, and increased safety.
Embraer worked with customers to develop high-level requirements for the Legacy 500. A principal challenge was translat-
ing the high-level requirements into well-written low-level requirements for the supplier who would develop the FCS
software.
Early designs were developed without the intensive use of modeling and simulation. As a result, requirements sometimes
had to be rewritten after they were delivered to the supplier, wasting time and increasing costs.
Embraer engineers decided to use Model-Based Design to define the low-level requirements for the Legacy 500 FCS. They
created a detailed model of the FCS, as well as models of the aircraft dynamics and pilot inputs. The complete model com-
prises more than a million blocks and dozens of components, many with more than 700 inputs and 500 outputs.
They created functional test cases, which they ran on the model to verify that the high-level requirements were being met
and to validate the low-level requirements. Embraer then delivered the written requirements to the supplier, who performed
their own validation before implementing the system according to DO-178 Level A and other aviation standards.
Design
In a traditional approach, every design idea must be coded and tested on a physical prototype. As a result, only a
limited number of design ideas and scenarios can be explored because each test iteration adds to the project develop-
ment time and cost.
In Model-Based Design, the number of ideas that can be explored is virtually limitless. Requirements, system com-
ponents, IP, and test scenarios are all captured in your model, and because the model can be simulated, you can
investigate design problems and questions long before building expensive hardware. You can quickly evaluate multi-
ple design ideas, explore tradeoffs, and see how each design change affects the system.
W H I T E PA P E R | 4
Model-Based Design for Embedded Control Systems
The Ather 450 intelligent electric scooter. Most of Bangalore’s more than 5 million two-wheeled scoot-
ers—about 70% of all vehicles in the city—are
petrol-powered, resulting in high levels of noise pollution and CO2 emissions. To meet the demand for cleaner alternatives,
startup company Ather Energy has built India’s first intelligent electric scooter. Capable of accelerating from 0 to 40 km/h
in less than 4 seconds, the Ather 450 has a top speed of 80 km/h and a range of up to 75 km on a single charge.
Because the 450 would be one of the first of its kind in the market, the team faced numerous unknowns. After building a
plant model comprising the scooter and its main components, they ran simulations to evaluate riding and usage
scenarios—for example, operating the 450 on an incline, with multiple riders, in extreme temperatures, and with a mostly
depleted battery.
They used the simulation results to make informed design tradeoffs; the results showed, for example, that increasing battery
capacity would provide better range, but it would also increase cost and size, as well as alter the scooter’s center of gravi-
ty. They refined the design until they had identified a motor and battery configuration that met the target acceleration and
range requirements while satisfying cost, size, and temperature constraints.
In addition to designing the scooter itself, the engineers developed embedded control algorithms for battery charging,
temperature management, and other key functions. In the absence of detailed component data, the team took an empirical
approach to modeling the battery cells. They tested the battery at various temperatures and state-of-charge levels and used
the measured input-output data to create a black-box model of the cell’s electrical and thermal characteristics.
Next, they developed algorithms for battery charging, power control, and temperature control. They ran closed-loop simu-
lations with the plant model to validate their control design. They generated code from the controller model and deployed
it either to an ARM® Cortex ® processor on the scooter or to a TI C2000™ microcontroller in the charging stations.
The Ather 450 is now in production, with an initial release in Bengaluru as well as 31 charging stations and 7 stations
in Chennai.
W H I T E PA P E R | 5
Model-Based Design for Embedded Control Systems
Code Generation
In a traditional workflow, embedded code must be handwritten from system models or from scratch. Software engi-
neers write control algorithms based on specifications written by control systems engineers. Each step in this
process—writing the specification, manually coding the algorithms, and debugging the handwritten code—
can be both time-consuming and error-prone.
With Model-Based Design, instead of writing thousands of lines of code by hand, you generate code directly from
your model, and the model acts as a bridge between the software engineers and the control systems engineers.
The generated code can be used for rapid prototyping or production.
Rapid prototyping provides a fast and inexpensive way to test algorithms on hardware in real time and perform
design iterations in minutes rather than weeks. You can use prototype hardware or your production ECU. With the
same rapid prototyping hardware and design models, you can conduct hardware-in-the-loop testing and other test
and verification activities to validate hardware and software designs before production.
Production code generation converts your model into the actual code that will be implemented on the production
embedded system. The generated code can be optimized for specific processor architectures and integrated with
handwritten legacy code.
To shorten development time for the control system, the engineering team wanted to generate control code directly from
their models. With just three engineers on the team, and with little previous programming experience, they felt that writing
and debugging the control code by hand would take too long and result in poor quality.
They created plant models of the major system components, including the solar converter, battery DC-DC converter, and
three-phase grid-tied inverter. The team modeled the system’s controller and then ran closed-loop simulations with the con-
troller and the plants. Additional closed-loop simulations were performed to assess the design’s response to abnormal situa-
tions, including blackouts and phase unbalance of the grid.
They generated C code from the controller model and deployed it to a 32-bit microcontroller. The team tested the micro-
controller and EMS circuitry together to verify the code with the production hardware by running open-loop tests to per-
form basic checks and by verifying system closed-loop controller and state transitions.
W H I T E PA P E R | 6
Model-Based Design for Embedded Control Systems
— Claes Lindskog,
Bombardier Transportation
Bombardier train for Germany.
New designs for light rail, metro, commuter, intercity, locomotives, and high-speed trains must meet the specific needs of
the cities or regions the vehicles will serve. In addition, software systems for these vehicles must comply with local and
country-specific regulations, as well as with industry standards such as EN 50128 and EN 50657.
In the rail transportation industry, system tests often cannot be performed until a complete vehicle is built and on tracks.
Engineers at Bombardier Transportation shortened lead times and reduced development costs for the company’s MITRAC
propulsion and control systems by adopting Model-Based Design with MATLAB and Simulink.
Before they adopted Model-Based Design, Bombardier followed a traditional waterfall workflow for control software devel-
opment: One team was responsible for the requirements and design, which would be handed off to a second team for
implementation via traditional manual coding. Most testing was done in a hardware-in-the-loop environment followed by a
combined hardware/software system test, and some tests had to be conducted on the train itself. If errors were discovered
late in this process, it could lead to weeks or even months of costly rework and delays.
Now that they have adopted Model-Based Design, Bombardier engineers configure and adapt control models to satisfy
customer-defined requirements captured in IBM® Rational® DOORS® or Microsoft ® Word documents. They then create elec-
trical hardware (plant) models of the propulsion systems and run closed-loop simulations to validate requirements, verify
functionality, and assess controller performance. In one instance, the team created an electrical and control system model
in MATLAB and Simulink. By simulating the model, they identified an electrical fault that typically would not have been
found until a combined system test.
W H I T E PA P E R | 7
Model-Based Design for Embedded Control Systems
Getting Started
While your team might see the benefits of moving to Model-Based Design, they might also be concerned about the
risks and challenges—organizational, logistical, and technical—that could be involved. This section addresses ques-
tions frequently asked by engineering teams considering adopting Model-Based Design and provides tips and best
practices that have helped many of these teams manage the transition.
• Build on your initial modeling success by adding system-level simulation. As previous sections of this paper
have shown, you can use system simulation to validate requirements, investigate design questions, and conduct
early test and verification. The system model does not need to be high-fidelity; it just needs to have enough
detail to ensure that interfacing signals have the right units and are connected to the right channels, and that
the dynamic behavior of the system is captured. The simulation results give you an early view of how the plant
and controller will behave.
W H I T E PA P E R | 8
Model-Based Design for Embedded Control Systems
• Use models to solve specific design problems. Your team can gain targeted benefits even without developing
full-scale models of the plant, environment, and algorithm. For example, suppose your team needs to select
parameters for a solenoid used for actuation. They can develop a simple model that draws a conceptual “con-
trol volume” around the solenoid, including what drives it and what it acts upon. The team can test various
extreme operating conditions and derive the basic parameters without having to derive the equations. This
model can then be stored for use on a different design problem or in a future project.
• Begin with the core elements of Model-Based Design. The immediate benefits of Model-Based Design
include the ability to create component and system models, use simulations to test and validate designs, and
generate C code automatically for prototyping and testing. Later, you can consider advanced tools and practic-
es and introduce modeling guidelines, automated compliance checking, requirements traceability, and soft-
ware build automation.
To help meet increased demand for its products, the Danfoss power elec-
tronics group hired new engineers and re-evaluated its embedded software
development processes, which up to then had relied on manual coding.
With a traditional development process and manual coding, errors
The Danfoss VLT® AutomationDrive FC302.
remained undetected until hardware prototype and certification testing.
While Danfoss knew they needed a new process, they were worried that adopting Model-Based Design would jeopardize
deadlines. Bringing the team up to speed would take time. In addition, work on a new product, a solar inverter, had already
begun. Model-Based Design would have to be introduced during development, and without affecting project deadlines.
Working with MathWorks consultants, Danfoss first developed a plan to ensure successful adoption of Model-Based Design.
Danfoss engineers attended on-site training courses on Simulink, Stateflow ®, and Embedded Coder ® led by MathWorks
engineers.
The team then completed a pilot project in which they rebuilt an existing software component that had been coded by hand.
For the pilot, they decided to focus on three core capabilities of Model-Based Design: modeling, simulation, and code gener-
ation. After completing the pilot project, the team fully transitioned to Model-Based Design for development of the new solar
inverter.
In weekly phone calls, MathWorks consultants advised them on the best way to get started, provided feedback on early ver-
sions of the models, and helped the team apply industry best practices to maximize model reuse and improve generated
code performance.
The team completed development on schedule, and the test and certification campaign progressed smoothly due to the
extensive simulations the team had performed in preparation.
Now that they have demonstrated the success of the new workflow, more engineers are involved in Model-Based Design
across the organization, and they have built a library of models and a knowledge base that can be reused on future
projects.
W H I T E PA P E R | 9
Model-Based Design for Embedded Control Systems
Summary
A system model is at the center of development, from requirements capture to design, implementation, and testing.
That’s the essence of Model-Based Design. With this system model you can:
• Link designs directly to requirements
• Collaborate in a shared design environment
• Simulate multiple what-if scenarios
• Optimize system-level performance
• Automatically generate embedded software code, reports, and documentation
• Detect errors earlier by testing earlier
“Three years ago, SAIC Motor did not have rich experience developing embedded control software. We chose
Model-Based Design because it is a proven and efficient development method. This approach enabled our team
of engineers to develop highly complex HCU control logic and complete the project ahead of schedule.”
Foundation Products
MATLAB®
Analyze data, develop algorithms, and create mathematical models
Simulink®
Model and simulate embedded systems
W H I T E PA P E R | 10
Model-Based Design for Embedded Control Systems
Design
Simulink Control Design™
Linearize models and design control systems
Stateflow®
Model and simulate decision logic using state machines and flow charts
Simscape™
Model and simulate multidomain physical systems
Code Generation
Simulink Coder™
Generate C and C++ code from Simulink and Stateflow models
Embedded Coder®
Generate C and C++ code optimized for embedded systems
HDL Coder™
Generate VHDL and Verilog code for FPGA and ASIC designs
W H I T E PA P E R | 11
Model-Based Design for Embedded Control Systems
Learn More
mathworks.com has a range of resources to help you ramp up quickly with Model-Based Design.
We recommend that you begin with these:
Interactive Tutorials
MATLAB Onramp
Simulink Onramp
Stateflow Onramp
Webinars
Simulink for New Users (54:07)
Model-Based Design of Control Systems (54:59)
Accelerating the Pace and Scope of Control System Design (51:03)
Modeling, Simulating, and Generating Code for a Solar Inverter (45:00)
Additional Resources
Consulting Services
© 2019 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See mathworks.com/trademarks for a list of additional trademarks.
Other product or brand names may be trademarks or registered trademarks of their respective holders.
W H I T E PA P E R | 12