Challenge

Project 2 Adaptive Cruise Control

Adaptive Cruise Control

AIM:

To develop an Adaptive Cruise Control MATLAB Simulink model as per requirement and initialize the input and output based on the requirements, tag the requirements to the Simulink model (tagging requirements to their corresponding subsystems), and also create the corresponding Data Dictionary & generate the code.

Procedure:

  1. Creating  subsystems as per the given instructions in requirement document.
  2. Attaching the requirement document.
  3. Creating a Simulink data dictionary (SLDD). 
  4. Generating a model advisor report (With necessary tests selected).
  5. Generation of code.

General Overview:

Adaptive Cruise Control Feature for passenger cars allows the host vehicle to adapt to the speed in line with the flow of traffic. Driving in heavy traffic or keeping a safe distance to the preceding vehicle calls for a high level of concentration. The Adaptive Cruise Control feature can reduce the stress on the driver by automatically controlling the vehicle speed & maintaining a predefined minimum distance to the preceding vehicle. As a consequence, the driver enjoys more comfort & can concentrate on the road little better.

A radar sensor is usually at the core of the Adaptive Cruise Control. Installed at the front of the vehicle, the system permanently monitors the road ahead. As long as the road ahead is clear, cruise control feature maintains the speed set by the driver. If the system spots a slower vehicle within its detection range, it gently reduces speed by releasing the accelerator or actively engaging the brake control system. If the vehicle ahead speeds up or changes lanes, the cruise control automatically accelerates to the driver’s desired speed.

Standard Adaptive Cruise Control can be activated from speeds of around 30 km/h (20 mph) upwards and supports the driver, primarily on cross-country journeys or on freeways. The cruise control stop & go variant is also active at speeds below 30 km/h (20 mph). It can maintain the set distance to the preceding vehicle even at very low speeds and can decelerate to a complete standstill. When the vehicle remains stopped longer, the driver needs only to reactivate the system, for example by briefly stepping on the gas pedal to return to cruise control mode. In this way, cruise control stop & go supports the driver even in heavy traffic and traffic jams.

Since Adaptive Cruise Control is a comfort and convenience system, brake interventions and vehicle acceleration only take place within defined limits. Even with Adaptive Cruise Control switched on, it remains the driver’s responsibility to monitor the speed and distance from the vehicle in front.

Objective of Main Project:

  • Developing Adaptive Cruise Control feature as per the Requirement Document using MATLAB Simulink.
  • Follow all the MBD related processes: Requirement Tagging & Traceability, SLDD creation, Configuration Parameter changes, Model Advisor check & Code Generation.
  • In Configuration Parameters: enable “Support Floating Numbers” under Code Generation settings.
  • Use Embedded Coder to generate the code.
  • If choosing code generation, Storage class for Input signals: ImportedExtern; Storage class for Output signal: Export to File; Storage class for local signals: localizable; Storage class for calibration signals: Const.
  • Choose sample time for all signals as 0.01s

Requirement 1– Lead Vehicle:

  • Lead Vehicle is a vehicle which is driving in the road ahead of our drive vehicle. Two input signals (Signal Name: CameraInput_LeadVehicle & RadarInput_LeadVehicle).
  • Ideally sensor fusion techniques will be deployed to process & analyze data from camera & radar. For complexity reasons, let’s not adapt to any such algorithms.
  • We can simply add both the radar & camera inputs & the corresponding output is read as Speed profile output (Signal Name: LeadVehicle_Speed).
  • Speed data of the lead vehicle is critical in implementing the Adaptive Cruise Control algorithm.

Requirement 2 – Drive Vehicle:

  • Drive Vehicle is the vehicle driven by the user & this is the vehicle which has ACC algorithm in it.
  • Like the Lead Vehicle, Drive Vehicle algorithm also has 2 input signals (Signal Name: CameraInput_DriveVehicle, RadarInput_DriveVehicle) & one signal coming as an Input to this subsystem (Signal Name: Acceleration_Mode) – three inputs into this requirement in total.
  • Like the above requirement, sensor fusion techniques will also be deployed here, for complexity reasons we are ignoring them.
  • Two output signals come from this subsystem (Signal Name: DriveVehicle_Speed & LeadVehicle_Detected).
  • Signal DriveVehicle_Speed is summation of three input signals mentioned above & LeadVehicle_Detected is renamed from Input Signal RadarInput_DriveVehicle by mere use of Signal Conversion block.

