19 "USAGE: stage [options] <worldfile1> [worldfile2 ... worldfileN]\n" 20 "Available [options] are:\n" 21 " --clock : print simulation time peridically on standard output\n" 22 " -c : equivalent to --clock\n" 23 " --gui : run without a GUI\n" 24 " -g : equivalent to --gui\n" 25 " --help : print this message\n" 26 " --args \"str\" : define an argument string to be passed to all controllers\n" 27 " -a \"str\" : equivalent to --args \"str\"\n" 28 " --host \"str\" : set the http server host name (default: \"localhost\")\n" 29 " --port num : set the http sever port number (default: 8000)\n" 30 " --verbose : provide lots of informative output\n" 31 " -v : equivalent to --verbose\n" 32 " -? : equivalent to --help\n";
36 {
"gui", optional_argument, NULL,
'g' },
37 {
"clock", optional_argument, NULL,
'c' },
38 {
"help", optional_argument, NULL,
'h' },
39 {
"args", required_argument, NULL,
'a' },
40 {
"verbose", no_argument, NULL,
'v' },
41 {
"port", required_argument, NULL,
'p' },
42 {
"host", required_argument, NULL,
'h' },
43 {
"rootdir", required_argument, NULL,
'r' },
52 return static_cast<uint64_t
>(stgtime);
66 bzero(pva,
sizeof(av_pva_t));
134 bzero(g,
sizeof(av_geom_t));
139 g->
pose[0] = ext.pose.
x;
140 g->pose[1] = ext.pose.y;
141 g->pose[2] = ext.pose.a;
142 g->extent[0] = ext.size.x;
143 g->extent[1] = ext.size.y;
144 g->extent[2] = ext.size.z;
161 static av_ranger_data_t rd;
162 bzero(&rd,
sizeof(rd));
163 bzero(data,
sizeof(av_msg_t));
166 data->interface = AV_INTERFACE_RANGER;
167 data->data = (
const void*)&rd;
171 const std::vector<Stg::ModelRanger::Sensor>& sensors = r->
GetSensors();
173 rd.transducer_count = sensors.size();
175 assert( rd.transducer_count <= AV_RANGER_TRANSDUCERS_MAX );
177 rd.time = data->time;
188 puts(
"ranger set does nothing" );
197 static av_ranger_t rgr;
198 bzero(&rgr,
sizeof(rgr));
201 data->interface = AV_INTERFACE_RANGER;
202 data->data = (
const void*)&rgr;
204 rgr.time = data->time;
208 const std::vector<Stg::ModelRanger::Sensor>& sensors = r->
GetSensors();
210 rgr.transducer_count = sensors.size();
212 assert( rgr.transducer_count <= AV_RANGER_TRANSDUCERS_MAX );
215 for(
unsigned int c=0; c<rgr.transducer_count; c++ )
218 rgr.transducers[c].fov[0].min = -sensors[c].fov/2.0;
219 rgr.transducers[c].fov[0].max = sensors[c].fov/2.0;
222 rgr.transducers[c].fov[1].min = 0.0;
223 rgr.transducers[c].fov[1].max = 0.0;
226 rgr.transducers[c].fov[2].min = sensors[c].range.min;
227 rgr.transducers[c].fov[2].min = sensors[c].range.max;
230 rgr.transducers[c].geom.pose[0] = sensors[c].pose.x;
231 rgr.transducers[c].geom.pose[1] = sensors[c].pose.y;
232 rgr.transducers[c].geom.pose[2] = sensors[c].pose.z;
233 rgr.transducers[c].geom.pose[3] = 0.0;
234 rgr.transducers[c].geom.pose[4] = 0.0;
235 rgr.transducers[c].geom.pose[5] = sensors[c].pose.a;
238 rgr.transducers[c].geom.extent[0] = sensors[c].size.x;
239 rgr.transducers[c].geom.extent[1] = sensors[c].size.y;
240 rgr.transducers[c].geom.extent[2] = sensors[c].size.z;
243 av_ranger_transducer_data_t& t = rgr.transducers[c];
246 t.pose[0] = s.
pose.
x;
247 t.pose[1] = s.
pose.
y;
248 t.pose[2] = s.
pose.
z;
251 t.pose[5] = s.
pose.
a;
253 const std::vector<Stg::meters_t>& ranges = s.
ranges;
254 const std::vector<double>& intensities = s.
intensities;
256 assert( ranges.size() == intensities.size() );
258 t.sample_count = ranges.size();
260 const double fov_max = s.
fov / 2.0;
261 const double fov_min = -fov_max;
262 const double delta = (fov_max - fov_min) / (
double)t.sample_count;
264 for(
unsigned int r=0; r<t.sample_count; r++ )
266 t.samples[r][AV_SAMPLE_BEARING] = fov_min + r*delta;
267 t.samples[r][AV_SAMPLE_AZIMUTH] = 0.0;
268 t.samples[r][AV_SAMPLE_RANGE] = ranges[r];
269 t.samples[r][AV_SAMPLE_INTENSITY] = intensities[r];
287 static av_fiducial_data_t fd;
288 bzero(&fd,
sizeof(fd));
289 bzero(data,
sizeof(av_msg_t));
292 data->interface = AV_INTERFACE_FIDUCIAL;
293 data->data = (
const void*)&fd;
297 const std::vector<Stg::ModelFiducial::Fiducial>& sf = fm->
GetFiducials();
299 fd.fiducial_count = sf.size();
301 printf(
"FIDUCIALS %u\n", fd.fiducial_count );
303 for(
size_t i=0; i<fd.fiducial_count; i++ )
305 fd.fiducials[i].pose[0] = sf[i].bearing;
306 fd.fiducials[i].pose[1] = 0.0;
307 fd.fiducials[i].pose[2] = sf[i].range;
309 fd.fiducials[i].geom.pose[0] = 0.0;
310 fd.fiducials[i].geom.pose[1] = 0.0;
311 fd.fiducials[i].geom.pose[2] = 0.0;
312 fd.fiducials[i].geom.pose[3] = 0.0;
313 fd.fiducials[i].geom.pose[4] = 0.0;
314 fd.fiducials[i].geom.pose[5] = sf[i].geom.a;
316 fd.fiducials[i].geom.extent[0] = sf[i].geom.x;
317 fd.fiducials[i].geom.extent[1] = sf[i].geom.y;
318 fd.fiducials[i].geom.extent[2] = sf[i].geom.z;
329 puts(
"fiducial setcfg does nothing" );
339 static av_fiducial_cfg_t cfg;
340 bzero(&cfg,
sizeof(cfg));
343 msg->interface = AV_INTERFACE_FIDUCIAL;
344 msg->data = (
const void*)&cfg;
351 cfg.
fov[0].min = -fid->
fov/2.0;
352 cfg.fov[0].max = fid->
fov/2.0;
374 Reg(
const std::string& prototype,
375 av_interface_t interface,
376 av_prop_get_t getter,
377 av_prop_set_t setter ) :
378 prototype(prototype),
379 interface(interface),
390 if( mod->
TokenStr() ==
"_ground_model" )
393 static std::map<std::string,Reg> type_table;
395 if( type_table.size() == 0 )
397 type_table[
"model" ] =
398 Reg(
"generic", AV_INTERFACE_GENERIC,NULL,NULL );
400 type_table[
"position" ] =
401 Reg(
"position2d", AV_INTERFACE_GENERIC,NULL,NULL );
403 type_table[
"ranger" ] =
406 type_table[
"fiducial" ] =
407 Reg(
"fiducial", AV_INTERFACE_FIDUCIA, FiducualGet, FiducualSet );
410 printf(
"[AvonStage] registering %s\n", mod->
Token() );
414 const std::map<std::string,proto_iface_pair_t>::iterator it =
417 if( it != type_table.end() )
420 const char* parent_name = parent ? parent->
Token() : NULL;
422 av_register_object( mod->
Token(),
424 it->prototype.c_str(),
428 dynamic_cast<void*
>(mod) );
433 printf(
"Avonstage error: model type \"%s\" not found.\n",
443 printf(
"%s %s ", PROJECT, VERSION );
445 int ch=0, optindex=0;
447 bool showclock =
false;
449 std::string host =
"localhost";
450 std::string rootdir =
".";
451 unsigned short port = AV_DEFAULT_PORT;
454 while ((ch = getopt_long(argc, argv,
"cvrgh?p?",
longopts, &optindex)) != -1)
459 printf(
"option %s given\n",
longopts[optindex].name );
468 printf(
"[Clock enabled]" );
472 printf(
"[GUI disabled]" );
480 host = std::string(optarg);
487 rootdir = std::string(optarg);
498 printf(
"unhandled option %c\n", ch );
504 const char* worldfilename = argv[optind];
506 if( worldfilename == NULL )
508 puts(
"[AvonStage] no worldfile specified on command line. Quit.\n" );
514 printf(
"[AvonStage] host %s:%u world %s\n",
520 snprintf( version, 1024,
"%s (%s-%s)",
526 av_init( host.c_str(), port, rootdir.c_str(),
verbose,
"AvonStage", version );
537 world->
Load( worldfilename );
538 world->ShowClock( showclock );
541 av_install_clock_callbacks( (av_clock_get_t)
GetTimeWorld, world );
549 if( ! world->paused )
562 puts(
"\n[AvonStage: done]" );
radians_t fov
field of view
meters_t max_range_anon
maximum detection range
int RangerGet(Stg::Model *mod, av_msg_t *data)
int GetModelGeom(Stg::Model *mod, av_geom_t *g)
usec_t SimTimeNow(void) const
std::vector< Fiducial > & GetFiducials()
void SetPose(const Pose &pose)
int RegisterModel(Stg::Model *mod, void *dummy)
void Init(int *argc, char **argv[])
int SetModelPVA(Stg::Model *mod, av_pva_t *p)
std::pair< std::string, av_interface_t > proto_iface_pair_t
Reg(const std::string &prototype, av_interface_t interface, av_prop_get_t getter, av_prop_set_t setter)
meters_t z
location in 3 axes
uint64_t GetTime(Stg::Model *mod)
uint64_t GetTimeWorld(Stg::World *world)
int FiducialData(Stg::Model *mod, av_msg_t *data)
int SetModelGeom(Stg::Model *mod, av_geom_t *g)
int main(int argc, char *argv[])
const std::vector< Sensor > & GetSensors() const
int RangerData(Stg::Model *mod, av_msg_t *data)
int GetModelPVA(Stg::Model *mod, av_pva_t *pva)
int RangerSet(Stg::Model *mod, av_msg_t *data)
int FiducialGet(Stg::Model *mod, av_msg_t *msg)
static struct option longopts[]
const std::string & TokenStr() const
bool HasSubscribers() const
void SetGeom(const Geom &src)
radians_t a
rotation about the z axis.
meters_t min_range
minimum detection range
std::vector< meters_t > ranges
const std::string & GetModelType() const
std::vector< double > intensities
static std::string ctrlargs
const char * Token() const
int FiducialSet(Stg::Model *mod, av_msg_t *data)
const char * AVONSTAGE_VERSION
virtual void Load(const std::string &worldfile_path)