Skip to content

Commit

Permalink
simplified ranger API
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Vaughan authored and Richard Vaughan committed Jul 22, 2010
1 parent 7198607 commit 7aa3b14
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 246 deletions.
15 changes: 7 additions & 8 deletions examples/ctrl/fasr.cc
Expand Up @@ -66,8 +66,8 @@ class Robot
Model* source,
Model* sink )
: pos(pos),
ranger( (ModelRanger*)pos->GetChild( "ranger:0" )),
laser( (ModelRanger*)pos->GetChild( "ranger:1" )),
ranger( (ModelRanger*)pos->GetChild( "ranger:0" )),
fiducial( (ModelFiducial*)pos->GetUnusedModelOfType( "fiducial" )),
//blobfinder( (ModelBlobfinder*)pos->GetUnusedModelOfType( "blobfinder" )),
//gripper( (ModelGripper*)pos->GetUnusedModelOfType( "gripper" )),
Expand Down Expand Up @@ -212,33 +212,32 @@ class Robot
double minright = 1e6;

// Get the data from the first sensor of the laser
const std::vector<ModelRanger::Sensor::Sample>& scan =
laser->GetSamples();
const std::vector<meters_t>& scan = laser->GetRanges();

uint32_t sample_count = scan.size();

for (uint32_t i = 0; i < sample_count; i++)
{
if( verbose ) printf( "%.3f ", scan[i].range );
if( verbose ) printf( "%.3f ", scan[i] );

if( (i > (sample_count/4))
&& (i < (sample_count - (sample_count/4)))
&& scan[i].range < minfrontdistance)
&& scan[i] < minfrontdistance)
{
if( verbose ) puts( " obstruction!" );
obstruction = true;
}

if( scan[i].range < stopdist )
if( scan[i] < stopdist )
{
if( verbose ) puts( " stopping!" );
stop = true;
}

if( i > sample_count/2 )
minleft = std::min( minleft, scan[i].range );
minleft = std::min( minleft, scan[i] );
else
minright = std::min( minright, scan[i].range );
minright = std::min( minright, scan[i] );
}

if( verbose )
Expand Down
15 changes: 7 additions & 8 deletions examples/ctrl/fasr2.cc
Expand Up @@ -563,7 +563,7 @@ class Robot
const std::vector<ModelRanger::Sensor>& sensors = sonar->GetSensors();

for( unsigned int s = BACK_SENSOR_FIRST; s <= BACK_SENSOR_LAST; ++s )
if( sensors[s].samples[0].range < wait_distance)
if( sensors[s].ranges[0] < wait_distance)
{
pos->Say( "Waiting..." );
pos->SetXSpeed( 0.0 );
Expand Down Expand Up @@ -616,34 +616,33 @@ class Robot
// Get the data
//const std::vector<ModelLaser::Sample>& scan = laser->GetSamples();

const std::vector<ModelRanger::Sensor::Sample>& scan =
laser->GetSensors()[0].samples;
const std::vector<meters_t>& scan = laser->GetRanges();

uint32_t sample_count = scan.size();


for (uint32_t i = 0; i < sample_count; i++)
{
if( verbose ) printf( "%.3f ", scan[i].range );
if( verbose ) printf( "%.3f ", scan[i] );

if( (i > (sample_count/4))
&& (i < (sample_count - (sample_count/4)))
&& scan[i].range < minfrontdistance)
&& scan[i] < minfrontdistance)
{
if( verbose ) puts( " obstruction!" );
obstruction = true;
}

if( scan[i].range < stopdist )
if( scan[i] < stopdist )
{
if( verbose ) puts( " stopping!" );
stop = true;
}

if( i > sample_count/2 )
minleft = std::min( minleft, scan[i].range );
minleft = std::min( minleft, scan[i] );
else
minright = std::min( minright, scan[i].range );
minright = std::min( minright, scan[i] );
}

if( verbose )
Expand Down
12 changes: 6 additions & 6 deletions examples/ctrl/wander.cc
Expand Up @@ -54,7 +54,7 @@ extern "C" int Init( Model* mod, CtrlArgs* args )
int LaserUpdate( Model* mod, robot_t* robot )
{
// get the data
const std::vector<ModelRanger::Sensor::Sample>& scan = robot->laser->GetSamples();
const std::vector<meters_t>& scan = robot->laser->GetRanges();
uint32_t sample_count = scan.size();
if( sample_count < 1 )
return 0;
Expand All @@ -70,26 +70,26 @@ int LaserUpdate( Model* mod, robot_t* robot )
for (uint32_t i = 0; i < sample_count; i++)
{

if( verbose ) printf( "%.3f ", scan[i].range );
if( verbose ) printf( "%.3f ", scan[i] );

if( (i > (sample_count/3))
&& (i < (sample_count - (sample_count/3)))
&& scan[i].range < minfrontdistance)
&& scan[i] < minfrontdistance)
{
if( verbose ) puts( " obstruction!" );
obstruction = true;
}

if( scan[i].range < stopdist )
if( scan[i] < stopdist )
{
if( verbose ) puts( " stopping!" );
stop = true;
}

if( i > sample_count/2 )
minleft = std::min( minleft, scan[i].range );
minleft = std::min( minleft, scan[i] );
else
minright = std::min( minright, scan[i].range );
minright = std::min( minright, scan[i] );
}

if( verbose )
Expand Down

0 comments on commit 7aa3b14

Please sign in to comment.