Модельно-ориентированное проектирование на коленке, идентификация систем в MATLAB/Simulink

// // File: arduinoTestVector.cpp // // Code generated for Simulink model 'arduinoTestVector'. // // Model version: 1.229 // Simulink Coder version: 8.6 (R2014a) 27-Dec-2013 // C/C++ source code generated on: Thu May 22 14:47:55 2014 // // Target selection: arduino_ec.tlc // Embedded hardware selection: Atmel→AVR // Code generation objectives: // 1. Execution efficiency // 2. ROM efficiency // 3. RAM efficiency // Validation result: Not run // #include «arduinoTestVector.h»

// Constant parameters (auto storage) const ConstParam_arduinoTestVector arduinoTestVector_ConstP = { // Expression: myData // Referenced by: '/Constant1'

{ 0, 1, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 17, 18, 19, 20, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 36, 37, 38, 40, 41, 42, 43, 45, 46, 47, 48, 50, 51, 52, 54, 55, 56, 57, 59, 60, 61, 62, 0, -1, -3, -4, -5, -6, -8, -9, -10, -11, -13, -14, -15, -17, -18, -19, -20, -22, -23, -24, -26, -27, -28, -29, -31, -32, -33, -34, -36, -37, -38, -40, -41, -42, -43, -45, -46, -47, -48, -50, -51, -52, -54, -55, -56, -57, -59, -60, -61, -62, 0, 3, 5, 8, 10, 13, 15, 18, 20, 23, 26, 28, 31, 33, 36, 38, 41, 43, 46, 48, 51, 54, 56, 59, 61, 64, 66, 69, 71, 74, 77, 79, 82, 84, 87, 89, 92, 94, 97, 99, 102, 105, 107, 110, 112, 115, 117, 120, 122, 125, 0, -3, -5, -8, -10, -13, -15, -18, -20, -23, -26, -28, -31, -33, -36, -38, -41, -43, -46, -48, -51, -54, -56, -59, -61, -64, -66, -69, -71, -74, -77, -79, -82, -84, -87, -89, -92, -94, -97, -99, -102, -105, -107, -110, -112, -115, -117, -120, -122, -125, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, -170, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, -255, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, -85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };

// Block signals (auto storage) BlockIO_arduinoTestVector arduinoTestVector_B;

// Block states (auto storage) D_Work_arduinoTestVector arduinoTestVector_DWork;

// Model step function void arduinoTestVector_step (void) { // local block i/o variables uint8_T rtb_MOTORSHIELD_IN1; uint8_T rtb_MOTORSHIELD_IN2; uint8_T rtb_Abs; boolean_T aVarTruthTableCondition_1; boolean_T aVarTruthTableCondition_2; boolean_T aVarTruthTableCondition_3; uint16_T rtb_Init;

// Outputs for Enabled SubSystem: '/ENABLE_TEST' incorporates: // EnablePort: '/Enable'

// S-Function (sfunar_digitalInput): '/RUN_TEST' if (((uint8_T)digitalRead (((uint8_T)2U))) > 0) { if (! arduinoTestVector_DWork.ENABLE_TEST_MODE) { // InitializeConditions for UnitDelay: '/Unit Delay' arduinoTestVector_DWork.UnitDelay_DSTATE = false;

// InitializeConditions for UnitDelay: '/FixPt Unit Delay2' arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE = 1U;

// InitializeConditions for UnitDelay: '/FixPt Unit Delay1' arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = 0U; arduinoTestVector_DWork.ENABLE_TEST_MODE = true; }

// Switch: '/Init' incorporates: // Constant: '/Initial Condition' // Logic: '/FixPt Logical Operator' // UnitDelay: '/Unit Delay' // UnitDelay: '/FixPt Unit Delay1' // UnitDelay: '/FixPt Unit Delay2'

if (arduinoTestVector_DWork.UnitDelay_DSTATE || (arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE!= 0)) { rtb_Init = 0U; } else { rtb_Init = arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE; }

// End of Switch: '/Init'

// Selector: '/Selector' incorporates: // Constant: '/Constant1'

arduinoTestVector_B.Selector = arduinoTestVector_ConstP.Constant1_Value [(int16_T)rtb_Init];

// Switch: '/Reset' incorporates: // UnitDelay: '/Unit Delay'

if (arduinoTestVector_DWork.UnitDelay_DSTATE) { // Update for UnitDelay: '/FixPt Unit Delay1' incorporates: // Constant: '/Initial Condition'

arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = 0U; } else { // Update for UnitDelay: '/FixPt Unit Delay1' incorporates: // Constant: '/Constant' // Sum: '/Add'

arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = rtb_Init + 1U; }

// End of Switch: '/Reset'

// Update for UnitDelay: '/Unit Delay' incorporates: // Constant: '/Constant' // RelationalOperator: '/Compare'

