Challenge

Project 2 Adaptive Cruise Control

AIM: To develop Adaptive Cruise Control feature as per given requirement.

An SLDD file is first developed so we can tag them in the model during builidng.

Based on given requirements, SLDD is developed as

For requirement 1, we have to add CameraInput and RadarInput signals from LeadVehicle which is developed as shown below

For requirement 2, we need to get drive vehicle speed as sum of CameraInput, Acclerationmode, Radarinput of drive vehicle. Leadvehicle_detected is the Radarinput signal which is converted from signal conversion block.

The requirement 3 from with all the sub requirements from 3a to 3c(vi) is implemented using state flow logic as shown below

The developed simulink model which has subsystems that meet all the given three requirements is

The given requirements are tagged to the respective sub system fron word file.

Now, before code generation, all the settings were applied as upport for floating point numbers is enabled.

Using model advisor tool, modelling standards for MAB check gives

It can be seen that there are 0 incomplete process and model is working

The code has been generated for this model can be seen below

/*
 * Adaptive_Cruise_Control_sf.c
 *
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * Code generation for model "Adaptive_Cruise_Control_sf".
 *
 * Model version              : 8.7
 * Simulink Coder version : 9.8 (R2022b) 13-May-2022
 * C source code generated on : Wed Oct 26 09:00:18 2022
 *
 * Target selection: rtwsfcn.tlc
 * Note: GRT includes extra infrastructure and instrumentation for prototyping
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "Adaptive_Cruise_Control_sf.h"
#include "rtwtypes.h"
#include "Adaptive_Cruise_Control_sf_private.h"
#include "simstruc.h"
#include "fixedpoint.h"

/* Named constants for Chart: '<S1>/Requirement3' */
#define Ada_IN_LeadVehicle_Not_Detected ((uint8_T)3U)
#define Adaptive_Cru_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define Adaptive_Cruise_Con_IN_OFF_mode ((uint8_T)1U)
#define Adaptive_Cruise_Cont_IN_ON_mode ((uint8_T)2U)
#define Adaptive_Cruise_IN_Standby_mode ((uint8_T)3U)
#define IN_LeadVehicle_Detected_Follow ((uint8_T)1U)
#define IN_LeadVehicle_Detected_Resume ((uint8_T)2U)
#define IN_LeadVehicle_Not_Detected_Res ((uint8_T)4U)
#define IN_LeadVehicle_Speed_equal_Set_ ((uint8_T)5U)
#define IN_LeadVehicle_Speed_lessthan_S ((uint8_T)6U)
#if defined(RT_MALLOC) || defined(MATLAB_MEX_FILE)

extern void *Adaptive_Cruise_Control_malloc(SimStruct *S);

#endif

#ifndef __RTW_UTFREE__
#if defined (MATLAB_MEX_FILE)

extern void * utMalloc(size_t);
extern void utFree(void *);

#endif
#endif                                 /* #ifndef __RTW_UTFREE__ */

#if defined(MATLAB_MEX_FILE)
#include "rt_nonfinite.c"
#endif

static const char_T *RT_MEMORY_ALLOCATION_ERROR =
  "memory allocation error in generated S-Function";

/* System initialize for root system: '<Root>' */
#define MDL_INITIALIZE_CONDITIONS

static void mdlInitializeConditions(SimStruct *S)
{
  if (ssIsFirstInitCond(S)) {
    B_Adaptive_Cruise_Control_T *_rtB;
    _rtB = ((B_Adaptive_Cruise_Control_T *) ssGetLocalBlockIO(S));

    /* SystemInitialize for Atomic SubSystem: '<Root>/Adaptive_Cruise_Control' */
    /* InitializeConditions for UnitDelay: '<S1>/Unit Delay' */
    ((real_T *)ssGetDWork(S, 0))[0] = 0.0;

    /* SystemInitialize for Chart: '<S1>/Requirement3' */
    ((uint8_T *)ssGetDWork(S, 2))[0] = Adaptive_Cru_IN_NO_ACTIVE_CHILD;
    ((uint8_T *)ssGetDWork(S, 3))[0] = 0U;
    ((uint8_T *)ssGetDWork(S, 1))[0] = Adaptive_Cru_IN_NO_ACTIVE_CHILD;
    _rtB->Acceleration_Mode = 0.0;

has popup
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.