/* ****************************************************************************** ** CarMaker - Version 10.2.1 ** Vehicle Dynamics Simulation Toolkit ** ** Copyright (C) IPG Automotive GmbH ** Bannwaldallee 60 Phone +49.721.98520.0 ** 76185 Karlsruhe Fax +49.721.98520.99 ** Germany WWW www.ipg-automotive.com ****************************************************************************** ** ** Functions ** --------- ** ** Initialization ** ** User_Init_First () ** User_PrintUsage () ** User_ScanCmdLine () ** ** User_AppLogFilter () ** ** User_Init () ** User_Register () ** User_DeclQuants () ** ** User_Param_Add () ** User_Param_Get () ** ** ** Main TestRun Start/End: ** ** User_TestRun_Start_atBegin () ** User_TestRun_Start_atEnd () ** User_TestRun_Start_StaticCond_Calc () ** User_TestRun_Start_Finalize () ** User_TestRun_RampUp () ** ** User_TestRun_End_First () ** User_TestRun_End () ** ** ** Main Cycle: ** ** User_In () ** ** User_DrivMan_Calc () ** User_Traffic_Calc () ** User_VehicleControl_Calc () ** User_Brake_Calc () in Vhcl_Calc () ** User_Calc () ** User_Check_IsIdle () ** ** User_Out () ** ** ** APO Communication: ** ** User_ApoMsg_Eval () ** User_ApoMsg_Send () ** ** User_ShutDown () ** User_End () ** User_Cleanup () ** ** ****************************************************************************** */ #include #if defined(WIN32) # include #endif #include #include #include #if defined(XENO) # include #endif # include #include #include #include #include #include "IOVec.h" #include "User.h" #include "MyModels.h" #include /* @@PLUGIN-BEGIN-INCLUDE@@ - Automatically generated code - don't edit! */ /* @@PLUGIN-END@@ */ int UserCalcCalledByAppTestRunCalc = 0; tUser User; /* ** User_Init_First () ** ** First, low level initialization of the User module ** ** Call: ** - one times at start of program ** - no realtime conditions ** */ int User_Init_First (void) { memset (&User, 0, sizeof(User)); return 0; } /* ** User_PrintUsage () ** ** Print the user/application specific programm arguments */ void User_PrintUsage (const char *Pgm) { /* REMARK: 1 log statement for each usage line, no line breaks */ LogUsage("\n"); LogUsage("Usage: %s [options] [testrun]\n", Pgm); LogUsage("Options:\n"); #if defined(CM_HIL) { const tIOConfig *cf; const char *defio = IO_GetDefault(); LogUsage(" -io %-12s Default I/O configuration (%s)\n", "default", (defio!=NULL && strcmp(defio, "none")!=0) ? defio : "minimal I/O"); for (cf=IO_GetConfigurations(); cf->Name!=NULL; cf++) LogUsage(" -io %-12s %s\n", cf->Name, cf->Description); } #endif } /* ** User_ScanCmdLine () ** ** Scan application specific command line arguments ** ** Return: ** - argv: last unscanned argument ** - NULL: error or unknown argument */ char ** User_ScanCmdLine (int argc, char **argv) { const char *Pgm = argv[0]; /* I/O configuration to be used in case no configuration was specified on the command line. */ IO_SelectDefault("default" /* or "demoapp", "demorbs,demofr" etc. */); while (*++argv) { if (strcmp(*argv, "-io") == 0 && argv[1] != NULL) { if (IO_Select(*++argv) != 0) return NULL; } else if (strcmp(*argv, "-h") == 0 || strcmp(*argv, "-help") == 0) { User_PrintUsage(Pgm); SimCore_PrintUsage(Pgm); /* Possible exit(), depending on CM-platform! */ return NULL; } else if ((*argv)[0] == '-') { LogErrF(EC_General, "Unknown option '%s'", *argv); return NULL; } else { break; } } return argv; } /* ** User_Init () ** ** Basic initialization of the module User.o ** ** Call: ** - once at program start ** - no realtime conditions */ int User_Init (void) { return 0; } int User_Register (void) { Steering_Register_MyModel(); /* @@PLUGIN-BEGIN-REGISTER@@ - Automatically generated code - don't edit! */ /* @@PLUGIN-END@@ */ return 0; } /* ** User_DeclQuants () ** ** Add user specific quantities to the dictionary ** ** Call: ** - once at program start ** - no realtime conditions */ void User_DeclQuants (void) { int i; for (i=0; i) */ int User_TestRun_End (void) { return 0; } /* ** User_In () ** ** Assign quantities of the i/o vector to model variables ** ** Call: ** - in the main loop ** - pay attention to realtime condition ** - just after IO_In() */ void User_In (const unsigned CycleNo) { if (SimCore.State != SCState_Simulate) return; } /* ** User_DrivMan_Calc () ** ** called ** - in RT context ** - after DrivMan_Calc() */ int User_DrivMan_Calc (double dt) { /* Rely on the Vehicle Operator within DrivMan module to get the vehicle in driving state using the IPG's PowerTrain Control model 'Generic' or similar */ if (Vehicle.OperationState != OperState_Driving) return 0; return 0; } /* ** User_VehicleControl_Calc () ** ** called ** - in RT context ** - after VehicleControl_Calc() */ int User_VehicleControl_Calc (double dt) { /* Rely on the Vehicle Operator within DrivMan module to get the vehicle in driving state using the IPG's PowerTrain Control model 'Generic' or similar */ if (Vehicle.OperationState != OperState_Driving) return 0; return 0; } /* ** User_Brake_Calc () ** ** called ** - in RT context ** - after Brake_Calc() in Vhcl_Calc() */ int User_Brake_Calc (double dt) { /* Modify the total brake torque from the brake system model Brake.Trq_tot[] or the target drive source torque from the brake control unit Brake.HydBrakeCU_IF.Trq_DriveSrc_trg[] */ return 0; } /* ** User_Traffic_Calc () ** ** called ** - in RT context ** - after Traffic_Calc() */ int User_Traffic_Calc (double dt) { if (SimCore.State != SCState_Simulate) return 0; return 0; } /* ** User_Calc () ** ** called in RT context */ int User_Calc (double dt) { /* Starting with CM 6.0 User_Calc() will be invoked in EVERY simulation state. Uncomment the following line in order to restore the behaviour of CM 5.1 and earlier. */ /*if (!UserCalcCalledByAppTestRunCalc) return 0;*/ return 0; } /* ** User_Check_IsIdle () ** ** Checking, if the simulation model is in idle conditions (stand still, ** steeringwheel angle zero, cluch pedal pressed, ...). ** If reached idle state, the calculation of vehicle model and driving ** manoevers is stopped. ** Ready for start new simulation. ** ** Return: ** 1 idle state reached ** 0 else ** ** Call: ** - in main task, in the main loop ** - pay attention to realtime condition ** - while SimCore.State==SCState_EndIdleGet */ int User_Check_IsIdle (int IsIdle) { double val; /*** ECU / carmodel signals */ /* vehicle and wheels: stand still */ val = 0.5*kmh2ms; if (Vehicle.v > val || fabs(Vehicle.Wheel[0]->vBelt) > val || fabs(Vehicle.Wheel[1]->vBelt) > val || fabs(Vehicle.Wheel[2]->vBelt) > val || fabs(Vehicle.Wheel[3]->vBelt) > val) { IsIdle = 0; } /* SteerAngle: drive straight forward position */ val = 1.0*deg2rad; if (Vehicle.Steering.Ang > val || Vehicle.Steering.Ang < -val) IsIdle = 0; return IsIdle; } /* ** User_Out () ** ** Assigns model quantities to variables of the i/o vector ** ** call: ** - in the main loop ** - pay attention to realtime condition ** - just before IO_Out(); */ void User_Out (const unsigned CycleNo) { RBS_OutMap(CycleNo); if (SimCore.State != SCState_Simulate) return; } /* ** User_ApoMsg_Eval () ** ** Communication between the application and connected GUIs. ** Evaluate messages from GUIs ** ** Call: ** - in the main loop ** - pay attention to realtime condition ** - near the end of the main loop, if the function SimCore_ApoMsg_Eval() ** skips the message ** ** Return: ** 0 : message evaluated ** -1 : message not handled */ int User_ApoMsg_Eval (int Ch, char *Msg, int len, int who) { #if defined(CM_HIL) /*** FailSafeTester */ if (Ch == ApoCh_CarMaker) { if (FST_ApoMsgEval(Ch, Msg, len) <= 0) return 0; } #endif return -1; } /* ** User_ApoMsg_Send () ** ** Communication between the application and connected GUIs. ** Sends messages to GUIs ** ** Call: ** - near the end of the main loop, in MainThread_FinishCycle() ** - pay attention to realtime condition */ void User_ApoMsg_Send (double T, const unsigned CycleNo) { } /* ** User_ShutDown () ** ** Prepare application for shut down ** ** Call: ** - at end of program ** - no realtime conditions */ int User_ShutDown (int ShutDownForced) { int IsDown = 0; /* Prepare application for shutdown and return that shutdown conditions are reached */ if (1) { IsDown = 1; } return IsDown; } /* ** User_End () ** ** End all models of the user module ** ** Call: ** - one times at end of program ** - no realtime conditions */ int User_End (void) { return 0; } /* ** User_Cleanup () ** ** Cleanup function of the User module ** ** Call: ** - one times at end of program, just before exit ** - no realtime conditions */ void User_Cleanup (void) { }