ld_exp_tro1.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <gsl/gsl_rng.h>
3 #include <gsl/gsl_randist.h>
4 #include <gsl/gsl_math.h>
5 #include <math.h>
6 #include <options/options.h>
7 
8 #include "../csm/csm_all.h"
9 
11  int seed;
12 
13  double max_xy_error;
15 
16  const char* file_input;
17  const char* file_output1;
18  const char* file_output2;
19 
21 
22  int debug;
23 };
24 
25 const char * banner =
26  "This program prepares the data for one of the experiments. \n\n"
27  "The input is any sensor log (Carmen or JSON format) \n"
28  "The output are two files that contain laser_ref and laser_sens\n"
29  "(you have to match the i-th scan in the first file with the i-th\n"
30  " in the second).\n\n"
31  "The two files contain exactly the same date but for the 'odometry' field\n"
32  "The odometry error is uniform in the intervals given.\n";
33 
34 int main(int argc, const char ** argv) {
35  sm_set_program_name(argv[0]);
36 
37  struct ld_exp_tro1_params p;
38 
40 
41  struct option* ops = options_allocate(10);
42  options_double(ops, "max_xy_error", &p.max_xy_error, 10.0, "Maximum error for x,y (m)");
43  options_double(ops, "max_theta_error_deg", &p.max_theta_error_deg, 10.0, "Maximum error for orientation (deg)");
44  options_int (ops, "seed", &p.seed, 0, "Seed for random number generator (if 0, use GSL_RNG_SEED env. variable).");
45 
46  options_int(ops, "num_per_scan", &p.num_per_scan, 10, "Number of trials for each scan.");
47 
48  options_string(ops, "in", &p.file_input, "stdin", "Input file ");
49  options_string(ops, "out1", &p.file_output1, "stdout", "Output file for first scan");
50  options_string(ops, "out2", &p.file_output2, "stdout", "Output file for second scan");
51 
52  options_int(ops, "debug", &p.debug, 0, "Shows debug information");
53 
54  if(!options_parse_args(ops, argc, argv)) {
55  options_print_help(ops, stderr);
56  return -1;
57  }
58 
60 
61  gsl_rng_env_setup();
62  gsl_rng * rng = gsl_rng_alloc (gsl_rng_ranlxs0);
63  if(p.seed != 0)
64  gsl_rng_set(rng, (unsigned int) p.seed);
65 
66  /* Open the two output files (possibly the same one) */
67 
68  FILE * in = open_file_for_reading(p.file_input);
69  if(!in) return -3;
70 
71  FILE * out1 = open_file_for_writing(p.file_output1);
72  if(!out1) return -2;
73 
74  FILE * out2;
75  if(!strcmp(p.file_output1, p.file_output2)) {
76  out1 = out2;
77  } else {
79  if(!out2) return -2;
80  }
81 
82  /* Read laser data from input file */
83  LDP ld; int count=0;
84  while( (ld = ld_read_smart(in))) {
85  count++;
86  if(!ld_valid_fields(ld)) {
87  sm_error("Invalid laser data (#%d in file)\n", count);
88  continue;
89  }
90 
91  for(int n=0; n < p.num_per_scan; n++) {
92  ld->true_pose[0] = 0;
93  ld->true_pose[1] = 0;
94  ld->true_pose[2] = 0;
95 
96  ld->odometry[0] = 0;
97  ld->odometry[1] = 0;
98  ld->odometry[2] = 0;
99 
100  ld_write_as_json(ld, out1);
101 
102  ld->odometry[0] = 2*(gsl_rng_uniform(rng)-0.5) * p.max_xy_error;
103  ld->odometry[1] = 2*(gsl_rng_uniform(rng)-0.5) * p.max_xy_error;
104  ld->odometry[2] = 2*(gsl_rng_uniform(rng)-0.5) * deg2rad(p.max_theta_error_deg);
105 
106  ld_write_as_json(ld, out2);
107  }
108 
109  ld_free(ld);
110  }
111 
112  return 0;
113 }
void options_banner(const char *message)
Definition: options.c:33
#define deg2rad(x)
Definition: gpc_test.c:22
double true_pose[3]
Definition: laser_data.h:38
void sm_set_program_name(const char *name)
Definition: logging.c:21
void ld_write_as_json(LDP ld, FILE *stream)
double odometry[3]
Definition: laser_data.h:39
const char * file_output1
Definition: ld_exp_tro1.c:17
const char * file_output2
Definition: ld_exp_tro1.c:18
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
int ld_valid_fields(LDP ld)
Definition: laser_data.c:179
struct option * ops
Definition: rb_sm.c:31
FILE * open_file_for_writing(const char *filename)
Definition: utils.c:25
LDP ld_read_smart(FILE *)
Definition: options.h:49
void ld_free(LDP ld)
Definition: laser_data.c:87
const char * banner
Definition: ld_exp_tro1.c:25
struct option * options_allocate(int n)
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
void sm_debug_write(int flag)
Definition: logging.c:16
FILE * open_file_for_reading(const char *filename)
Definition: utils.c:19
void options_print_help(struct option *options, FILE *f)
Definition: options.c:398
const char * file_input
Definition: ld_exp_tro1.c:16
int main(int argc, const char **argv)
Definition: ld_exp_tro1.c:34
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
gsl_rng * rng
Definition: ld_resample.c:18
double max_theta_error_deg
Definition: ld_exp_tro1.c:14
void sm_error(const char *msg,...)
Definition: logging.c:49
int options_parse_args(struct option *ops, int argc, const char *argv[])
Definition: options.c:66


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23