/* * File: Model_actuator.c * * Code generated for Simulink model 'Model_actuator'. * * Model version : 1.538 * Simulink Coder version : 24.1 (R2024a) 19-Nov-2023 * C/C++ source code generated on : Fri Dec 19 14:23:04 2025 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex-M * Emulation hardware selection: * Differs from embedded hardware (MATLAB Host) * Code generation objectives: Unspecified * Validation result: Not run */ #include "Model_actuator.h" #include #include "Model_actuator_private.h" #include "Model_actuator_types.h" /* Exported block states */ ActuatorCmdBus controllerData; /* '/Data Store Memory15' */ /* Block signals (default storage) */ B rtB; /* Block states (default storage) */ DW rtDW; /* External inputs (root inport signals with default storage) */ ExtU rtU; /* External outputs (root outports fed by signals with default storage) */ ExtY rtY; /* Real-time model */ static RT_MODEL rtM_; RT_MODEL *const rtM = &rtM_; /* * Output and update for action system: * '/If Action Subsystem2' * '/If Action Subsystem2' */ void IfActionSubsystem2(int8_t rtu_stepIn, int8_t *rty_step, uint8_t rtd_autos_set_loc[9], uint8_t rtd_coils_stop_set_loc[9], uint8_t rtd_com_loc[9], uint8_t rtd_lnoise_set_loc[9], uint8_t rtd_speed_set_loc[9], uint8_t rtd_stall_set_loc[9]) { int32_t i; for (i = 0; i < 9; i++) { /* DataStoreWrite: '/Data Store Write1' incorporates: * Constant: '/Constant1' */ rtd_stall_set_loc[i] = 0U; /* DataStoreWrite: '/Data Store Write3' incorporates: * Constant: '/Constant2' */ rtd_lnoise_set_loc[i] = 0U; /* DataStoreWrite: '/Data Store Write2' */ rtd_com_loc[i] = 2U; /* DataStoreWrite: '/Data Store Write4' incorporates: * Constant: '/Constant4' */ rtd_autos_set_loc[i] = 0U; /* DataStoreWrite: '/Data Store Write5' incorporates: * Constant: '/Constant5' */ rtd_speed_set_loc[i] = 0U; /* DataStoreWrite: '/Data Store Write6' incorporates: * Constant: '/Constant6' */ rtd_coils_stop_set_loc[i] = 0U; } /* Sum: '/step inc' incorporates: * Constant: '/Constant' */ *rty_step = (int8_t)(rtu_stepIn + 1); } /* Model step function */ void Model_actuator_step(void) { int32_t i; uint16_t tmp; int8_t rtb_Switch; /* BusCreator: '/Bus Creator' incorporates: * DataStoreRead: '/Data Store Read1' * DataStoreRead: '/Data Store Read2' * DataStoreRead: '/Data Store Read3' * DataStoreRead: '/Data Store Read4' * DataStoreRead: '/Data Store Read5' * DataStoreRead: '/Data Store Read6' * DataStoreRead: '/Data Store Read7' * DataStoreRead: '/Data Store Read8' * DataStoreRead: '/Data Store Read9' * DataStoreWrite: '/Data Store Write' */ for (i = 0; i < 9; i++) { controllerData.POS[i] = rtDW.pos_loc[i]; controllerData.BUS_ADR[i] = rtDW.busAdr_loc[i]; controllerData.MODE[i] = rtDW.mode_loc[i]; controllerData.COM[i] = rtDW.com_loc[i]; controllerData.Stall_SET[i] = rtDW.stall_set_loc[i]; controllerData.Lnoise_SET[i] = rtDW.lnoise_set_loc[i]; controllerData.Autos_SET[i] = rtDW.autos_set_loc[i]; controllerData.Speed_SET[i] = rtDW.speed_set_loc[i]; controllerData.Coils_Stop_SET[i] = rtDW.coils_stop_set_loc[i]; } /* End of BusCreator: '/Bus Creator' */ /* Switch: '/Switch' incorporates: * Constant: '/Constant1' * DataStoreRead: '/Data Store Read' * UnitDelay: '/Unit Delay' */ if (rtDW.stepSig >= 1) { rtb_Switch = rtDW.UnitDelay_DSTATE; } else { rtb_Switch = 1; } /* End of Switch: '/Switch' */ /* SwitchCase: '/Switch Case' */ switch (rtb_Switch) { case 1: /* Outputs for IfAction SubSystem: '/Stop Mode' incorporates: * ActionPort: '/Action Port' */ /* If: '/If1' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem2' incorporates: * ActionPort: '/Action Port' */ for (i = 0; i < 9; i++) { /* DataStoreWrite: '/Data Store Write2' */ rtDW.mode_loc[i] = 2U; /* DataStoreWrite: '/Data Store Write3' */ rtDW.com_loc[i] = 0U; } /* Merge: '/Merge' incorporates: * Constant: '/Constant' * Merge: '/Merge' * Sum: '/step inc' */ rtB.Merge = (int8_t)(rtb_Switch + 1); /* End of Outputs for SubSystem: '/If Action Subsystem2' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If1' */ /* MATLAB Function: '/stop mode' */ /* : y = step; */ /* : fprintf('Stop Mode\n'); */ printf("Stop Mode\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Stop Mode' */ break; case 2: /* Outputs for IfAction SubSystem: '/Initial CPOS Min' incorporates: * ActionPort: '/Action Port' */ /* If: '/If' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem' incorporates: * ActionPort: '/Action Port' */ for (i = 0; i < 9; i++) { /* DataStoreWrite: '/Data Store Write' */ rtDW.pos_loc[i] = 6000U; /* DataStoreWrite: '/Data Store Write1' */ rtDW.com_loc[i] = 1U; } /* Merge: '/Merge' incorporates: * Constant: '/Constant' * Merge: '/Merge' * Sum: '/step inc' */ rtB.Merge = (int8_t)(rtb_Switch + 1); /* End of Outputs for SubSystem: '/If Action Subsystem' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/step' * SignalConversion generated from: '/stepIn1' */ /* : y = step; */ /* : coder.extrinsic('fprintf'); */ /* : fprintf('Actuator else: step = %d\n', step); */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If' */ /* MATLAB Function: '/Initial CPOS Min' */ /* : y = step; */ /* : fprintf('Initial CPOS Min\n'); */ printf("Initial CPOS Min\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Initial CPOS Min' */ break; case 3: /* Outputs for IfAction SubSystem: '/Normal Mode' incorporates: * ActionPort: '/Action Port' */ /* If: '/If1' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem2' incorporates: * ActionPort: '/Action Port' */ for (i = 0; i < 9; i++) { /* DataStoreWrite: '/Data Store Write' */ rtDW.mode_loc[i] = 0U; /* DataStoreWrite: '/Data Store Write2' */ rtDW.com_loc[i] = 0U; } /* Merge: '/Merge' incorporates: * Constant: '/Constant' * Merge: '/Merge' * Sum: '/step inc' */ rtB.Merge = (int8_t)(rtb_Switch + 1); /* End of Outputs for SubSystem: '/If Action Subsystem2' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If1' */ /* MATLAB Function: '/Normal Mode' */ /* : y = step; */ /* : fprintf('Normal Mode\n'); */ printf("Normal Mode\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Normal Mode' */ break; case 4: /* Outputs for IfAction SubSystem: '/Move to position Min' incorporates: * ActionPort: '/Action Port' */ /* If: '/If1' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem2' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' */ IfActionSubsystem2(rtb_Switch, &rtB.Merge, rtDW.autos_set_loc, rtDW.coils_stop_set_loc, rtDW.com_loc, rtDW.lnoise_set_loc, rtDW.speed_set_loc, rtDW.stall_set_loc); /* End of Outputs for SubSystem: '/If Action Subsystem2' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If1' */ /* MATLAB Function: '/Move to position Min' */ /* : y = step; */ /* : fprintf('Move to position Min\n'); */ printf("Move to position Min\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Move to position Min' */ break; case 5: /* Outputs for IfAction SubSystem: '/Check Stall Min' incorporates: * ActionPort: '/Action Port' */ /* If: '/If1' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem2' incorporates: * ActionPort: '/Action Port' */ /* DataStoreWrite: '/Data Store Write1' incorporates: * DataStoreWrite: '/Data Store Write1' * Inport: '/in_CPOS_ALL_Ch0' */ for (i = 0; i < 9; i++) { rtDW.Min_position_Ch0[i] = rtU.in_CPOS_ALL_Ch0[i]; } /* End of DataStoreWrite: '/Data Store Write1' */ /* Merge: '/Merge' incorporates: * Constant: '/Constant' * Merge: '/Merge' * Sum: '/step inc' */ rtB.Merge = (int8_t)(rtb_Switch + 1); /* End of Outputs for SubSystem: '/If Action Subsystem2' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If1' */ /* MATLAB Function: '/Check Stall Min' */ /* : y = step; */ /* : fprintf('Check Stall Min\n'); */ printf("Check Stall Min\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Check Stall Min' */ break; case 6: /* Outputs for IfAction SubSystem: '/Initial CPOS Max' incorporates: * ActionPort: '/Action Port' */ /* If: '/If1' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem2' incorporates: * ActionPort: '/Action Port' */ for (i = 0; i < 9; i++) { /* DataStoreWrite: '/Data Store Write' */ rtDW.pos_loc[i] = 0U; /* DataStoreWrite: '/Data Store Write1' */ rtDW.com_loc[i] = 1U; } /* Merge: '/Merge' incorporates: * Constant: '/Constant' * Merge: '/Merge' * Sum: '/step inc' */ rtB.Merge = (int8_t)(rtb_Switch + 1); /* End of Outputs for SubSystem: '/If Action Subsystem2' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If1' */ /* MATLAB Function: '/Initial CPOS Max' */ /* : y = step; */ /* : fprintf('Initial CPOS Max\n'); */ printf("Initial CPOS Max\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Initial CPOS Max' */ break; case 7: /* Outputs for IfAction SubSystem: '/Move to position Max' incorporates: * ActionPort: '/Action Port' */ /* If: '/If1' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem2' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' */ IfActionSubsystem2(rtb_Switch, &rtB.Merge, rtDW.autos_set_loc, rtDW.coils_stop_set_loc, rtDW.com_loc, rtDW.lnoise_set_loc, rtDW.speed_set_loc, rtDW.stall_set_loc); /* End of Outputs for SubSystem: '/If Action Subsystem2' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If1' */ /* MATLAB Function: '/Move to position Max' */ /* : y = step; */ /* : fprintf('Move to position Max\n'); */ printf("Move to position Max\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Move to position Max' */ break; case 8: /* Outputs for IfAction SubSystem: '/Check Stall Max' incorporates: * ActionPort: '/Action Port' */ /* If: '/If1' incorporates: * Inport: '/in_Busy_Ch0' * Inport: '/in_Error_Connect_Ch0' */ if ((rtU.in_Busy_Ch0 == 0) && (rtU.in_Error_Connect_Ch0 == 0)) { /* Outputs for IfAction SubSystem: '/If Action Subsystem2' incorporates: * ActionPort: '/Action Port' */ /* DataStoreWrite: '/Data Store Write1' incorporates: * DataStoreWrite: '/Data Store Write1' * Inport: '/in_CPOS_ALL_Ch0' */ for (i = 0; i < 9; i++) { rtDW.Max_position_Ch0[i] = rtU.in_CPOS_ALL_Ch0[i]; } /* End of DataStoreWrite: '/Data Store Write1' */ /* Merge: '/Merge' incorporates: * Constant: '/Constant' * Merge: '/Merge' * Sum: '/step inc' */ rtB.Merge = (int8_t)(rtb_Switch + 1); /* End of Outputs for SubSystem: '/If Action Subsystem2' */ } else { /* Outputs for IfAction SubSystem: '/If Action Subsystem3' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Merge: '/Merge' * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/If Action Subsystem3' */ } /* End of If: '/If1' */ /* MATLAB Function: '/Check Stall Max' */ /* : y = step; */ /* : fprintf('Check Stall Max\n'); */ printf("Check Stall Max\n"); fflush(stdout); /* End of Outputs for SubSystem: '/Check Stall Max' */ break; case 9: /* Outputs for IfAction SubSystem: '/Homing' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * Constant: '/Constant2' * SignalConversion generated from: '/step' */ rtB.Merge = 1; /* MATLAB Function: '/MAX POSITION' incorporates: * DataStoreRead: '/Data Store Read2' */ /* : y = step; */ /* : fprintf('MAX POSITION '); */ printf("MAX POSITION "); fflush(stdout); /* : for i = 1:numel(step) */ for (i = 0; i < 9; i++) { /* : fprintf('%d ', int16(step(i))); */ tmp = rtDW.Max_position_Ch0[i]; if (tmp > 32767) { tmp = 32767U; } printf("%d ", (int16_t)tmp); fflush(stdout); } /* : fprintf('\n'); */ printf("\n"); fflush(stdout); /* End of MATLAB Function: '/MAX POSITION' */ /* MATLAB Function: '/MIN POSITION' incorporates: * DataStoreRead: '/Data Store Read3' */ /* : y = step; */ /* : fprintf('MIN POSITION '); */ printf("MIN POSITION "); fflush(stdout); /* : for i = 1:numel(step) */ for (i = 0; i < 9; i++) { /* : fprintf('%d ', int16(step(i))); */ tmp = rtDW.Min_position_Ch0[i]; if (tmp > 32767) { tmp = 32767U; } printf("%d ", (int16_t)tmp); fflush(stdout); } /* : fprintf('\n'); */ printf("\n"); fflush(stdout); /* End of MATLAB Function: '/MIN POSITION' */ /* End of Outputs for SubSystem: '/Homing' */ break; case 0: /* Outputs for IfAction SubSystem: '/Homing1' incorporates: * ActionPort: '/Action Port' */ /* Merge: '/Merge' incorporates: * SignalConversion generated from: '/stepIn' */ rtB.Merge = rtb_Switch; /* End of Outputs for SubSystem: '/Homing1' */ break; } /* End of SwitchCase: '/Switch Case' */ /* Outport: '/Out1' incorporates: * DataStoreRead: '/Data Store Read10' */ rtY.Out1 = controllerData; /* DataStoreWrite: '/Start write stepSig' incorporates: * Constant: '/Constant1' */ rtDW.stepSig = 1; /* MATLAB Function: '/Finish case' incorporates: * UnitDelay: '/Unit Delay' */ /* : y = step; */ /* : fprintf('Finish case: step = %d\n', step); */ printf("Finish case: step = %d\n", rtDW.UnitDelay_DSTATE); fflush(stdout); /* MATLAB Function: '/Start case' */ /* : y = step; */ /* : fprintf('Start case: step = %d\n', step); */ printf("Start case: step = %d\n", rtb_Switch); fflush(stdout); /* Update for UnitDelay: '/Unit Delay' */ rtDW.UnitDelay_DSTATE = rtB.Merge; } /* Model initialize function */ void Model_actuator_initialize(void) { /* (no initialization code required) */ } /* Model terminate function */ void Model_actuator_terminate(void) { /* (no terminate code required) */ } /* * File trailer for generated code. * * [EOF] */