maglev_timer.cc

Go to the documentation of this file.
00001 
00008 #include "maglev_timer.h"
00009 #include <string.h>
00010 
00011 
00012 
00013 maglev_timer::maglev_timer(const char * mod_name) : cd_control_module(mod_name)
00014 {
00015         plog("maglev_timer\n");
00016 }
00017 
00018 void maglev_timer::initialize_data()
00019 {
00020         double control_period = 0.005;
00021     control_period_command_ref = create_data( NULL, "control_period_command", sd_type_double, "s", "Control period" , &control_period ); 
00022 
00023         mark_command( control_period_command_ref );
00024 
00025         // Request events
00026         request_event_notification( CD_SYSTEM_GROUP, CD_SIMULATION_STEP_EVENT, 1 );
00027 }
00028 
00029 void maglev_timer::initialize()
00030 {
00031         jD0                                     = -1.0;         
00032         met_last                        =  0.0;         
00033         control_time_last       =  0.0;         
00034         perctol                         =  0.02;        
00035 }
00036 
00037 void maglev_timer::handle_event(int code)
00038 {
00039         if (code == 1)
00040         {
00041                 trigger_event(NULL,"INIT_TRIGGER");
00042                 
00043                 double control_period;
00044                 
00045                 bool valid = value_as_type(control_period_command_ref, sd_type_double, &control_period);
00046                 
00047                 // Get Mission Elapsed Time
00048                 double met = get_met();
00049                 
00050                 if( !valid )
00051                 {
00052                         plog("control_period_command not valid.\n");
00053                         return;
00054                 }
00055                 
00056                 // EXECUTE THESE MODULES IN ORDER EVERY CONTROL_PERIOD
00057                 if( met-control_time_last >= control_period*(1-perctol) )
00058                 {       
00059                         trigger_event(NULL,"MAGLEV_CONTROL_TRIGGER");
00060                         
00061                         control_time_last = met;
00062                 }
00063         }
00064 }
00065 
00066 double maglev_timer::get_met()
00067 {
00068         ds_date dd = current_time();
00069         if( jD0<0 ){ jD0 = dd.jd(); }
00070         return (dd.jd()-jD0)*86400.0;
00071 }
00072 
00073 
00074 cd_control_module *maglev_timer_builder(const char *name)
00075 {
00076     return new maglev_timer(name);
00077 }
 All Classes Files Functions Variables