Requirement 3 – Adaptive Cruise Control Algorithm:

  • Adaptive Cruise Control feature has 3 major modes of operation: OFF Mode, STANDBY Mode & ON Mode. This particular requirement has to be implemented as state machine logic in Simulink.
  • The input signals to this state machine system are (Signal Name: Time_Gap, Set_Speed, Set_Gap, CruiseSwitch, SetSwitch).
  • Also, the output signals (Signal Name: DriveVehicle_Speed & LeadVehicle_Detected) from requirement-2 is fed back as an input signal into this state machine block.
  • Additionally, output signal (Signal Name: LeadVehicle_Speed) from requirement-1 is given as an input signal to this state machine block as well.
  • Output from this subsystem is a signal (Signal Name: Acceleration_Mode) which governs the vehicular speed of the drive vehicle which automatically adjusts its speed & velocity to match the lead vehicle.

Requirement 3a – ACC OFF MODE state logic:

  • This is the default state inside state machine logic. Output signal Acceleration_Mode is at value 0 in this state.
  • This state is governed by input signal CruiseSwitch.
  • If CruiseSwitch is equal to 1, state ACC STANDBY mode will get activated. If CruiseSwitch is equal to 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode

Requirement 3b – ACC STANDBY MODE state logic:

  • This is the second activated state inside state machine logic. Output signal Acceleration_Mode is at value 1 in this state.
  • This state is governed by both input signals CruiseSwitch & SetSwitch.
  • If CruiseSwitch is equal to 1, state ACC STANDBY mode will get activated. If CruiseSwitch is equal to 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode
  • If SetSwitch is equal to 1, state ACC ON mode will get activated. If SetSwitch is equal to 0, state ACC STANDBY mode will get activated.

Requirement 3c – ACC ON MODE state logic:

This state will be activated when input signal SetSwitch is equal to 1. There are 6 sub states to this state logic: They are:

  • LeadVehicle_Detected_Follow (Default)
  • LeadVehicle_Not_Detected
  • LeadVehicle_Detected_Resume
  • LeadVehicle_Not_Detected_Resume
  • LeadVehicle_Speed_lessthan_Set_Speed
  • LeadVehicle_Speed_equal_Set_Speed

Requirement 3c (i) – LeadVehicle_Detected_Follow (ACC ON MODE):

  • This is the default sub state inside ACC ON MODE state. Output signal Acceleration_Mode is equal to 2.
  • Condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Not_Detected; Input signal condition LeadVehicle_Detected == 0.
  • Condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Speed_lessthan_Set_Speed; Input Signals condition (LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap).

