Level2_Robot/room_seeker_core/src/room_seeker_level1.cpp
//================================================================================================//
// open_datafile()                                                                                //
//   Arguments : none                                                                             //
//   Return    : bool - Whether data file successfully opened or not                              //
//================================================================================================//
open_datafile()
Arguments : none
Return    : bool - Whether data file successfully opened or not
open_datafile () Arguments : none Return : bool - Whether data file successfully opened or not
bool RoomSeekerLevel1::open_datafile(void){
  char data_file_name[1024];
  char time_str[64];
  struct tm tm;
  time_t t = time(NULL);
  localtime_r(&t, &tm);
  sprintf(time_str, "%04d_%02d_%02d__%02d_%02d_%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  sprintf(data_file_name, "%s%s_%s_%s.csv", dataFileDir.c_str(), preffix, time_str, suffix);
  fp_data = fopen(data_file_name, "w");
  if(fp_data == NULL){
    printf("File open failed. filename = %s\n", data_file_name);
    write_log(fp_log, "File open failed. filename = \n");
    write_log(fp_log, data_file_name);
    return(false);
  }
  write_log(fp_log, "New file opened successfully. File name = \n");
  write_log(fp_log, data_file_name);
  fprintf(fp_data, "time,nMEGA,nFM,nRM,cnt_now[0],cnt_now[1],cnt_now[2],cnt_now[3],omega_res[0],omega_res[1],omega_res[2],omega_res[3],omega_cmd[0],omega_cmd[1],omega_cmd[2],omega_cmd[3],vout[0],vout[1],vout[2],vout[3],dx_res[0],dx_res[1],dx_res[2],dx_cmd[0],dx_cmd[1],dx_cmd[2],x_res[0],x_res[1],x_res[2],x_res_[2],int_gz_hpf,ir_state,ax,ay,az,gx,gy,gz,gz_hpf,mx,my,mz,temp,bat_vol,ps2_button,ps2_analogRX,ps2_analogRY,ps2_analogLX,ps2_analogLY\n");
  return(true);
}
bool RoomSeekerLevel1 :: open_datafile ( void ) { char data_file_name [ 1024 ] ; char time_str [ 64 ] ; struct tm tm ; time_t t = time ( NULL ) ; localtime_r ( & t , & tm ) ; sprintf ( time_str , " " , tm . tm_year + 1900 , tm . tm_mon + 1 , tm . tm_mday , tm . tm_hour , tm . tm_min , tm . tm_sec ) ; sprintf ( data_file_name , " " , dataFileDir . c_str ( ) , preffix , time_str , suffix ) ; fp_data = fopen ( data_file_name , " " ) ; if ( fp_data == NULL ) { printf ( " \n " , data_file_name ) ; write_log ( fp_log , " \n " ) ; write_log ( fp_log , data_file_name ) ; return ( false ) ; } write_log ( fp_log , " \n " ) ; write_log ( fp_log , data_file_name ) ; fprintf ( fp_data , " \n " ) ; return ( true ) ; }
open_datafile()
Arguments : none
Return    : bool - Whether data file successfully opened or not
open_datafile () Arguments : none Return : bool - Whether data file successfully opened or not