Main Content

AUTOSAR-Based FOC of PMSM

This example shows how to implement an AUTOSAR-based field-oriented control (FOC) algorithm to run a permanent magnet synchronous motor (PMSM).

Automotive open system architecture (AUTOSAR), is an open and standardized automotive software architecture, jointly developed by automobile manufacturers, suppliers, and tool developers. AUTOSAR defines a standardized software architecture for automotive electronic control units (ECUs). A standardized software architecture helps original equipment manufacturers (OEMs) and software suppliers in creating reusable software with scalability across different vehicles and automotive platforms. The framework also enables smooth and seamless collaboration between manufacturing partners and suppliers. In addition, compliance with AUTOSAR standards reduces software maintenance efforts throughout the product life cycle. AUTOSAR standards ensure safety and increase robustness of automotive applications.

AUTOSAR-based motor control system software enables electrical vehicle manufacturers, suppliers, and partners to take advantage of these benefits. For more information, see AUTOSAR Standard (AUTOSAR Blockset) and What is AUTOSAR? (AUTOSAR Blockset).

This example shows how a motor control system that you model in Simulink® using Motor Control Blockset™ integrates with the AUTOSAR Classic Platform (CP).

This image shows where you can position the motor control algorithm within AUTOSAR's Classic Platform solution.

This example uses Motor Control Blockset™, AUTOSAR Blockset, and System Composer to develop the software architecture using model-based design in Simulink. You can use these products to create software compositions. A software composition is a group of components.

This example enables you to simulate a software composition. Each component in this software composition acts as a model reference to a Simulink model. You can also use this example to generate AUTOSAR code for the following layers:

  • Application layer — Encloses higher-level speed control algorithm of the motor control system.

  • Complex drivers — Encloses lower-level torque or current control algorithm of the motor control system.

You can then integrate the generated production AUTOSAR code with basic software (BSW) stack.

Note: The software composition in this example includes only the components required to implement a motor control algorithm.

What are complex drivers?

A complex device drivers (CDD) is a specific module located in the complex drivers layer of the BSW that interacts with the standard BSW modules or run time environment (RTE).

The complex drivers layer can integrate with other AUTOSAR layers using standard AUTOSAR interfaces as well as basic software modules (BSM) APIs.

With direct access to a microcontroller, you can use this layer to perform complex sensor read and evaluation operations as well as actuator control operations using specific interrupts, complex microcontroller peripherals, and external devices (such as communication transceivers and ASIC) to fulfil specialized functional and timing-related requirements.

Why is motor current control part of complex drivers layer?

The current control loop in any motor control algorithm is very time sensitive. The loop needs precise synchronization with hardware peripherals such as analog-to-digital converter (ADC) and pulse-width modulator (PWM) for accurate current and position sensor measurements.

With direct access to the microcontroller abstraction layer (MCAL), the complex drivers layer enables the motor control algorithm to configure ADC-PWM synchronization accurately. Using BSM APIs from other layers does not always provide this access.

Open MATLAB Project

The example is packaged as a MATLAB® project. Use one of these methods to open the MATLAB project window:

  • Click Open Project.

  • Run the following command to access the supporting files of the example and open the MATLAB project.

openExample('mcb/AUTOSARBasedPMSMFOCExample');

Model

The MATLAB project has an integModels folder that includes the model mcb_AUTOSAR_System.slx.

This model contains the following entities:

  • MCU — Software composition that encloses software for the microcontroller.

  • InverterAndMotor — Component that models a plant containing a motor and an inverter. This component acts as a replica of an actual inverter and motor setup for simulation purposes.

Simulating a real plant helps you perform extensive tests and validation with ease, which helps you identify and fix issues prior to deploying the algorithm to hardware and operating the motor. Simulating a real plant also helps you troubleshoot problems and reproduce operating conditions that are hard to reproduce using a physical hardware setup.

MCU (microcontroller software) contains these entities:

  • AUTOSAR — The AUTOSAR-based controller software that includes these software components:

          - motorControlApplication — The application layer containing the high-level motor speed control algorithm. This acts as the outer field-oriented control (FOC) loop that controls the speed of a permanent magnet synchronous motor (PMSM) using a proportional integral (PI) controller. This loop usually runs at a slower rate than the inner loop controlling the motor torque.

          - ComplexDeviceDriver — The complex drivers layer containing the low-level motor torque or current control algorithm. This acts as the inner FOC loop of PMSM that controls the torque by controlling the motor currents using two separate PI controllers (for d- and q-axis currents). This loop usually runs at a faster rate than the outer loop controlling the motor speed.

For more information about FOC, see Field-Oriented Control (FOC).

Required MathWorks Products

To simulate the software composition, you need these products:

  • Motor Control Blockset

  • AUTOSAR Blockset

  • System Composer

To generate code from the software composition, you need these products:

  • Motor Control Blockset

  • AUTOSAR Blockset

  • System Composer

  • Embedded Coder®

  • Fixed-Point Designer™ (needed only for optimized code generation)

Prerequisites

1. Obtain the motor and inverter parameters. The MATLAB project uses default motor and inverter parameters that you can replace with values from the motor and inverter datasheets or from other sources.

Optionally, if you have the actual motor, you can estimate the parameters for the motor that you want to use with the motor control hardware by using the Motor Control Blockset parameter estimation tool. For instructions, see Estimate PMSM Parameters Using Recommended Hardware. The parameter estimation tool updates the motorParam variable (in the MATLAB workspace) with the estimated motor parameters.

2. Update the motor and inverter parameters in the StartUp.m parameter script (available in the scripts folder in the Project window) associated with the software composition.

3. Click Run on the Editor tab to run the parameter script.

Simulate Model

Complete these steps to simulate the software composition included in the project:

1. Open the software composition mcb_AUTOSAR_System.slx from the model folder included in the MATLAB project.

2. Click Run on the Simulation tab to validate the motor operation.

Generate Code for Integration with AUTOSAR-Based Software

This section shows how to generate AUTOSAR code for the motorControlApplication and ComplexDeviceDrivers software components that you can integrate with your BSW for a motor control application such as that of an electric vehicle.

1. Open the software composition mcb_AUTOSAR_System.slx from the integModels folder included in the MATLAB project.

2. Navigate to mcb_AUTOSAR_System/MCU/AUTOSAR (mcb_AUTOSAR) and select the CDDTorqueControl software component.

3. In the Modeling tab of the Simulink toolstrip, click Export > Generate Code and ARXML.

4. Select the export options in the Export Component window and click OK to generate the AUTOSAR code.

5. Navigate to mcb_AUTOSAR_System/MCU/AUTOSAR (mcb_AUTOSAR) and select the Appl_CruiseControl software component.

6. Repeat steps 3 and 4 for the Appl_CruiseControl software component.

Reference