Requirement 3c (ii) – LeadVehicle_Not_Detected (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 1.
  • Condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Detected_Follow; Input signals condition [(LeadVehicle_Detected==1) && (DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
  • Condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Speed_lessthan_Set_Speed; Input signals condition [(LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap)]

Requirement 3c (iii) – LeadVehicle_Detected_Resume (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 3.
  • Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Detected_Follow; Input signals condition [(DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
  • Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Not_Detected_Resume; Input signal condition LeadVehicle_Detected==0.
  • Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Speed_equal_Set_Speed; Input Signal condition [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) && (Time_Gap >= Set_Gap)]

Requirement 3c (iv) - LeadVehicle_Not_Detected_Resume (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 1.

Requirement 3c (v) - LeadVehicle_Speed_lessthan_Set_Speed (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 4.
  • Condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Not_Detected; Input signal condition [(LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed)]
  • Condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Speed_equal_Set_Speed; Input signals condition [((LeadVehicle_Speed*1.25>=DriveVehicle_Speed) && (LeadVehicle_Speed * 0.75<=DriveVehicle_Speed)) && (DriveVehicle_Speed < Set_Speed) && ((Time_Gap<=1.25*Set_Gap) && (Time_Gap >=0.75*Set_Gap))]

Requirement 3c (vi) - LeadVehicle_Speed_equal_Set_Speed (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 5.
  • Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Not_Detected_Resume; Input signal conditions is [(LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)]
  • Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Detected_Resume; Input signal conditions [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) || (Time_Gap >= Set_Gap)]
  • Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Speed_lessthan_Set_Speed; Input signals conditions [(LeadVehicle_Speed

Signals & Calibration Data List

 
Signal / Calibration Name Signal Type Data Type Dimension    Min   Max Initial Value  Units
CameraInput_LeadVehicle    Input    Uint8      1     0   255      -     -
RadarInput_LeadVehicle    Input    Uint8      1     0   255      -     -
CameraInput_DriveVehicle    Input    Uint8      1     0   255      -     -
RadarInput_DriveVehicle    Input    Uint8      1     0   255      -     -
Time_Gap    Input    Uint8      1     0   255      -     -
Set_Speed    Input    Uint8      1     0   255      -     -
Set_Gap    Input    Uint8      1     0   255      -     -
CruiseSwitch    Input   Boolean      1     0     1      -     -
SetSwitch    Input   Boolean      1     0     1      -     -
Acceleration_Mode    Output   Uint8      1     0   255      -     -
LeadVehicle_Speed    Output    Uint8      1     0   255      -     -
DriveVehicle_Speed    Output    Uint8      1     0   255      -     -
LeadVehicle_Detected    Output    Uint8      1     0   255      -     -

Adaptive Cruise Control

Adaptive cruise control (ACC) is an active safety system that automatically controls the acceleration and braking of a vehicle. It is activated through a button on the steering wheel and cancelled by driver’s braking and/or another button.

By monitoring other vehicles and objects on the road, adaptive cruise control enables a safe and comfortable driving experience. It does so by helping the driver keep a steady vehicle speed at a given moment. The driver can set their preference regarding certain factors, such as the distance to the car in front, driving mode – for example, economical, sporty or comfortable – and others. Together with information about speed limits, road curvature, accidents data and more, these choices influence the automatically selected speed.

Cruise control has come a long way from its early days in its quest to assist drivers on the road. When first introduced, it was only found in luxury car models due to its high production cost. As less expensive sensors reached the market, adaptive cruise control is steadily becoming a standard feature in new vehicles today

DESIGNING THE MODEL:

This is the main model subsystem that having 9 inputs  CameraInput_LeadVehicle, RadarInput_LeadVehicle, CameraInput_DriveVehicle, RadarInput_DriveVehi, Time_Gap, Set_Speed, Set_Gap, CruiseSwitch and SetSwitch entering into the Adaptive Cruise Control subsystem and 4 outputs Acceleration_Mode, LeadVehicle_Speed, DriveVehicle_Speed, LeadVehicle_Detected     

There are 3 requirements are designed in 2 subsystems and one state machine flow chart 

Requirement 1– Lead Vehicle:

  • A lead vehicle is a vehicle that is driving in the road ahead of our drive vehicle. Two input signals (Signal Name: CameraInput_LeadVehicle & RadarInput_LeadVehicle).
  • Ideally, sensor fusion techniques will be deployed to process & analyze data from cameras & radar. For complexity reasons, let’s not adapt to any such algorithms.
  • We can simply add both the radar & camera inputs & the corresponding output is read as Speed profile output (Signal Name: LeadVehicle_Speed).
  • Speed data of the lead vehicle is critical in implementing the Adaptive Cruise Control algorithm.

Requirement 2 – Drive Vehicle:

  • Drive Vehicle is the vehicle driven by the user & this is the vehicle that has ACC algorithm in it.
  • Like the Lead Vehicle, the Driver Vehicle algorithm also has 2 input signals (Signal Name: CameraInput_DriveVehicle, RadarInput_DriveVehicle) & one signal coming as an Input to this subsystem (Signal Name: Acceleration_Mode) – three inputs into this requirement in total.
  • Like the above requirement, sensor fusion techniques will also be deployed here, for complexity reasons we are ignoring them.
  • Two output signals come from this subsystem (Signal Name: DriveVehicle_Speed & LeadVehicle_Detected).
  • Signal DriveVehicle_Speed is the summation of three input signals mentioned above & LeadVehicle_Detected is renamed from Input Signal RadarInput_DriveVehicle by mere use of Signal Conversion block.
  • Adaptive Cruise Control Mode Subsystem

The ACC Mode subsystem contain a chart(Stateflow), which will be act as a state machine logic used to program the vehicle to control automatically while driving.

Requirement 3 – Adaptive Cruise Control Algorithm:

Requirement 3a – ACC OFF MODE state logic:

  • This is the default state inside state machine logic. Output signal Acceleration_Mode is at value 0 in this state.
  • This state is governed by the input signal CruiseSwitch.
  • If CruiseSwitch is equal to 1, state ACC STANDBY mode will get activated. If CruiseSwitch is equal to 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode

Requirement 3b – ACC STANDBY MODE state logic:

  • This is the second activated state inside state machine logic. Output signal Acceleration_Mode is at value 1 in this state.
  • This state is governed by both input signals CruiseSwitch & SetSwitch.
  • If CruiseSwitch is equal to 1, state ACC STANDBY mode will get activated. If CruiseSwitch is equal to 0, state ACC OFF mode will get activated, from either ACC ON mode or ACC STANDBY mode
  • If SetSwitch is equal to 1, state ACC ON mode will get activated. If SetSwitch is equal to 0, state ACC STANDBY mode will get activated.

Requirement 3c – ACC ON MODE state logic:

This state will be activated when the input signal SetSwitch is equal to 1. There are 6 sub-states to this state logic: They are:

  • LeadVehicle_Detected_Follow (Default)
  • LeadVehicle_Not_Detected
  • LeadVehicle_Detected_Resume
  • LeadVehicle_Not_Detected_Resume
  • LeadVehicle_Speed_lessthan_Set_Speed

Requirement 3c (i) – LeadVehicle_Detected_Follow (ACC ON MODE):

  • This is the default substate inside the ACC ON MODE state. Output signal Acceleration_Mode is equal to 2.
  • Condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Not_Detected; Input signal condition LeadVehicle_Detected == 0.
  • Condition to transit from LeadVehicle_Detected_Follow to LeadVehicle_Speed_lessthan_Set_Speed; Input Signals condition (LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap).

Requirement 3c (ii) – LeadVehicle_Not_Detected (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 1.
  • Condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Detected_Follow; Input signals condition [(LeadVehicle_Detected==1) && (DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
  • Condition to transit from LeadVehicle_Not_Detected to LeadVehicle_Speed_lessthan_Set_Speed; Input signals condition [(LeadVehicle_Detected == 1) && (LeadVehicle_Speed < Set_Speed) || (Time_Gap < Set_Gap)]

Requirement 3c (iii) – LeadVehicle_Detected_Resume (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 3.
  • Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Detected_Follow; Input signals condition [(DriveVehicle_Speed == Set_Speed) && (LeadVehicle_Speed >= Set_Speed) && (Time_Gap >= Set_Gap)]
  • Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Not_Detected_Resume; Input signal condition LeadVehicle_Detected==0.
  • Condition to transit from LeadVehicle_Detected_Resume to LeadVehicle_Speed_equal_Set_Speed; Input Signal condition [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) && (Time_Gap >= Set_Gap)]

Requirement 3c (iv) - LeadVehicle_Not_Detected_Resume (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 1.

Requirement 3c (v) - LeadVehicle_Speed_lessthan_Set_Speed (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 4.
  • Condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Not_Detected; Input signal condition [(LeadVehicle_Detected == 0) && (DriveVehicle_Speed == Set_Speed)]
  • Condition to transit from LeadVehicle_Speed_lessthan_Set_Speed to LeadVehicle_Speed_equal_Set_Speed; Input signals condition [((LeadVehicle_Speed*1.25>=DriveVehicle_Speed) && (LeadVehicle_Speed * 0.75<=DriveVehicle_Speed)) && (DriveVehicle_Speed < Set_Speed) && ((Time_Gap<=1.25*Set_Gap) && (Time_Gap >=0.75*Set_Gap))]

Requirement 3c (vi) - LeadVehicle_Speed_equal_Set_Speed (ACC ON MODE):

  • Output signal Acceleration_Mode is equal to 5.
  • Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Not_Detected_Resume; Input signal conditions is [(LeadVehicle_Detected == 0) || (DriveVehicle_Speed <= Set_Speed)]
  • Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Detected_Resume; Input signal conditions [(DriveVehicle_Speed < Set_Speed) && (LeadVehicle_Speed > DriveVehicle_Speed) || (Time_Gap >= Set_Gap)]
  • Condition to transit from LeadVehicle_Speed_equal_Set_Speed to LeadVehicle_Speed_lessthan_Set_Speed; Input signals conditions [(LeadVehicle_Speed

REQUIREMENT Tagging and Tracebility report 

all the requirements are tagged for better understandability, anyone who is reviewing the model or who is trying to update the model can get a clear idea of what logic is used in the system. from the requirement manager, we can see what are all are tagged and the description.

  • REQUIREMENT 1 TAG WITH Lead_Vehicle_Mode Subsystem

  • REQUIREMENT 1 TAG WITH Drive_Vehicle_Mode_Subsystem

  • REQUIREMENT 1 TAG WITH ACC_Mode Subsystem

DEVELOPING SLDD:

All the inputs, outputs, calibration parameters are saved in SLDD so while simulation the model takes all the values and its parameters from the Simulink Data Dictionary

  •  Signal Resolution for inputs and outputs

The inputs and output signals are resolved so the signals will take the values from sldd and pass them to the logical blocks. Otherwise, it may take some junk values if it is unresolved

  • Model Update.

The model update is done by Ctrl-D. this is done to check for any static errors. If no errors are coming the model is working fine without any errors.

  • Simulation

The model is simulated too for checking for errors and warnings

  • Configuration Parameter Update

Various configuration parameters are updated as per the code generation the solver type should be fixed for  code generation 

Model Advisory Report

By running the model advisor tool, we can see commonly made modelling errors.

For this,

Go to model advisor check>by task>ony check modelling standards with MAB>Run selected checks.

Code generation 

For this code generation go to APPS tab then embeded coder then choose c code and generate that code which has been attached to code window.

The c code generated is :

       *  Inport: '/Time_Gap'
       */
      if (((*DriveVehicle_speed < Set_Speed) && (LeadVehicle_Speed >
            *DriveVehicle_speed)) || (Time_Gap >= Set_Gap)) {
        rtDW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Resume;

        /* ForcingFunction for Outport: '/Acceleration_Mode' */
        rtY.Acceleration_Mode = 3.0;
      } else if ((LeadVehicle_Detected == 0) || (*DriveVehicle_speed <=
                  Set_Speed)) {
        rtDW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected_Res;

        /* ForcingFunction for Outport: '/Acceleration_Mode' */
        rtY.Acceleration_Mode = 1.0;
      } else {
        if (((LeadVehicle_Speed < Set_Speed) && (LeadVehicle_Speed <
              *DriveVehicle_speed)) || ((int32_T)rt_roundd_snf(0.75 * (real_T)
              Set_Gap) == Time_Gap)) {
          rtDW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_lessthan_S;

          /* ForcingFunction for Outport: '/Acceleration_Mode' */
          rtY.Acceleration_Mode = 4.0;
        }
      }
      break;

     default:
      /* ForcingFunction for Outport: '/Acceleration_Mode' */
      /* case IN_LeadVehicle_Speed_lessthan_Set_Speed: */
      rtY.Acceleration_Mode = 4.0;

      /* Inport: '/Set_Speed' */
      if ((LeadVehicle_Detected == 0) && (*DriveVehicle_speed == Set_Speed)) {
        rtDW.is_ACC_ON_MODE = IN_LeadVehicle_Not_Detected;

        /* ForcingFunction for Outport: '/Acceleration_Mode' */
        rtY.Acceleration_Mode = 1.0;
      } else {
        tmp = (int32_T)rt_roundd_snf((real_T)LeadVehicle_Speed * 1.25);

        /* Inport: '/Set_Gap' */
        tmp_0 = (int32_T)rt_roundd_snf(1.25 * (real_T)Set_Gap);
        if (tmp < 256) {
          tmp_1 = (uint8_T)tmp;
        } else {
          tmp_1 = MAX_uint8_T;
        }

        if (tmp_0 < 256) {
          tmp_2 = (uint8_T)tmp_0;
        } else {
          tmp_2 = MAX_uint8_T;
        }

        /* Inport: '/Time_Gap' incorporates:
         *  Inport: '/Set_Gap'
         */
        if ((tmp_1 >= *DriveVehicle_speed) && (rt_roundd_snf((real_T)
              LeadVehicle_Speed * 0.75) <= *DriveVehicle_speed) &&
            (*DriveVehicle_speed < Set_Speed) && (Time_Gap <= tmp_2) &&
            (Time_Gap >= (int32_T)rt_roundd_snf(0.75 * (real_T)Set_Gap))) {
          rtDW.is_ACC_ON_MODE = IN_LeadVehicle_Speed_equal_Set_;

          /* ForcingFunction for Outport: '/Acceleration_Mode' */
          rtY.Acceleration_Mode = 5.0;
        }
      }
      break;
    }
  }

  /* End of Inport: '/CruiseSwitch' */
}

/* Model step function */
void Final_Project_step(void)
{
  real_T DriveVehicle_speed;
  if (rtmIsMajorTimeStep(rtM)) {
    /* set solver stop time */
    rtsiSetSolverStopTime(&rtM->solverInfo,((rtM->Timing.clockTick0+1)*
      rtM->Timing.stepSize0));
  }                                    /* end MajorTimeStep */

  /* Update absolute time of base rate at minor time step */
  if (rtmIsMinorTimeStep(rtM)) {
    rtM->Timing.t[0] = rtsiGetT(&rtM->solverInfo);
  }

  /* SignalConversion: '/Signal Conversion' incorporates:
   *  Inport: '/RadarInput_DriveVehicle'
   */
  LeadVehicle_Detected = RadarInput_DriveVehicle;

  /* Sum: '/Add1' incorporates:
   *  Inport: '/CameraInput_DriveVehicle'
   *  Inport: '/RadarInput_DriveVehicle'
   *  Integrator: '/Integrator'
   *  Sum: '/Add'
   */
  DriveVehicle_speed = ((real_T)CameraInput_DriveVehicle + rtX.Integrator_CSTATE)
    + (real_T)RadarInput_DriveVehicle;
  if (rtmIsMajorTimeStep(rtM)) {
    /* Sum: '/Add' incorporates:
     *  Inport: '/CameraInput_LeadVehicle'
     *  Inport: '/RadarInput_LeadVehicle'
     */
    LeadVehicle_Speed = (uint8_T)((uint32_T)CameraInput_LeadVehicle +
      RadarInput_LeadVehicle);

    /* Chart: '/Chart' incorporates:
     *  Inport: '/CruiseSwitch'
     *  Inport: '/SetSwitch'
     */
    if (rtDW.is_active_c3_Final_Project == 0U) {
      rtDW.is_active_c3_Final_Project = 1U;
      rtDW.is_c3_Final_Project = IN_ACC_OFF_MODE;

      /* Outport: '/Acceleration_Mode' */
      rtY.Acceleration_Mode = 0.0;
    } else {
      switch (rtDW.is_c3_Final_Project) {
       case IN_ACC_OFF_MODE:
        /* Outport: '/Acceleration_Mode' */
        rtY.Acceleration_Mode = 0.0;
        if (CruiseSwitch) {
          rtDW.is_c3_Final_Project = IN_ACC_STANDBY_MODE;

          /* Outport: '/Acceleration_Mode' */
          rtY.Acceleration_Mode = 1.0;
        }
        break;

       case IN_ACC_ON_MODE:
        ACC_ON_MODE(&DriveVehicle_speed);
        break;

       default:
        /* Outport: '/Acceleration_Mode' */
        /* case IN_ACC_STANDBY_MODE: */
        rtY.Acceleration_Mode = 1.0;
        if (!CruiseSwitch) {
          rtDW.is_c3_Final_Project = IN_ACC_OFF_MODE;

          /* Outport: '/Acceleration_Mode' */
          rtY.Acceleration_Mode = 0.0;
        } else {
          if (SetSwitch) {
            rtDW.is_c3_Final_Project = IN_ACC_ON_MODE;
            rtDW.is_ACC_ON_MODE = IN_LeadVehicle_Detected_Follow;

            /* Outport: '/Acceleration_Mode' */
            rtY.Acceleration_Mode = 2.0;
          }
        }
        break;
      }
    }

    /* End of Chart: '/Chart' */
  }

  if (rtmIsMajorTimeStep(rtM)) {
    rt_ertODEUpdateContinuousStates(&rtM->solverInfo);

    /* Update absolute time for base rate */
    /* The "clockTick0" counts the number of times the code of this task has
     * been executed. The absolute time is the multiplication of "clockTick0"
     * and "Timing.stepSize0". Size of "clockTick0" ensures timer will not
     * overflow during the application lifespan selected.
     */
    ++rtM->Timing.clockTick0;
    rtM->Timing.t[0] = rtsiGetSolverStopTime(&rtM->solverInfo);

    {
      /* Update absolute timer for sample time: [0.01s, 0.0s] */
      /* The "clockTick1" counts the number of times the code of this task has
       * been executed. The resolution of this integer timer is 0.01, which is the step size
       * of the task. Size of "clockTick1" ensures timer will not overflow during the
       * application lifespan selected.
       */
      rtM->Timing.clockTick1++;
    }
  }                                    /* end MajorTimeStep */
}

/* Derivatives for root system: '' */
void Final_Project_derivatives(void)
{
  XDot *_rtXdot;
  _rtXdot = ((XDot *) rtM->derivs);

  /* Derivatives for Integrator: '/Integrator' incorporates:
   *  Outport: '/Acceleration_Mode'
   */
  _rtXdot->Integrator_CSTATE = rtY.Acceleration_Mode;
}

/* Model initialize function */
void Final_Project_initialize(void)
{
  /* Registration code */
  {
    /* Setup solver object */
    rtsiSetSimTimeStepPtr(&rtM->solverInfo, &rtM->Timing.simTimeStep);
    rtsiSetTPtr(&rtM->solverInfo, &rtmGetTPtr(rtM));
    rtsiSetStepSizePtr(&rtM->solverInfo, &rtM->Timing.stepSize0);
    rtsiSetdXPtr(&rtM->solverInfo, &rtM->derivs);
    rtsiSetContStatesPtr(&rtM->solverInfo, (real_T **) &rtM->contStates);
    rtsiSetNumContStatesPtr(&rtM->solverInfo, &rtM->Sizes.numContStates);
    rtsiSetNumPeriodicContStatesPtr(&rtM->solverInfo,
      &rtM->Sizes.numPeriodicContStates);
    rtsiSetPeriodicContStateIndicesPtr(&rtM->solverInfo,
      &rtM->periodicContStateIndices);
    rtsiSetPeriodicContStateRangesPtr(&rtM->solverInfo,
      &rtM->periodicContStateRanges);
    rtsiSetErrorStatusPtr(&rtM->solverInfo, (&rtmGetErrorStatus(rtM)));
    rtsiSetRTModelPtr(&rtM->solverInfo, rtM);
  }

  rtsiSetSimTimeStep(&rtM->solverInfo, MAJOR_TIME_STEP);
  rtM->intgData.y = rtM->odeY;
  rtM->intgData.f[0] = rtM->odeF[0];
  rtM->intgData.f[1] = rtM->odeF[1];
  rtM->intgData.f[2] = rtM->odeF[2];
  rtM
->contStates = ((X *) &rtX);
  rtsiSetSolverData(&rtM->solverInfo, (void *)&rtM->intgData);
  rtsiSetSolverName(&rtM->solverInfo,"ode3");
  rtmSetTPtr(rtM, &rtM->Timing.tArray[0]);
  rtM->Timing.stepSize0 = 0.01;

  /* InitializeConditions for Integrator: '/Integrator' */
  rtX.Integrator_CSTATE = 0.0;
}

/* Model terminate function */
void Final_Project_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */

RESULT AND CONCLUSION:

Thus we implementing the Adaptive Cruise Control simulation model will be created as per given requirements, also create a sldd file based on it. All input output signals are resolved and propageted. Then generate the model advisor report and the code is generated successfully.In this way I have done my project and get result satisfactory..

Hence. The Adaptive Cruise Control feature is developed as per the Requirement Document using MATLAB Simulink.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.