Go to the documentation of this file.00001 #include <time.h>
00002
00003 #include <options/options.h>
00004
00005 #include "../csm/csm_all.h"
00006
00007 int ld_equal_readings(LDP ld1, LDP ld2, double epsilon);
00008
00009 int main(int argc, const char*argv[]) {
00010 sm_set_program_name(argv[0]);
00011
00012 double epsilon;
00013 int debug;
00014
00015
00016 struct option* ops = options_allocate(3);
00017 options_double(ops, "epsilon", &epsilon, 0.0001, "minimum difference between rays to be used");
00018
00019
00020 if(!options_parse_args(ops, argc, argv)) {
00021 options_print_help(ops, stderr);
00022 return -1;
00023 }
00024
00025 sm_debug_write(debug);
00026
00027
00028
00029 LDP laser_ref=0, laser_sens;
00030
00031 int count = -1;
00032 int num_discarded = 0;
00033 int num_invalid = 0;
00034 int ref_index = 0;
00035
00036 while( (laser_sens = ld_read_smart(stdin)) ) {
00037 count++;
00038
00039 if(!ld_valid_fields(laser_sens)) {
00040 sm_error("Invalid laser data (#%d in file)\n", count);
00041 num_invalid++;
00042 continue;
00043 }
00044
00045 if(!laser_ref) {
00046 laser_ref = laser_sens;
00047 ld_write_as_json(laser_sens, stdout);
00048 count++;
00049 continue;
00050 }
00051
00052 if(ld_equal_readings(laser_ref, laser_sens, epsilon)) {
00053 sm_debug("Ignoring scan #%d, too similar to #%d.\n", count, ref_index);
00054 num_discarded++;
00055 } else {
00056 ld_write_as_json(laser_sens, stdout);
00057 ld_free(laser_ref);
00058 laser_ref = laser_sens;
00059 ref_index = count;
00060 }
00061
00062 }
00063 if(laser_ref) ld_free(laser_ref);
00064
00065 sm_info("# epsilon: %f m\n", epsilon);
00066 sm_info("# scans: %d\n", count);
00067 if(count>0) {
00068 sm_info("# invalid: %d\n", num_invalid);
00069 sm_info("# discarded: %d (%d%%)\n", num_discarded, num_discarded * 100 / count);
00070 }
00071
00072 return num_invalid;
00073 }
00074
00075
00076
00077 int ld_equal_readings(LDP ld1, LDP ld2, double epsilon) {
00078 int i;
00079 for(i=0;i<ld1->nrays;i++) {
00080 if(!ld_valid_ray(ld1,i) || !ld_valid_ray(ld2,i)) continue;
00081
00082 if(fabs(ld1->readings[i]-ld2->readings[i]) > epsilon)
00083 return 0;
00084 }
00085 return 1;
00086 }