Skip to content
Browse files

fixed bug that prevented color_rgba entries being read correctly, tid…

…ied up Map/UnMap code
  • Loading branch information...
1 parent 1e01c9d commit 39fdb26bddd3d623b769b31916c29d2d1cfb28ed @rtv committed Apr 22, 2012
View
6 examples/ctrl/fasr.cc
@@ -59,6 +59,8 @@ class Robot
nav_mode_t mode;
bool at_dest;
+ unsigned int charger_detection_accum;
+
public:
Robot( ModelPosition* pos,
Model* source,
@@ -80,7 +82,8 @@ class Robot
charger_range(0),
charger_heading(0),
mode(MODE_WORK),
- at_dest( false )
+ at_dest( false ),
+ charger_detection_accum(0)
{
// need at least these models to get any work done
// (pos must be good, as we used it in the initialization list)
@@ -420,7 +423,6 @@ class Robot
}
-
static int FiducialUpdate( ModelFiducial* mod, Robot* robot )
{
robot->charger_ahoy = false;
View
60 libstage/blockgroup.cc
@@ -288,7 +288,7 @@ void BlockGroup::CallDisplayList()
void BlockGroup::LoadBlock( Worldfile* wf, int entity )
{
AppendBlock( Block( this, wf, entity ));
-
+ //CalcSize(); // adjust the blocks so they fit in our bounding box
}
void BlockGroup::LoadBitmap( const std::string& bitmapfile, Worldfile* wf )
@@ -305,43 +305,43 @@ void BlockGroup::LoadBitmap( const std::string& bitmapfile, Worldfile* wf )
full = std::string(dirname(workaround_const)) + "/" + bitmapfile;
free( workaround_const );
}
-
+
char buf[512];
snprintf( buf, 512, "[Image \"%s\"", bitmapfile.c_str() );
- fputs( buf, stdout );
- fflush( stdout );
-
- PRINT_DEBUG1( "attempting to load image %s", full );
-
- Color col( 1.0, 0.0, 1.0, 1.0 );
-
- std::vector<std::vector<point_t> > polys;
+ fputs( buf, stdout );
+ fflush( stdout );
+
+ PRINT_DEBUG1( "attempting to load image %s", full );
- if( polys_from_image_file( full,
- polys ) )
+ Color col( 1.0, 0.0, 1.0, 1.0 );
+
+ std::vector<std::vector<point_t> > polys;
+
+ if( polys_from_image_file( full,
+ polys ) )
{
PRINT_ERR1( "failed to load polys from image file \"%s\"",
- full.c_str() );
+ full.c_str() );
return;
}
-
- FOR_EACH( it, polys )
+
+ FOR_EACH( it, polys )
AppendBlock( Block( this,
- *it,
- Bounds(0,1) ));
-
- CalcSize();
-
- fputs( "]", stdout );
- }
+ *it,
+ Bounds(0,1) ));
+
+ CalcSize();
+
+ fputs( "]", stdout );
+}
- void BlockGroup::Rasterize( uint8_t* data,
- unsigned int width,
- unsigned int height,
- meters_t cellwidth,
- meters_t cellheight )
- {
- FOR_EACH( it, blocks )
+void BlockGroup::Rasterize( uint8_t* data,
+ unsigned int width,
+ unsigned int height,
+ meters_t cellwidth,
+ meters_t cellheight )
+{
+ FOR_EACH( it, blocks )
it->Rasterize( data, width, height, cellwidth, cellheight );
- }
+}
View
3 libstage/color.cc
@@ -107,6 +107,7 @@ const Color& Color::Load( Worldfile* wf, const int section )
if( wf->PropertyExists( section, "color" ))
{
const std::string& colorstr = wf->ReadString( section, "color", "" );
+
if( colorstr != "" )
{
if( colorstr == "random" )
@@ -128,7 +129,7 @@ const Color& Color::Load( Worldfile* wf, const int section )
}
else
wf->ReadTuple( section, "color_rgba", 0, 4, "ffff", &r, &g, &b, &a );
-
+
return *this;
}
View
21 libstage/model.cc
@@ -419,8 +419,7 @@ Model::Flag* Model::PopFlag()
void Model::ClearBlocks()
{
- blockgroup.UnMap(0);
- blockgroup.UnMap(1);
+ UnMap();
blockgroup.Clear();
//no need to Map() - we have no blocks
NeedRedraw();
@@ -885,23 +884,15 @@ kg_t Model::GetMassOfChildren() const
return( GetTotalMass() - mass);
}
+// render all blocks in the group at my global pose and size
void Model::Map( unsigned int layer )
{
- if( ! mapped )
- {
- // render all blocks in the group at my global pose and size
- blockgroup.Map( layer );
- mapped = true;
- }
+ blockgroup.Map( layer );
}
void Model::UnMap( unsigned int layer )
{
- if( mapped )
- {
- blockgroup.UnMap(layer);
- mapped = false;
- }
+ blockgroup.UnMap(layer);
}
void Model::BecomeParentOf( Model* child )
@@ -1560,9 +1551,11 @@ void Model::Load()
// we may well have changed blocks or geometry
blockgroup.CalcSize();
+ // remove and re-add to both layers
UnMapWithChildren(0);
- UnMapWithChildren(1);
MapWithChildren(0);
+
+ UnMapWithChildren(1);
MapWithChildren(1);
if( this->debug )
View
48 libstage/model_ranger.cc
@@ -128,35 +128,25 @@ void ModelRanger::Shutdown( void )
Model::Shutdown();
}
+
void ModelRanger::LoadSensor( Worldfile* wf, int entity )
{
- //static int c=0;
- // printf( "ranger %s loading sensor %d\n", token.c_str(), c++ );
Sensor s;
s.Load( wf, entity );
- sensors.push_back(s);
+ sensors.push_back(s);
}
void ModelRanger::Sensor::Load( Worldfile* wf, int entity )
{
- //static int c=0;
- // printf( "ranger %s loading sensor %d\n", token.c_str(), c++ );
-
pose.Load( wf, entity, "pose" );
size.Load( wf, entity, "size" );
range.Load( wf, entity, "range" );
- col.Load( wf, entity );
fov = wf->ReadAngle( entity, "fov", fov );
sample_count = wf->ReadInt( entity, "samples", sample_count );
- //ranges.resize(sample_count);
- //intensities.resize(sample_count);
+ color.Load( wf, entity );
}
-void ModelRanger::Load( void )
-{
- Model::Load();
-}
static bool ranger_match( Model* hit,
Model* finder,
@@ -213,16 +203,16 @@ void ModelRanger::Sensor::Update( ModelRanger* mod )
intensities[t] = res.mod ? res.mod->vis.ranger_return : 0.0;
bearings[t] = start_angle + ((double)t) * sample_incr;
- // point the ray to the next angle
+ // point the ray to the next angle:
ray.origin.a += sample_incr;
}
}
std::string ModelRanger::Sensor::String() const
{
char buf[256];
- snprintf( buf, 256, "[ samples %u, range [%.2f %.2f] ]",
- sample_count, range.min, range.max );
+ snprintf( buf, 256, "[ samples %u, range [%.2f %.2f] fov %.2f color [%.2f %.2f %.2f %.2f]",
+ sample_count, range.min, range.max, fov, color.r, color.g, color.b, color.a );
return( std::string( buf ) );
}
@@ -238,7 +228,7 @@ void ModelRanger::Sensor::Visualize( ModelRanger::Vis* vis, ModelRanger* rgr ) c
pts[0] = 0.0;
pts[1] = 0.0;
-
+
glDepthMask( GL_FALSE );
glPointSize( 2 );
@@ -248,16 +238,21 @@ void ModelRanger::Sensor::Visualize( ModelRanger::Vis* vis, ModelRanger* rgr ) c
if( vis->showTransducers )
{
- // draw the sensor body as a rectangle
- rgr->PushColor( col );
+ // draw the sensor body as a rectangle in a darker version of the body color
+ // Color col( rgr->color );
+ // col.r /= 3.0;
+ // col.g /= 3.0;
+ // col.b /= 3.0;
+ rgr->PushColor( color );
+
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glRectf( -size.x/2.0, -size.y/2.0, size.x/2.0, size.y/2.0 );
rgr->PopColor();
}
- Color c( col );
- c.a = 0.15; // transparent version of sensor color
- rgr->PushColor( c );
+ //Color c( color );
+ //c.a = 0.15; // transparent version of sensor color
+ rgr->PushColor( color );
glPolygonMode( GL_FRONT, GL_FILL );
if( ranges.size() ) // if we have some data
@@ -309,11 +304,12 @@ void ModelRanger::Sensor::Visualize( ModelRanger::Vis* vis, ModelRanger* rgr ) c
// }
// draw the beam strike points
- c.a = 0.8;
- rgr->PushColor( c );
+ //c.a = 0.8;
+ rgr->PushColor( Color::blue );
glDrawArrays( GL_POINTS, 0, sample_count+1 );
rgr->PopColor();
}
+
if( vis->showFov )
{
@@ -325,6 +321,8 @@ void ModelRanger::Sensor::Visualize( ModelRanger::Vis* vis, ModelRanger* rgr ) c
}
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+
+ Color c = color;
c.a = 0.5;
rgr->PushColor( c );
glDrawArrays( GL_POLYGON, 0, sample_count+1 );
@@ -333,6 +331,8 @@ void ModelRanger::Sensor::Visualize( ModelRanger::Vis* vis, ModelRanger* rgr ) c
if( vis->showBeams )
{
+ Color c = color;
+
// darker version of the same color
c.r /= 2.0;
c.g /= 2.0;
View
7 libstage/stage.hh
@@ -197,7 +197,7 @@ namespace Stg
class Color
{
public:
- float r,g,b,a;
+ double r,g,b,a;
Color( double r, double g, double b, double a=1.0 );
@@ -2732,7 +2732,6 @@ namespace Stg
ModelRanger( World* world, Model* parent, const std::string& type );
virtual ~ModelRanger();
- virtual void Load();
virtual void Print( char* prefix ) const;
class Vis : public Visualizer
@@ -2757,7 +2756,7 @@ namespace Stg
Bounds range;
radians_t fov;
unsigned int sample_count;
- Color col;
+ Color color;
std::vector<meters_t> ranges;
std::vector<double> intensities;
@@ -2768,7 +2767,7 @@ namespace Stg
range( 0.0, 5.0 ),
fov( 0.1 ),
sample_count(1),
- col( 0,1,0,0.3 ),
+ color( Color(0,0,1,0.15)),
ranges(),
intensities(),
bearings()
View
12 libstage/world.cc
@@ -473,14 +473,16 @@ void World::Load( const std::string& worldfile_path )
// call all controller init functions
FOR_EACH( it, models )
{
- // all this is a hack and shouldn't be necessary
(*it)->blockgroup.CalcSize();
- (*it)->UnMap(updates%2);
- (*it)->Map(updates%2);
+ (*it)->UnMap(); // clears both layers
+ (*it)->Map(); // maps both layers
+
// to here
-
- (*it)->InitControllers();
}
+
+ // the world is all done - run any init code for user's controllers
+ FOR_EACH( it, models )
+ (*it)->InitControllers();
putchar( '\n' );
}
View
5 libstage/worldfile.cc
@@ -1528,9 +1528,9 @@ int Worldfile::ReadTuple( const int entity, const char *name,
va_start( args, format );
for( unsigned int i=0; i<count; i++ )
- {
+ {
const char* val = GetPropertyValue(property, first+i);
-
+
switch( format[i] )
{
case 'i': // signed integer
@@ -1638,4 +1638,3 @@ void Worldfile::WriteTuple( const int entity, const char *name,
va_end( args );
}
-
View
13 worlds/fasr.world
@@ -8,7 +8,8 @@ include "map.inc"
include "sick.inc"
speedup -1
-paused 0
+paused 1
+
# time at which to pause (in GUI mode) or quit (in headless mode) the simulation
#quit_time 3600 # 1 hour of simulated time
@@ -107,8 +108,14 @@ charge_station( pose [ 6.427 -0.964 0 74.484 ] )
define autorob pioneer2dx
(
- sickbase( sensor( samples 32 range [0 3] fov 180 color_rgba [ 0 0 1 0.15 ] )
- ranger_return 2.000 watts 30 )
+ sickbase( sensor( samples 32
+ range [0 3]
+ fov 180
+ color_rgba [0 0 1 0.15] )
+# color "yellow" )
+
+ ranger_return 2.000 watts 30
+)
ctrl "fasr"
# kjoules 400
View
8 worlds/pioneer.inc
@@ -12,12 +12,10 @@ define p2dxsonar sensor
size [0.01 0.05 0.01 ]
# define the range bounds [min max]
range [0 5.0]
- # define the angular field of view in degrees
- fov 15
- # define the number of samples spread over the fov
+ # define the angular field of view in degrees
+ fov 15
+ # define the number of samples spread over the fov
samples 1
- # define the color that ranges are drawn in the gui
- color_rgba [ 0 1 0 0.2 ]
)
define p2dx_sonar ranger
View
4 worlds/sick.inc
@@ -3,11 +3,11 @@ define sicksensor sensor
(
# factory settings for LMS200
range [ 0.0 8.0 ]
- pose [ 0 0 0.1 0 ]
+ pose [ 0 0 0.1 0 ]
fov 180
samples 180
#samples 90 # still useful but much faster to compute
- color_rgba [ 0 0 1 0.15 ]
+ color_rgba [0 0 1 0.15]
)
define sickcommon ranger

0 comments on commit 39fdb26

Please sign in to comment.
Something went wrong with that request. Please try again.