/* Output and update for referenced model: 'motor_hr' */ void motor_hr(const real_T *rtu_enable, const real_T *rtu_power, const real_T *rtu_direction) { real_T rtu_enable_0; uint8_T rtu_enable_1; /* Switch: '<Root>/Switch' incorporates: * Constant: '<Root>/Constant2' */ if (*rtu_enable > motor_hr_P.Switch_Threshold) { rtu_enable_0 = *rtu_direction; } else { rtu_enable_0 = motor_hr_P.Constant2_Value; } /* End of Switch: '<Root>/Switch' */ /* DataTypeConversion: '<S1>/Data Type Conversion' */ if (rtu_enable_0 < 256.0) { if (rtu_enable_0 >= 0.0) { rtu_enable_1 = (uint8_T)rtu_enable_0; } else { rtu_enable_1 = 0U; } } else { rtu_enable_1 = MAX_uint8_T; } /* End of DataTypeConversion: '<S1>/Data Type Conversion' */ /* S-Function (arduinodigitaloutput_sfcn): '<S1>/Digital Output' */ MW_digitalWrite(motor_hr_P.DigitalOutput_pinNumber, rtu_enable_1); /* Switch: '<Root>/Switch1' incorporates: * Constant: '<Root>/Constant3' */ if (*rtu_enable > motor_hr_P.Switch1_Threshold) { rtu_enable_0 = *rtu_power; } else { rtu_enable_0 = motor_hr_P.Constant3_Value; } /* End of Switch: '<Root>/Switch1' */ /* DataTypeConversion: '<S2>/Data Type Conversion' */ if (rtu_enable_0 < 256.0) { if (rtu_enable_0 >= 0.0) { rtu_enable_1 = (uint8_T)rtu_enable_0; } else { rtu_enable_1 = 0U; } } else { rtu_enable_1 = MAX_uint8_T; } /* End of DataTypeConversion: '<S2>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S2>/PWM' */ MW_analogWrite(motor_hr_P.PWM_pinNumber, rtu_enable_1); }
/* Model output function */ void untitled_output(void) { uint8_T tmp; /* DataTypeConversion: '<S1>/Data Type Conversion' incorporates: * Constant: '<Root>/Constant1' */ if (untitled_P.Constant1_Value < 256.0) { if (untitled_P.Constant1_Value >= 0.0) { tmp = (uint8_T)untitled_P.Constant1_Value; } else { tmp = 0U; } } else { tmp = MAX_uint8_T; } /* End of DataTypeConversion: '<S1>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S1>/PWM' */ MW_analogWrite(untitled_P.PWM_pinNumber, tmp); /* DataTypeConversion: '<S2>/Data Type Conversion' incorporates: * Constant: '<Root>/Constant2' */ if (untitled_P.Constant2_Value < 256.0) { if (untitled_P.Constant2_Value >= 0.0) { tmp = (uint8_T)untitled_P.Constant2_Value; } else { tmp = 0U; } } else { tmp = MAX_uint8_T; } /* End of DataTypeConversion: '<S2>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S2>/PWM' */ MW_analogWrite(untitled_P.PWM_pinNumber_m, tmp); }
/* Model step function */ void motor_hr_step(void) { real_T tmp; uint8_T tmp_0; /* Switch: '<Root>/Switch' incorporates: * Constant: '<Root>/Constant2' * Inport: '<Root>/direction' * Inport: '<Root>/enable' */ if (motor_hr_U.enable > motor_hr_P.Switch_Threshold) { tmp = motor_hr_U.direction; } else { tmp = motor_hr_P.Constant2_Value; } /* End of Switch: '<Root>/Switch' */ /* DataTypeConversion: '<S1>/Data Type Conversion' */ if (tmp < 256.0) { if (tmp >= 0.0) { tmp_0 = (uint8_T)tmp; } else { tmp_0 = 0U; } } else { tmp_0 = MAX_uint8_T; } /* End of DataTypeConversion: '<S1>/Data Type Conversion' */ /* S-Function (arduinodigitaloutput_sfcn): '<S1>/Digital Output' */ MW_digitalWrite(motor_hr_P.DigitalOutput_pinNumber, tmp_0); /* Switch: '<Root>/Switch1' incorporates: * Constant: '<Root>/Constant3' * Inport: '<Root>/enable' * Inport: '<Root>/power' */ if (motor_hr_U.enable > motor_hr_P.Switch1_Threshold) { tmp = motor_hr_U.power; } else { tmp = motor_hr_P.Constant3_Value; } /* End of Switch: '<Root>/Switch1' */ /* DataTypeConversion: '<S2>/Data Type Conversion' */ if (tmp < 256.0) { if (tmp >= 0.0) { tmp_0 = (uint8_T)tmp; } else { tmp_0 = 0U; } } else { tmp_0 = MAX_uint8_T; } /* End of DataTypeConversion: '<S2>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S2>/PWM' */ MW_analogWrite(motor_hr_P.PWM_pinNumber, tmp_0); /* External mode */ rtExtModeUploadCheckTrigger(1); { /* Sample time: [20.0s, 0.0s] */ rtExtModeUpload(0, motor_hr_M->Timing.taskTime0); } /* signal main to stop simulation */ { /* Sample time: [20.0s, 0.0s] */ if ((rtmGetTFinal(motor_hr_M)!=-1) && !((rtmGetTFinal(motor_hr_M)-motor_hr_M->Timing.taskTime0) > motor_hr_M->Timing.taskTime0 * (DBL_EPSILON))) { rtmSetErrorStatus(motor_hr_M, "Simulation finished"); } if (rtmGetStopRequested(motor_hr_M)) { rtmSetErrorStatus(motor_hr_M, "Simulation finished"); } } /* 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. */ motor_hr_M->Timing.taskTime0 = (++motor_hr_M->Timing.clockTick0) * motor_hr_M->Timing.stepSize0; }
/* Model output function */ void SingleCylinderTest_output(void) { uint16_T rtb_FeedbackVoltage_0; static const int8_T b[6] = { 1, 2, 3, 4, 3, 2 }; real_T rtb_Abs1; real_T rtb_Product; real_T rtb_Switch; real_T rtb_Abs1_p; uint64m_T tmp; uint32_T tmp_0; uint8_T rtb_Abs1_k; /* Step: '<Root>/Step' */ if (((SingleCylinderTest_M->Timing.clockTick0) * 0.01) < SingleCylinderTest_P.Step_Time) { rtb_Product = SingleCylinderTest_P.Step_Y0; } else { rtb_Product = SingleCylinderTest_P.Step_YFinal; } /* End of Step: '<Root>/Step' */ /* Product: '<S4>/Product' incorporates: * Abs: '<S6>/Abs' * Constant: '<S6>/Constant' * RelationalOperator: '<S6>/Relational Operator' * Sum: '<S6>/Sum' * UnitDelay: '<Root>/Unit Delay' * UnitDelay: '<S4>/Unit Delay1' */ rtb_Product *= (real_T)(fabs(SingleCylinderTest_DW.UnitDelay_DSTATE - SingleCylinderTest_DW.UnitDelay1_DSTATE) < SingleCylinderTest_P.Constant_Value_m); /* Chart: '<S5>/Chart' incorporates: * UnitDelay: '<S5>/Unit Delay1' */ /* Gateway: High Level System Controller/System Model/State Machine/Chart */ /* During: High Level System Controller/System Model/State Machine/Chart */ if (SingleCylinderTest_DW.is_active_c3_SingleCylinderTest == 0U) { /* Entry: High Level System Controller/System Model/State Machine/Chart */ SingleCylinderTest_DW.is_active_c3_SingleCylinderTest = 1U; /* Entry Internal: High Level System Controller/System Model/State Machine/Chart */ /* Transition: '<S8>:23' */ SingleCylinderTest_DW.is_c3_SingleCylinderTest = SingleCylinderTest_IN_Idle; /* Entry 'Idle': '<S8>:1' */ SingleCylinderTest_B.index_out_n = SingleCylinderTest_DW.UnitDelay1_DSTATE_k; } else { switch (SingleCylinderTest_DW.is_c3_SingleCylinderTest) { case SingleCylinderTest_IN_Forward: /* During 'Forward': '<S8>:2' */ if (rtb_Product != 1.0) { /* Transition: '<S8>:7' */ SingleCylinderTest_DW.is_c3_SingleCylinderTest = SingleCylinderTest_IN_Idle; /* Entry 'Idle': '<S8>:1' */ SingleCylinderTest_B.index_out_n = SingleCylinderTest_DW.UnitDelay1_DSTATE_k; } else { SingleCylinderTest_B.index_out_n = SingleCylinderTest_DW.UnitDelay1_DSTATE_k + 1.0; } break; case SingleCylinderTest_IN_Idle: /* During 'Idle': '<S8>:1' */ if (rtb_Product == 1.0) { /* Transition: '<S8>:4' */ SingleCylinderTest_DW.is_c3_SingleCylinderTest = SingleCylinderTest_IN_Forward; /* Entry 'Forward': '<S8>:2' */ SingleCylinderTest_B.index_out_n = SingleCylinderTest_DW.UnitDelay1_DSTATE_k + 1.0; } else { if (rtb_Product == -1.0) { /* Transition: '<S8>:5' */ SingleCylinderTest_DW.is_c3_SingleCylinderTest = SingleCylinderTest_IN_Reverse; /* Entry 'Reverse': '<S8>:3' */ SingleCylinderTest_B.index_out_n = SingleCylinderTest_DW.UnitDelay1_DSTATE_k - 1.0; } } break; default: /* During 'Reverse': '<S8>:3' */ if (rtb_Product != -1.0) { /* Transition: '<S8>:6' */ SingleCylinderTest_DW.is_c3_SingleCylinderTest = SingleCylinderTest_IN_Idle; /* Entry 'Idle': '<S8>:1' */ SingleCylinderTest_B.index_out_n = SingleCylinderTest_DW.UnitDelay1_DSTATE_k; } else { SingleCylinderTest_B.index_out_n = SingleCylinderTest_DW.UnitDelay1_DSTATE_k - 1.0; } break; } } /* End of Chart: '<S5>/Chart' */ /* MATLAB Function: '<S5>/MATLAB Function' */ /* MATLAB Function 'High Level System Controller/System Model/State Machine/MATLAB Function': '<S9>:1' */ /* '<S9>:1:3' */ SingleCylinderTest_B.index_out = SingleCylinderTest_B.index_out_n; if (SingleCylinderTest_B.index_out_n > 6.0) { /* '<S9>:1:4' */ /* '<S9>:1:5' */ SingleCylinderTest_B.index_out = 1.0; } if (SingleCylinderTest_B.index_out_n < 1.0) { /* '<S9>:1:7' */ /* '<S9>:1:8' */ SingleCylinderTest_B.index_out = 6.0; } /* End of MATLAB Function: '<S5>/MATLAB Function' */ /* MATLAB Function: '<S7>/MATLAB Function' */ /* MATLAB Function 'High Level System Controller/System Model/State Machine/Calculate Foot Position/MATLAB Function': '<S10>:1' */ /* '<S10>:1:3' */ rtb_Product = SingleCylinderTest_B.index_out; if (SingleCylinderTest_B.index_out < 1.0) { /* '<S10>:1:4' */ /* '<S10>:1:5' */ rtb_Product = 1.0; } else { if (SingleCylinderTest_B.index_out > 6.0) { /* '<S10>:1:6' */ /* '<S10>:1:7' */ rtb_Product = 6.0; } } /* '<S10>:1:9' */ /* divide by 5 to normalize */ /* '<S10>:1:11' */ SingleCylinderTest_B.x = b[(int16_T)rtb_Product - 1]; /* End of MATLAB Function: '<S7>/MATLAB Function' */ /* S-Function (arduinoanaloginput_sfcn): '<S2>/Feedback Voltage' */ rtb_FeedbackVoltage_0 = MW_analogRead(SingleCylinderTest_P.FeedbackVoltage_p1); /* Gain: '<Root>/P' */ rtb_Product = SingleCylinderTest_P.P_Gain * SingleCylinderTest_B.x; /* Gain: '<S2>/P' incorporates: * Gain: '<S2>/Normalize Feedback' * S-Function (arduinoanaloginput_sfcn): '<S2>/Feedback Voltage' * Sum: '<S2>/Sum1' */ rtb_Abs1 = (rtb_Product - (real_T)((uint32_T) SingleCylinderTest_P.NormalizeFeedback_Gain_g * rtb_FeedbackVoltage_0) * 2.9802322387695313E-8) * SingleCylinderTest_P.P_Gain_b; /* Switch: '<S13>/Switch' incorporates: * Constant: '<S13>/Constant1' * Constant: '<S13>/Constant2' */ if (rtb_Abs1 >= SingleCylinderTest_P.Switch_Threshold) { rtb_Switch = SingleCylinderTest_P.Constant1_Value; } else { rtb_Switch = SingleCylinderTest_P.Constant2_Value; } /* End of Switch: '<S13>/Switch' */ /* Abs: '<S13>/Abs' incorporates: * Product: '<S13>/0 if Negative' */ rtb_Abs1_p = fabs(rtb_Abs1 * rtb_Switch); /* DataTypeConversion: '<S11>/Data Type Conversion' incorporates: * MinMax: '<S2>/Extend Saturation' */ if (rtb_Abs1_p < 256.0) { rtb_Abs1_k = (uint8_T)rtb_Abs1_p; } else { rtb_Abs1_k = MAX_uint8_T; } /* End of DataTypeConversion: '<S11>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S11>/PWM' */ MW_analogWrite(SingleCylinderTest_P.PWM_pinNumber, rtb_Abs1_k); /* Product: '<S13>/0 If Positive' incorporates: * Constant: '<S13>/Constant3' * Sum: '<S13>/Sum' */ rtb_Abs1 *= rtb_Switch - SingleCylinderTest_P.Constant3_Value; /* Abs: '<S13>/Abs1' */ rtb_Abs1 = fabs(rtb_Abs1); /* DataTypeConversion: '<S12>/Data Type Conversion' incorporates: * MinMax: '<S2>/Retract Saturation' */ if (rtb_Abs1 < 256.0) { rtb_Abs1_k = (uint8_T)rtb_Abs1; } else { rtb_Abs1_k = MAX_uint8_T; } /* End of DataTypeConversion: '<S12>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S12>/PWM' */ MW_analogWrite(SingleCylinderTest_P.PWM_pinNumber_n, rtb_Abs1_k); /* Sum: '<S2>/Sum2' */ SingleCylinderTest_B.Sum2 = rtb_Abs1_p + rtb_Abs1; /* S-Function (arduinoanaloginput_sfcn): '<S3>/Feedback Voltage' */ rtb_FeedbackVoltage_0 = MW_analogRead (SingleCylinderTest_P.FeedbackVoltage_p1_n); /* Gain: '<S3>/Normalize Feedback' incorporates: * Gain: '<S3>/Length Compensation' * S-Function (arduinoanaloginput_sfcn): '<S3>/Feedback Voltage' */ tmp_0 = (uint32_T)SingleCylinderTest_P.LengthCompensation_Gain * rtb_FeedbackVoltage_0; uMultiWordMul(&SingleCylinderTest_P.NormalizeFeedback_Gain, 1, &tmp_0, 1, &tmp.chunks[0U], 2); /* Gain: '<S3>/P' incorporates: * Constant: '<Root>/Constant' * Sum: '<Root>/Sum' * Sum: '<S3>/Sum1' */ rtb_Abs1_p = ((SingleCylinderTest_P.Constant_Value - rtb_Product) - uMultiWord2Double(&tmp.chunks[0U], 2, 0) * 1.3877787807814457E-17) * SingleCylinderTest_P.P_Gain_h; /* Switch: '<S16>/Switch' incorporates: * Constant: '<S16>/Constant1' * Constant: '<S16>/Constant2' */ if (rtb_Abs1_p >= SingleCylinderTest_P.Switch_Threshold_m) { rtb_Switch = SingleCylinderTest_P.Constant1_Value_j; } else { rtb_Switch = SingleCylinderTest_P.Constant2_Value_d; } /* End of Switch: '<S16>/Switch' */ /* DataTypeConversion: '<S14>/Data Type Conversion' incorporates: * Abs: '<S16>/Abs' * Product: '<S16>/0 if Negative' */ rtb_Product = fabs(rtb_Abs1_p * rtb_Switch); if (rtb_Product < 256.0) { rtb_Abs1_k = (uint8_T)rtb_Product; } else { rtb_Abs1_k = MAX_uint8_T; } /* End of DataTypeConversion: '<S14>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S14>/PWM' */ MW_analogWrite(SingleCylinderTest_P.PWM_pinNumber_p, rtb_Abs1_k); /* Product: '<S16>/0 If Positive' incorporates: * Constant: '<S16>/Constant3' * Sum: '<S16>/Sum' */ rtb_Abs1_p *= rtb_Switch - SingleCylinderTest_P.Constant3_Value_p; /* Abs: '<S16>/Abs1' */ rtb_Abs1_p = fabs(rtb_Abs1_p); /* DataTypeConversion: '<S15>/Data Type Conversion' incorporates: * MinMax: '<S3>/Retract Saturation' */ if (rtb_Abs1_p < 256.0) { rtb_Abs1_k = (uint8_T)rtb_Abs1_p; } else { rtb_Abs1_k = MAX_uint8_T; } /* End of DataTypeConversion: '<S15>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S15>/PWM' */ MW_analogWrite(SingleCylinderTest_P.PWM_pinNumber_g, rtb_Abs1_k); }
/* Model output function */ void XbeeSerialRead_output(void) { uint8_T rtb_DataTypeConversion_j; int16_T rtb_SerialReceive_o2; uint8_T tmp[11]; /* S-Function (arduinoserialread_sfcn): '<Root>/Serial Receive' */ Serial_read(XbeeSerialRead_P.SerialReceive_p1, XbeeSerialRead_P.SerialReceive_p2, &rtb_DataTypeConversion_j, &rtb_SerialReceive_o2); /* Switch: '<Root>/Switch' incorporates: * UnitDelay: '<Root>/Unit Delay' */ if (rtb_SerialReceive_o2 > XbeeSerialRead_P.Switch_Threshold) { XbeeSerialRead_B.Switch = rtb_DataTypeConversion_j; } else { XbeeSerialRead_B.Switch = XbeeSerialRead_DW.UnitDelay_DSTATE; } /* End of Switch: '<Root>/Switch' */ /* DataTypeConversion: '<S1>/Data Type Conversion' */ if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { rtb_DataTypeConversion_j = (uint8_T)XbeeSerialRead_B.Switch; } else { rtb_DataTypeConversion_j = 0U; } } else { rtb_DataTypeConversion_j = MAX_uint8_T; } /* End of DataTypeConversion: '<S1>/Data Type Conversion' */ /* S-Function (arduinoanalogoutput_sfcn): '<S1>/PWM' */ MW_analogWrite(XbeeSerialRead_P.PWM_pinNumber, rtb_DataTypeConversion_j); /* DataTypeConversion: '<S2>/Data Type Conversion' incorporates: * Constant: '<S2>/Footer 1' * Constant: '<S2>/Footer 2' * Constant: '<S2>/Header' */ if (XbeeSerialRead_P.Header_Value < 256.0) { if (XbeeSerialRead_P.Header_Value >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[0] = (uint8_T)XbeeSerialRead_P.Header_Value; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[0] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[0] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[1] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[1] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[1] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[2] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[2] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[2] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[3] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[3] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[3] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[4] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[4] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[4] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[5] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[5] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[5] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[6] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[6] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[6] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[7] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[7] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[7] = MAX_uint8_T; } if (XbeeSerialRead_B.Switch < 256.0) { if (XbeeSerialRead_B.Switch >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[8] = (uint8_T)XbeeSerialRead_B.Switch; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[8] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[8] = MAX_uint8_T; } if (XbeeSerialRead_P.Footer1_Value < 256.0) { if (XbeeSerialRead_P.Footer1_Value >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[9] = (uint8_T)XbeeSerialRead_P.Footer1_Value; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[9] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[9] = MAX_uint8_T; } if (XbeeSerialRead_P.Footer2_Value < 256.0) { if (XbeeSerialRead_P.Footer2_Value >= 0.0) { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[10] = (uint8_T)XbeeSerialRead_P.Footer2_Value; } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[10] = 0U; } } else { /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ tmp[10] = MAX_uint8_T; } /* End of DataTypeConversion: '<S2>/Data Type Conversion' */ /* S-Function (arduinoserialwrite_sfcn): '<S2>/Serial Transmit' */ Serial_write(XbeeSerialRead_P.SerialTransmit_portNumber, tmp, 11UL); }
/* * Output and update for atomic system: * '<S1>/hl' * '<S1>/vl' */ void motor_test_hierarchies_hl(real_T rtu_enable, real_T rtu_power, real_T rtu_direction, B_hl_motor_test_hierarchies_T *localB, P_hl_motor_test_hierarchies_T *localP) { real_T rtu_enable_0; uint8_T rtu_enable_1; /* Switch: '<S4>/Switch' incorporates: * Constant: '<S4>/Constant2' */ if (rtu_enable > localP->Switch_Threshold) { rtu_enable_0 = rtu_direction; } else { rtu_enable_0 = localP->Constant2_Value; } /* End of Switch: '<S4>/Switch' */ /* DataTypeConversion: '<S8>/Data Type Conversion' */ if (rtu_enable_0 < 256.0) { if (rtu_enable_0 >= 0.0) { rtu_enable_1 = (uint8_T)rtu_enable_0; } else { rtu_enable_1 = 0U; } } else { rtu_enable_1 = MAX_uint8_T; } /* End of DataTypeConversion: '<S8>/Data Type Conversion' */ /* S-Function (arduinodigitaloutput_sfcn): '<S8>/Digital Output' */ MW_digitalWrite(localP->DigitalOutput_pinNumber, rtu_enable_1); /* Switch: '<S4>/Switch1' incorporates: * Constant: '<S4>/Constant3' * DataTypeConversion: '<S9>/Data Type Conversion' */ if (rtu_enable > localP->Switch1_Threshold) { /* DataTypeConversion: '<S9>/Data Type Conversion' */ if (rtu_power < 256.0) { if (rtu_power >= 0.0) { localB->DataTypeConversion = (uint8_T)rtu_power; } else { localB->DataTypeConversion = 0U; } } else { localB->DataTypeConversion = MAX_uint8_T; } } else if (localP->Constant3_Value < 256.0) { /* DataTypeConversion: '<S9>/Data Type Conversion' incorporates: * Constant: '<S4>/Constant3' */ if (localP->Constant3_Value >= 0.0) { localB->DataTypeConversion = (uint8_T)localP->Constant3_Value; } else { localB->DataTypeConversion = 0U; } } else { /* DataTypeConversion: '<S9>/Data Type Conversion' */ localB->DataTypeConversion = MAX_uint8_T; } /* End of Switch: '<S4>/Switch1' */ /* S-Function (arduinoanalogoutput_sfcn): '<S9>/PWM' */ MW_analogWrite(localP->PWM_pinNumber, localB->DataTypeConversion); }
/* Model step function */ void motor_test_hierarchies_step(void) { /* local block i/o variables */ real_T rtb_FromWs; real_T tmp; uint8_T tmp_0; /* Constant: '<Root>/enable' */ motor_test_hierarchies_B.enable = motor_test_hierarchies_P.enable_Value; /* FromWorkspace: '<S3>/FromWs' */ { real_T *pDataValues = (real_T *) motor_test_hierarchies_DW.FromWs_PWORK.DataPtr; real_T *pTimeValues = (real_T *) motor_test_hierarchies_DW.FromWs_PWORK.TimePtr; int_T currTimeIndex = motor_test_hierarchies_DW.FromWs_IWORK.PrevIndex; real_T t = motor_test_hierarchies_M->Timing.t[0]; /* Get index */ if (t <= pTimeValues[0]) { currTimeIndex = 0; } else if (t >= pTimeValues[9]) { currTimeIndex = 8; } else { if (t < pTimeValues[currTimeIndex]) { while (t < pTimeValues[currTimeIndex]) { currTimeIndex--; } } else { while (t >= pTimeValues[currTimeIndex + 1]) { currTimeIndex++; } } } motor_test_hierarchies_DW.FromWs_IWORK.PrevIndex = currTimeIndex; /* Post output */ { real_T t1 = pTimeValues[currTimeIndex]; real_T t2 = pTimeValues[currTimeIndex + 1]; if (t1 == t2) { if (t < t1) { rtb_FromWs = pDataValues[currTimeIndex]; } else { rtb_FromWs = pDataValues[currTimeIndex + 1]; } } else { real_T f1 = (t2 - t) / (t2 - t1); real_T f2 = 1.0 - f1; real_T d1; real_T d2; int_T TimeIndex= currTimeIndex; d1 = pDataValues[TimeIndex]; d2 = pDataValues[TimeIndex + 1]; rtb_FromWs = (real_T) rtInterpolate(d1, d2, f1, f2); pDataValues += 10; } } } /* Outputs for Atomic SubSystem: '<S1>/hl' */ /* Constant: '<Root>/direction' */ motor_test_hierarchies_hl(motor_test_hierarchies_B.enable, rtb_FromWs, motor_test_hierarchies_P.direction_Value, &motor_test_hierarchies_B.hl, (P_hl_motor_test_hierarchies_T *)&motor_test_hierarchies_P.hl); /* End of Outputs for SubSystem: '<S1>/hl' */ /* Outputs for Atomic SubSystem: '<S1>/hr' */ /* Switch: '<S5>/Switch' incorporates: * Constant: '<Root>/direction' * Constant: '<S5>/Constant2' */ if (motor_test_hierarchies_B.enable > motor_test_hierarchies_P.Switch_Threshold) { tmp = motor_test_hierarchies_P.direction_Value; } else { tmp = motor_test_hierarchies_P.Constant2_Value; } /* End of Switch: '<S5>/Switch' */ /* DataTypeConversion: '<S10>/Data Type Conversion' */ if (tmp < 256.0) { if (tmp >= 0.0) { tmp_0 = (uint8_T)tmp; } else { tmp_0 = 0U; } } else { tmp_0 = MAX_uint8_T; } /* End of DataTypeConversion: '<S10>/Data Type Conversion' */ /* S-Function (arduinodigitaloutput_sfcn): '<S10>/Digital Output' */ MW_digitalWrite(motor_test_hierarchies_P.DigitalOutput_pinNumber, tmp_0); /* Switch: '<S5>/Switch1' incorporates: * Constant: '<S5>/Constant3' * DataTypeConversion: '<S11>/Data Type Conversion' */ if (motor_test_hierarchies_B.enable > motor_test_hierarchies_P.Switch1_Threshold) { /* DataTypeConversion: '<S11>/Data Type Conversion' */ if (rtb_FromWs < 256.0) { if (rtb_FromWs >= 0.0) { motor_test_hierarchies_B.DataTypeConversion_b = (uint8_T)rtb_FromWs; } else { motor_test_hierarchies_B.DataTypeConversion_b = 0U; } } else { motor_test_hierarchies_B.DataTypeConversion_b = MAX_uint8_T; } } else if (motor_test_hierarchies_P.Constant3_Value < 256.0) { /* DataTypeConversion: '<S11>/Data Type Conversion' incorporates: * Constant: '<S5>/Constant3' */ if (motor_test_hierarchies_P.Constant3_Value >= 0.0) { motor_test_hierarchies_B.DataTypeConversion_b = (uint8_T) motor_test_hierarchies_P.Constant3_Value; } else { motor_test_hierarchies_B.DataTypeConversion_b = 0U; } } else { /* DataTypeConversion: '<S11>/Data Type Conversion' */ motor_test_hierarchies_B.DataTypeConversion_b = MAX_uint8_T; } /* End of Switch: '<S5>/Switch1' */ /* S-Function (arduinoanalogoutput_sfcn): '<S11>/PWM' */ MW_analogWrite(motor_test_hierarchies_P.PWM_pinNumber, motor_test_hierarchies_B.DataTypeConversion_b); /* Outputs for Atomic SubSystem: '<S1>/vl' */ /* Constant: '<Root>/direction' */ motor_test_hierarchies_hl(motor_test_hierarchies_B.enable, rtb_FromWs, motor_test_hierarchies_P.direction_Value, &motor_test_hierarchies_B.vl, (P_hl_motor_test_hierarchies_T *)&motor_test_hierarchies_P.vl); /* End of Outputs for SubSystem: '<S1>/vl' */ /* Outputs for Atomic SubSystem: '<S1>/vr' */ /* Switch: '<S7>/Switch' incorporates: * Constant: '<Root>/direction' * Constant: '<S7>/Constant2' */ if (motor_test_hierarchies_B.enable > motor_test_hierarchies_P.Switch_Threshold_k) { tmp = motor_test_hierarchies_P.direction_Value; } else { tmp = motor_test_hierarchies_P.Constant2_Value_n; } /* End of Switch: '<S7>/Switch' */ /* DataTypeConversion: '<S14>/Data Type Conversion' */ if (tmp < 256.0) { if (tmp >= 0.0) { tmp_0 = (uint8_T)tmp; } else { tmp_0 = 0U; } } else { tmp_0 = MAX_uint8_T; } /* End of DataTypeConversion: '<S14>/Data Type Conversion' */ /* S-Function (arduinodigitaloutput_sfcn): '<S14>/Digital Output' */ MW_digitalWrite(motor_test_hierarchies_P.DigitalOutput_pinNumber_a, tmp_0); /* Switch: '<S7>/Switch1' incorporates: * Constant: '<S7>/Constant3' * DataTypeConversion: '<S15>/Data Type Conversion' */ if (motor_test_hierarchies_B.enable > motor_test_hierarchies_P.Switch1_Threshold_o) { /* DataTypeConversion: '<S15>/Data Type Conversion' */ if (rtb_FromWs < 256.0) { if (rtb_FromWs >= 0.0) { motor_test_hierarchies_B.DataTypeConversion = (uint8_T)rtb_FromWs; } else { motor_test_hierarchies_B.DataTypeConversion = 0U; } } else { motor_test_hierarchies_B.DataTypeConversion = MAX_uint8_T; } } else if (motor_test_hierarchies_P.Constant3_Value_f < 256.0) { /* DataTypeConversion: '<S15>/Data Type Conversion' incorporates: * Constant: '<S7>/Constant3' */ if (motor_test_hierarchies_P.Constant3_Value_f >= 0.0) { motor_test_hierarchies_B.DataTypeConversion = (uint8_T) motor_test_hierarchies_P.Constant3_Value_f; } else { motor_test_hierarchies_B.DataTypeConversion = 0U; } } else { /* DataTypeConversion: '<S15>/Data Type Conversion' */ motor_test_hierarchies_B.DataTypeConversion = MAX_uint8_T; } /* End of Switch: '<S7>/Switch1' */ /* S-Function (arduinoanalogoutput_sfcn): '<S15>/PWM' */ MW_analogWrite(motor_test_hierarchies_P.PWM_pinNumber_n, motor_test_hierarchies_B.DataTypeConversion); /* External mode */ rtExtModeUploadCheckTrigger(2); { /* Sample time: [0.0s, 0.0s] */ rtExtModeUpload(0, motor_test_hierarchies_M->Timing.t[0]); } { /* Sample time: [1.0s, 0.0s] */ rtExtModeUpload(1, ((motor_test_hierarchies_M->Timing.clockTick1) )); } /* signal main to stop simulation */ { /* Sample time: [0.0s, 0.0s] */ if ((rtmGetTFinal(motor_test_hierarchies_M)!=-1) && !((rtmGetTFinal(motor_test_hierarchies_M)- motor_test_hierarchies_M->Timing.t[0]) > motor_test_hierarchies_M->Timing.t[0] * (DBL_EPSILON))) { rtmSetErrorStatus(motor_test_hierarchies_M, "Simulation finished"); } if (rtmGetStopRequested(motor_test_hierarchies_M)) { rtmSetErrorStatus(motor_test_hierarchies_M, "Simulation finished"); } } /* 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. */ motor_test_hierarchies_M->Timing.t[0] = (++motor_test_hierarchies_M->Timing.clockTick0) * motor_test_hierarchies_M->Timing.stepSize0; { /* Update absolute timer for sample time: [1.0s, 0.0s] */ /* The "clockTick1" counts the number of times the code of this task has * been executed. The resolution of this integer timer is 1.0, which is the step size * of the task. Size of "clockTick1" ensures timer will not overflow during the * application lifespan selected. */ motor_test_hierarchies_M->Timing.clockTick1++; } }