arduinoTestVector_DWork.UnitDelay_DSTATE = (rtb_Init == 500U);

// Update for UnitDelay: '/FixPt Unit Delay2' incorporates: // Constant: '/FixPt Constant'

arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE = 0U; } else { if (arduinoTestVector_DWork.ENABLE_TEST_MODE) { // Disable for Outport: '/TEST_OUT' arduinoTestVector_B.Selector = 0; arduinoTestVector_DWork.ENABLE_TEST_MODE = false; } }

// End of S-Function (sfunar_digitalInput): '/RUN_TEST' // End of Outputs for SubSystem: '/ENABLE_TEST'

// Truth Table: '/Truth Table' // Truth Table Function 'Truth Table': ':1' // ClockWise // Condition '#1': ':1:10' aVarTruthTableCondition_1 = (arduinoTestVector_B.Selector > 0);

// CounterClockWise // Condition '#2': ':1:14' aVarTruthTableCondition_2 = (arduinoTestVector_B.Selector < 0);

// Stop // Condition '#3': ':1:18' aVarTruthTableCondition_3 = (arduinoTestVector_B.Selector == 0); if ((! aVarTruthTableCondition_1) && (! aVarTruthTableCondition_2) && aVarTruthTableCondition_3) { // Decision 'D1': ':1:20' // Stop // Action '3': ':1:48' rtb_MOTORSHIELD_IN1 = 0U;

// Action '3': ':1:49' rtb_MOTORSHIELD_IN2 = 0U; } else { // Decision 'D2': ':1:20' if (aVarTruthTableCondition_1 && (! aVarTruthTableCondition_2) && (! aVarTruthTableCondition_3)) { // Decision 'D2': ':1:22' // ClockWise // Action '1': ':1:34' rtb_MOTORSHIELD_IN1 = 1U;

// Action '1': ':1:35' rtb_MOTORSHIELD_IN2 = 0U; } else { // Decision 'D3': ':1:22' if ((! aVarTruthTableCondition_1) && aVarTruthTableCondition_2 && (! aVarTruthTableCondition_3)) { // Decision 'D3': ':1:24' // CounterClockWise // Action '2': ':1:41' rtb_MOTORSHIELD_IN1 = 0U;

// Action '2': ':1:42' rtb_MOTORSHIELD_IN2 = 1U; } else { // Decision 'D4': ':1:24' // Decision 'D4': ':1:26' // Default // None // Action '4': ':1:55' rtb_MOTORSHIELD_IN1 = 0U;

// Action '4': ':1:56' rtb_MOTORSHIELD_IN2 = 0U; } } }

// End of Truth Table: '/Truth Table'

// S-Function (sfunar_digitalOutput): '/MOTORSHIELD_IN1' digitalWrite (((uint8_T)8U), rtb_MOTORSHIELD_IN1);

// S-Function (sfunar_digitalOutput): '/MOTORSHIELD_IN2' digitalWrite (((uint8_T)11U), rtb_MOTORSHIELD_IN2);

// Abs: '/Abs' if (arduinoTestVector_B.Selector < 0) { rtb_Abs = (uint8_T)-arduinoTestVector_B.Selector; } else { rtb_Abs = (uint8_T)arduinoTestVector_B.Selector; }

// End of Abs: '/Abs'

// S-Function (sfunar_analogOutput): '/SPEEDPIN_A' analogWrite (((uint8_T)9U), rtb_Abs); }

// Model initialize function void arduinoTestVector_initialize (void) { // Registration code

// block I/O (void) memset (((void *) &arduinoTestVector_B), 0, sizeof (BlockIO_arduinoTestVector));

// states (dwork) (void) memset ((void *)&arduinoTestVector_DWork, 0, sizeof (D_Work_arduinoTestVector));

// S-Function (sfunar_digitalInput): /RUN_TEST pinMode (((uint8_T)2U), INPUT);

// InitializeConditions for Enabled SubSystem: '/ENABLE_TEST' // InitializeConditions for UnitDelay: '/Unit Delay' arduinoTestVector_DWork.UnitDelay_DSTATE = false;

// InitializeConditions for UnitDelay: '/FixPt Unit Delay2' arduinoTestVector_DWork.FixPtUnitDelay2_DSTATE = 1U;

// InitializeConditions for UnitDelay: '/FixPt Unit Delay1' arduinoTestVector_DWork.FixPtUnitDelay1_DSTATE = 0U;

// End of InitializeConditions for SubSystem: '/ENABLE_TEST'

// S-Function (sfunar_digitalOutput): /MOTORSHIELD_IN1 pinMode (((uint8_T)8U), OUTPUT);

// S-Function (sfunar_digitalOutput): /MOTORSHIELD_IN2 pinMode (((uint8_T)11U), OUTPUT);

// S-Function (sfunar_analogOutput): /SPEEDPIN_A pinMode (((uint8_T)9U), OUTPUT); }

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

© Habrahabr.ru