/*
* File: PID_control.c
*
* Code generated for Simulink model 'PID_control'.
*
* Model version : 1.1
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Tue Jul 9 16:54:27 2019
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "PID_control.h"
/* Invariant block signals (default storage) */
const ConstB_PID_control_T PID_control_ConstB = {
0.1, /* '<S6>/Gain' */
0.010000000000000002, /* '<S6>/Math Function' */
0.25, /* '<S6>/Gain1' */
0.0625, /* '<S6>/Math Function1' */
0.072500000000000009, /* '<S6>/Add' */
0.26925824035672524, /* '<S6>/Sqrt' */
0.3805063771123649, /* '<S6>/Trigonometric Function' */
0.9284766908852593, /* '<S301>/Trigonometric Function1' */
0.37139067635410372, /* '<S301>/Trigonometric Function2' */
0.9284766908852593, /* '<S299>/Trigonometric Function' */
0.37139067635410372, /* '<S299>/Trigonometric Function1' */
0.37139067635410372, /* '<S302>/Trigonometric Function2' */
0.9284766908852593, /* '<S302>/Trigonometric Function1' */
0.9284766908852593, /* '<S300>/Trigonometric Function' */
0.37139067635410372 /* '<S300>/Trigonometric Function1' */
};
/* Block signals (default storage) */
B_PID_control_T PID_control_B;
/* Block states (default storage) */
DW_PID_control_T PID_control_DW;
/* External inputs (root inport signals with default storage) */
ExtU_PID_control_T PID_control_U;
/* External outputs (root outports fed by signals with default storage) */
ExtY_PID_control_T PID_control_Y;
/* Real-time model */
RT_MODEL_PID_control_T PID_control_M_;
RT_MODEL_PID_control_T *const PID_control_M = &PID_control_M_;
static void PID_cont_FunctionCallSubsystem2(real_T rtu_In1, real_T rtu_In2,
real_T *rty_Out1, real_T *rty_Out1_n);
static void PID_cont_FunctionCallSubsystem1(real_T rtu_In1, real_T rtu_In2,
real_T *rty_Out1, real_T *rty_Out1_j);
/*
* Output and update for action system:
* '<S7>/Function-Call Subsystem2'
* '<S309>/Function-Call Subsystem1'
* '<S316>/Function-Call Subsystem1'
*/
static void PID_cont_FunctionCallSubsystem2(real_T rtu_In1, real_T rtu_In2,
real_T *rty_Out1, real_T *rty_Out1_n)
{
/* Sum: '<S305>/Subtract' incorporates:
* Constant: '<S305>/Constant'
*/
*rty_Out1_n = rtu_In2 + 3.1415926535897931;
/* Gain: '<S305>/Gain' */
*rty_Out1 = -rtu_In1;
}
/*
* Output and update for action system:
* '<S311>/Function-Call Subsystem1'
* '<S318>/Function-Call Subsystem1'
*/
static void PID_cont_FunctionCallSubsystem1(real_T rtu_In1, real_T rtu_In2,
real_T *rty_Out1, real_T *rty_Out1_j)
{
/* Sum: '<S314>/Subtract' incorporates:
* Constant: '<S314>/Constant'
*/
*rty_Out1_j = rtu_In2 - 3.1415926535897931;
/* Gain: '<S314>/Gain' */
*rty_Out1 = -rtu_In1;
}
/* Model step function */
void PID_control_step(void)
{
real_T rtb_Add_li;
real_T rtb_Add1_h;
real_T rtb_TrigonometricFunction;
real_T rtb_MathFunction;
real_T rtb_Subtract_j;
real_T rtb_Subtract_p;
/* Gain: '<S6>/Gain3' incorporates:
* Gain: '<S178>/Proportional Gain'
* Inport: '<Root>/Y_act'
* Inport: '<Root>/Y_aim'
* Sum: '<S5>/Subtract1'
*/
rtb_Add_li = (PID_control_U.Y_aim - PID_control_U.Y_act) * 0.5 * 0.001;
/* Product: '<S301>/Product' incorporates:
* Gain: '<S274>/Proportional Gain'
* Inport: '<Root>/theta_act'
* Inport: '<Root>/theta_aim'
* Product: '<S299>/Product'
* Product: '<S300>/Product'
* Product: '<S302>/Product'
* Sum: '<S5>/Subtract2'
*/
rtb_Subtract_p = (PID_control_U.theta_aim - PID_control_U.theta_act) * 0.0 *
PID_control_ConstB.Sqrt;
/* Gain: '<S6>/Gain2' incorporates:
* Gain: '<S82>/Proportional Gain'
* Inport: '<Root>/X_act'
* Inport: '<Root>/X_aim'
* Sum: '<S5>/Subtract'
*/
rtb_Add1_h = (PID_control_U.X_aim - PID_control_U.X_act) * 0.5 * 0.001;
/* Trigonometry: '<S301>/Trigonometric Function' incorporates:
* Product: '<S301>/Divide'
* Product: '<S301>/Product'
* Product: '<S301>/Product1'
* Product: '<S301>/Product2'
* Sum: '<S301>/Add'
* Sum: '<S301>/Add1'
*/
rtb_TrigonometricFunction = atan((rtb_Subtract_p *
PID_control_ConstB.TrigonometricFunction1 + rtb_Add_li) /
(PID_control_ConstB.TrigonometricFunction2 * rtb_Subtract_p + rtb_Add1_h));
/* Sum: '<S299>/Add' incorporates:
* Product: '<S299>/Product1'
*/
PID_control_Y.velocity_rear = rtb_Subtract_p *
PID_control_ConstB.TrigonometricFunction_i + rtb_Add_li;
/* Math: '<S299>/Math Function' */
rtb_MathFunction = PID_control_Y.velocity_rear * PID_control_Y.velocity_rear;
/* Sum: '<S299>/Add1' incorporates:
* Product: '<S299>/Product2'
*/
PID_control_Y.velocity_rear = PID_control_ConstB.TrigonometricFunction1_j *
rtb_Subtract_p + rtb_Add1_h;
/* Gain: '<S6>/Gain4' incorporates:
* Math: '<S299>/Math Function1'
* Sqrt: '<S299>/Sqrt'
* Sum: '<S299>/Add2'
*/
rtb_MathFunction = sqrt(PID_control_Y.velocity_rear *
PID_control_Y.velocity_rear + rtb_MathFunction) * 1000.0;
/* If: '<S7>/If' */
if (rtb_TrigonometricFunction > 2.0) {
/* Outputs for IfAction SubSystem: '<S7>/Function-Call Subsystem' incorporates:
* ActionPort: '<S303>/Action Port'
*/
/* Sum: '<S303>/Subtract' incorporates:
* Constant: '<S303>/Constant'
*/
PID_control_B.Merge[1] = rtb_TrigonometricFunction - 3.1415926535897931;
/* Gain: '<S303>/Gain' */
PID_control_B.Merge[0] = -rtb_MathFunction;
/* End of Outputs for SubSystem: '<S7>/Function-Call Subsystem' */
} else if (rtb_TrigonometricFunction < -2.0) {
/* Outputs for IfAction SubSystem: '<S7>/Function-Call Subsystem2' incorporates:
* ActionPort: '<S305>/Action Port'
*/
PID_cont_FunctionCallSubsystem2(rtb_MathFunction, rtb_TrigonometricFunction,
&PID_control_B.Merge[0], &PID_control_B.Merge[1]);
/* End of Outputs for SubSystem: '<S7>/Function-Call Subsystem2' */
} else {
/* Outputs for IfAction SubSystem: '<S7>/Function-Call Subsystem1' incorporates:
* ActionPort: '<S304>/Action Port'
*/
/* Sum: '<S304>/Subtract' incorporates:
* Inport: '<Root>/theta_front_wheel'
*/
rtb_Subtract_j = rtb_TrigonometricFunction - PID_control_U.theta_front_wheel;
/* If: '<S304>/If' incorporates:
* Inport: '<S310>/In1'
* Inport: '<S310>/In2'
*/
if (rtb_Subtract_j > 1.57) {
/* Outputs for IfAction SubSystem: '<S304>/Function-Call Subsystem3' incorporates:
* ActionPort: '<S311>/Action Port'
*/
/* If: '<S311>/If' incorporates:
* Constant: '<S311>/Constant'
* Inport: '<S315>/In1'
* Inport: '<S315>/In2'
* Sum: '<S311>/Add'
*/
if (rtb_TrigonometricFunction - 3.1415926535897931 < -2.0) {
/* Outputs for IfAction SubSystem: '<S311>/Function-Call Subsystem3' incorporates:
* ActionPort: '<S315>/Action Port'
*/
PID_control_B.Merge[0] = rtb_MathFunction;
PID_control_B.Merge[1] = rtb_TrigonometricFunction;
/* End of Outputs for SubSystem: '<S311>/Function-Call Subsystem3' */
} else {
/* Outputs for IfAction SubSystem: '<S311>/Function-Call Subsystem1' incorporates:
* ActionPort: '<S314>/Action Port'
*/
PID_cont_FunctionCallSubsystem1(rtb_Ma