Skip to content

Commit 791aac4

Browse files
committed
fixing up more examples
1 parent e7ae061 commit 791aac4

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

examples/ctrl/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ SET( PLUGINS
66
wander
77
# wander_pioneer
88
pioneer_flocking
9-
rasterize
10-
dynamic
9+
rasterize
10+
lasernoise
11+
dynamic
1112
)
1213

1314
# need plaer's wavefront planning library for this one

examples/ctrl/lasernoise.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
File lasernoise.cc: laser noise plugin demo for Stage
2+
File rangernoise.cc: ranger noise plugin demo for Stage
33
Author: Richard Vaughan
44
Date: 3 March 2008
5-
CVS: $Id: lasernoise.cc,v 1.1 2008-03-04 02:09:56 rtv Exp $
5+
CVS: $Id: rangernoise.cc,v 1.1 2008-03-04 02:09:56 rtv Exp $
66
*/
77

88
#include "stage.hh"
@@ -20,17 +20,17 @@ double simple_normal_deviate( double mean, double stddev )
2020
return ( stddev * (x - 6.0) + mean );
2121
}
2222

23-
// process the laser data
24-
int LaserUpdate( ModelLaser* mod, void* dummy )
23+
// process the ranger data
24+
int RangerUpdate( ModelRanger* mod, void* dummy )
2525
{
2626
// get the data
2727
uint32_t sample_count=0;
2828

29-
const std::vector<ModelLaser::Sample>& scan = mod->GetSamples();
29+
std::vector<meters_t>& scan = mod->GetRangesMutable();
3030

3131
if( scan.size()>0 )
3232
FOR_EACH( it, scan )
33-
it->range *= simple_normal_deviate( 1.0, DEVIATION );
33+
*it *= simple_normal_deviate( 1.0, DEVIATION );
3434

3535
return 0; // run again
3636
}
@@ -39,10 +39,10 @@ int LaserUpdate( ModelLaser* mod, void* dummy )
3939
// the model that gets called just after the sensor update is done.
4040
extern "C" int Init( Model* mod )
4141
{
42-
mod->AddUpdateCallback( (model_callback_t)LaserUpdate, NULL );
43-
42+
mod->AddCallback( Model::CB_UPDATE, (model_callback_t)RangerUpdate, NULL );
43+
4444
// add this so we can see the effects immediately, without needing
45-
// anyone else to subscribe to the laser
45+
// anyone else to subscribe to the ranger
4646
mod->Subscribe();
4747

4848
return 0; // ok

libstage/stage.hh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,9 +2756,20 @@ namespace Stg
27562756
const std::vector<Sensor>& GetSensors() const
27572757
{ return sensors; }
27582758

2759-
/** returns a vector of range samples from the indicated sensor
2760-
(defaults to zero) */
2759+
/** returns a const reference to the vector of range samples from
2760+
the indicated sensor (defaults to zero) */
27612761
const std::vector<meters_t>& GetRanges( unsigned int sensor=0) const
2762+
{
2763+
if( sensor < sensors.size() )
2764+
return sensors[sensor].ranges;
2765+
2766+
PRINT_ERR1( "invalid sensor index specified (%d)", sensor );
2767+
exit(-1);
2768+
}
2769+
2770+
/** returns a mutable reference to the vector of range samples from
2771+
the indicated sensor (defaults to zero). Mutating the range data in place allows controllers to act as filters. */
2772+
std::vector<meters_t>& GetRangesMutable( unsigned int sensor=0)
27622773
{
27632774
if( sensor < sensors.size() )
27642775
return sensors[sensor].ranges;

worlds/simple.world

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ pioneer2dx
4141
pose [ -6.432 -5.895 0 45.000 ]
4242

4343
# pioneer2dx's sonars will be ranger:0 and the laser will be ranger:1
44-
sicklaser( pose [ 0 0 0 0 ] )
44+
sicklaser(
45+
pose [ 0 0 0 0 ]
46+
47+
# uncomment the ctrl line to filter the data through
48+
# the plugin controller implemented in examples/ctr/lasernoise.cc
49+
# ctrl "lasernoise"
50+
)
4551

52+
# demonstrate a plugin controller, implemented in examples/ctrl/wander.cc
53+
# you probably should comment this out when using simple.cfg with Player
4654
ctrl "wander"
4755

4856
# report error-free position in world coordinates

0 commit comments

Comments
 (0)