Challenge

Project 1 (Mini Project on Vehicle Direction Detection

AIM: To develop a model which simulates vehicle direction.

In developing a simulink file, first step is to create SLDD file with given parameters. The developed SLDD file is

For the given requirement 1, simulink model is developed as

If Steering wheel is straight, we get turn status as 0

If Steering wheel is left, we get turn status as -120

If Steering wheel is right, we get turn status as 30

In other cases, we get turn status as -121(an arbitary constant which will be neglected in requirement 2).

For the requirement 2, simulink model is developed as

This gives output as high when any roadsign is active else zero.

The final system after which contains two required sub systems is

The requirements have been tagged to the respective sub systems.

After generating s function, we get required code as

/*
 * Subsystem2_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 "Subsystem2_sf".
 *
 * Model version              : 1.12
 * Simulink Coder version : 9.8 (R2022b) 13-May-2022
 * C source code generated on : Tue Oct 25 23:16:08 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 "Subsystem2_sf.h"
#include "rtwtypes.h"
#include "Subsystem2_sf_private.h"
#include "simstruc.h"
#include "fixedpoint.h"
#if defined(RT_MALLOC) || defined(MATLAB_MEX_FILE)

extern void *Subsystem2_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";

/* Start for root system: '<Root>' */
#define MDL_START

static void mdlStart(SimStruct *S)
{
  /* instance underlying S-Function data */
#if defined(RT_MALLOC) || defined(MATLAB_MEX_FILE)
#if defined(MATLAB_MEX_FILE)

  /* non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

#endif

  Subsystem2_malloc(S);
  if (ssGetErrorStatus(S) != (NULL) ) {
    return;
  }

#endif

  {
  }
}

/* Outputs for root system: '<Root>' */
static void mdlOutputs(SimStruct *S, int_T tid)
{
  B_Subsystem2_T *_rtB;
  int32_T tmp;
  int32_T tmp_0;
  int32_T tmp_1;
  _rtB = ((B_Subsystem2_T *) ssGetLocalBlockIO(S));

  /* Outputs for Atomic SubSystem: '<Root>/Subsystem2' */
  /* Switch: '<S2>/Switch4' incorporates:
   *  Constant: '<S2>/Garbage constant'
   *  Switch: '<S2>/Switch3'
   */
  if (*((const int16_T **)ssGetInputPortSignalPtrs(S, 0))[0] > 0) {
    tmp = *((const int16_T **)ssGetInputPortSignalPtrs(S, 0))[0];
    tmp_0 = -121;
  } else {
    tmp = -121;
    tmp_0 = *((const int16_T **)ssGetInputPortSignalPtrs(S, 0))[0];
  }

  /* Switch: '<S2>/Switch' incorporates:
   *  Constant: '<S2>/Constant'
   *  Constant: '<S2>/Garbage constant'
   *  Switch: '<S2>/Switch4'
   */
  if (tmp > 30) {
    tmp = -121;
  } else {
    tmp = 30;
  }

  /* Switch: '<S2>/Switch1' incorporates:
   *  Constant: '<S2>/Constant1'
   *  Constant: '<S2>/Garbage constant'
   *  Switch: '<S2>/Switch3'
   */
  if (tmp_0 > -120) {
    tmp_0 = -120;
  } else {
    tmp_0 = -121;
  }

  /* Switch: '<S2>/Switch2' incorporates:
   *  Constant: '<S2>/Constant2'
   *  Constant: '<S2>/Garbage constant'
   */
  if (*((const int16_T **)ssGetInputPortSignalPtrs(S, 0))[0] != 0) {
    tmp_1 = -121;
  } else {
    tmp_1 = 0;
  }

  /* Logic: '<S3>/OR' incorporates:
   *  Constant: '<S3>/Constant1'
   *  Logic: '<S3>/AND1'
   *  RelationalOperator: '<S3>/Relational Operator1'
   *  Sum: '<S2>/Add'
   *  Switch: '<S2>/Switch'
   *  Switch: '<S2>/Switch1'
   *  Switch: '<S2>/Switch2'
   */
  _rtB->Vehicle_Direction_Indicator = (((tmp + tmp_0) + tmp_1 == -120) && (*((
    const boolean_T **)ssGetInputPortSignalPtrs(S, 1))[0]));

  /* End of Outputs for SubSystem: '<Root>/Subsystem2' */

  /* Outport: '<Root>/Vehicle_Direction_Indicator' */
  ((boolean_T *)ssGetOutputPortSignal(S, 0))[0] =
    _rtB->Vehicle_Direction_Indicator;
  UNUSED_PARAMETER(tid);
}

/* Update for root system: '<Root>' */
#define MDL_UPDATE
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.