Frequently asked questions

Need technical support?

How Can I Implement a PID Controller Using the Controller.h?

Question

Can I use the Controller.h in the include directory in order to implement a controller into my user code?

Solution

With the Controller.h (default location: C:\IPG\carmaker\win64-\include), the CarMaker installation offers a library to include controllers such as P-, PI-, or PID-controllers into your user code.
Actual value and target value of the controlled signal and the controller P-, I-, and D-values have to be send to the library, which will do the integration and differentiation for you and send back the output, which you can assign to the control signal.

The attached project contains an example User.c (commented), vehicle info file and TestRun that shows the implementation of a PID controller controlling the vehicle speed via the gas pedal position.

It offers a UAQ ‘Target Speed’ that set the target speed for the controller. In the additional parameters of the vehicle, controller characteristics can be set like P, I, D-value, tolerance, lower and upper limit for the control signal, which is DM.Gas. The controlled signal is Car.v.

All additional parameters:

PP-value (default 25)
II-value (default 0.00001)
DD-value (default 0.0001)
Tolerancetolerance of controlled signal (default 0)
lowerLimitlower limit of control signal (default 0)
upperLimitupper limit of control signal (default 1)

 

 

 



 

 

In User.c:

  • A handle for the struct and a variable for a UAQ to define the target speed at the top (lines 105-106)
  • A UAQ is created in User_DeclQuants (line 242)
  • The additional vehicle parameters are read in and assigned to the array vec, which is later internally read by the controller, in User_TestRun_Start_atEnd (lines 401-408)
  • Memory for a variable of the struct tCtrl is allocated in User_TestRun_Start_atEnd (line 410)
  • The controller is initialized in User_TestRun_Start_atEnd (line 411) using the function Ctrl_Init from Controller.h
  • The target for the controller is set in User_Calc (line 638) using the function Ctrl_SetTarget from Controller.h
  • The actual value of the controlled signal (Car.v) is passed to the controller in User_Calc (line 639) using the function Ctrl_Calc from Controller.h
  • The output of the controller is passed to DM.Gas in User_Calc (line 640)
  • The controller is deleted in User_TestRun_End (line 513)
  • Memory is released in User_TestRun_End (line 514)

 

Download: ControllerHeader.zip

Need technical support?
  • Date: 30.04.2021
  • Product: CarMaker
  • Version: 9.1
  • Component: C-Code Interface
  • Language: English

Tags

PID
Speed Controller
User Models