Revision: 7558
http://playerstage.svn.sourceforge.net/playerstage/?rev=7558&view=rev
Author: rtv
Date: 2009-03-30 05:55:10 +0000 (Mon, 30 Mar 2009)
Log Message:
-----------
working on power models
Modified Paths:
--------------
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_draw.cc
code/stage/trunk/libstage/model_laser.cc
code/stage/trunk/libstage/powerpack.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/worldgui.cc
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2009-03-29 01:03:23 UTC (rev 7557)
+++ code/stage/trunk/libstage/model.cc 2009-03-30 05:55:10 UTC (rev 7558)
@@ -690,7 +690,7 @@
{
// consume energy stored in the power pack
stg_joules_t consumed = watts * (world->interval_sim * 1e-6);
- pp->Dissipate( consumed, this->pose );
+ pp->Dissipate( consumed, GetGlobalPose() );
}
}
Modified: code/stage/trunk/libstage/model_draw.cc
===================================================================
--- code/stage/trunk/libstage/model_draw.cc 2009-03-29 01:03:23 UTC (rev
7557)
+++ code/stage/trunk/libstage/model_draw.cc 2009-03-30 05:55:10 UTC (rev
7558)
@@ -245,7 +245,7 @@
glPopMatrix();
}
-void Model::AddVisualizer( Visualizer* custom_visual )
+void Model::AddVisualizer( Visualizer* custom_visual, bool on_by_default )
{
if( !custom_visual )
return;
@@ -267,7 +267,7 @@
Option* op = new Option( custom_visual->GetMenuName(),
custom_visual->GetWorldfileName(),
"",
-
true,
+
on_by_default,
world_gui );
canvas->_custom_options[ custom_visual->GetMenuName() ] = op;
RegisterOption( op );
Modified: code/stage/trunk/libstage/model_laser.cc
===================================================================
--- code/stage/trunk/libstage/model_laser.cc 2009-03-29 01:03:23 UTC (rev
7557)
+++ code/stage/trunk/libstage/model_laser.cc 2009-03-30 05:55:10 UTC (rev
7558)
@@ -218,7 +218,7 @@
// set default color
SetColor( stg_lookup_color(DEFAULT_COLOR));
- AddVisualizer( &vis );
+ AddVisualizer( &vis, true );
}
Modified: code/stage/trunk/libstage/powerpack.cc
===================================================================
--- code/stage/trunk/libstage/powerpack.cc 2009-03-29 01:03:23 UTC (rev
7557)
+++ code/stage/trunk/libstage/powerpack.cc 2009-03-30 05:55:10 UTC (rev
7558)
@@ -20,8 +20,7 @@
PowerPack::PowerPack( Model* mod ) :
- dissipation_vec(),
- event_vis( dissipation_vec ),
+ event_vis( 32,32,1.0 ),
mod( mod),
stored( 0.0 ),
capacity( 0.0 ),
@@ -29,7 +28,7 @@
{
// tell the world about this new pp
mod->world->AddPowerPack( this );
- //mod->AddVisualizer( &event_vis );
+ mod->AddVisualizer( &event_vis, false );
};
PowerPack::~PowerPack()
@@ -219,57 +218,81 @@
Subtract( amount );
global_dissipated += amount;
+
+ //stg_watts_t w = j / (interval / 1e6);
}
void PowerPack::Dissipate( stg_joules_t j, const Pose& p )
{
Dissipate( j );
- DissEvent ev( j, p );
- //dissipation_vec.push_back( ev );
+ event_vis.Accumulate( p.x, p.y, j );
}
-
//------------------------------------------------------------------------------
-// Dissipation Event class
+// Dissipation Visualizer class
-PowerPack::DissEvent::DissEvent( stg_joules_t j, const Pose& p )
- : pose(p), joules(j)
-{
- // empty
-}
-void PowerPack::DissEvent::Draw() const
+PowerPack::DissipationVis::DissipationVis( stg_meters_t width,
+
stg_meters_t height,
+
stg_meters_t cellsize )
+ : Visualizer( "energy dissipation", "energy_dissipation" ),
+ columns(width/cellsize),
+ rows(height/cellsize),
+ width(width),
+ height(height),
+ cells( new stg_joules_t[columns*rows] ),
+ peak_value(0),
+ cellsize(cellsize)
+{ /* nothing to do */ }
+
+PowerPack::DissipationVis::~DissipationVis()
{
- float scale = 0.1;
- float delta = 0.05;
-
- glColor4f( 1,0,0, MIN( joules * scale, 1.0 ) );
- glRectf( pose.x-delta, pose.y-delta, pose.x+delta, pose.z+delta );
+ if( cells )
+ delete[] cells;
}
-//------------------------------------------------------------------------------
-// Dissipation Visualizer class
-
-PowerPack::DissipationVis::DissipationVis( std::vector<DissEvent>& events )
- : Visualizer( "energy dissipation", "energy_dissipation" ),
- events( events )
-{ /* nothing to do */ }
-
-
void PowerPack::DissipationVis::Visualize( Model* mod, Camera* cam )
{
// go into world coordinates
glPushMatrix();
-
-
- // draw the dissipation events in world coordinates
- for( std::vector<DissEvent>::const_iterator i = events.begin();
- i != events.end();
- i++ )
- {
- i->Draw();
- }
+ Gl::pose_inverse_shift( mod->GetPose() );
+
+ glTranslatef( -width/2.0, -height/2.0, 0 );
+ glScalef( cellsize, cellsize, 1 );
+
+ for( unsigned int y=0; y<rows; y++ )
+ for( unsigned int x=0; x<columns; x++ )
+ {
+ stg_joules_t j = cells[ y*columns + x ];
+ if( j > 0 )
+ {
+ glColor4f( 1.0, 0, 0, j/peak_value );
+ glRectf( x,y,x+1,y+1 );
+ }
+ }
+
glPopMatrix();
}
+
+
+
+void PowerPack::DissipationVis::Accumulate( stg_meters_t x,
+
stg_meters_t y,
+
stg_joules_t amount )
+{
+ int ix = (x+width/2.0)/cellsize;
+ int iy = (y+height/2.0)/cellsize;
+
+ assert( ix >= 0 );
+ assert( ix < (int)columns );
+ assert( iy >= 0 );
+ assert( iy < (int)rows );
+
+ stg_joules_t* j = cells + (iy*columns + ix );
+
+ (*j) += amount;
+ if( (*j) > peak_value )
+ peak_value = (*j);
+}
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-03-29 01:03:23 UTC (rev 7557)
+++ code/stage/trunk/libstage/stage.hh 2009-03-30 05:55:10 UTC (rev 7558)
@@ -856,13 +856,13 @@
stg_usec_t quit_time;
stg_usec_t real_time_now; ///< The current real time in microseconds
stg_usec_t real_time_start; ///< the real time at which this world was
created
- GMutex* thread_mutex;
- GThreadPool *threadpool;
+ GMutex* thread_mutex; ///< protect the worker thread management stuff
+ GThreadPool *threadpool; ///<worker threads for updating some sensor
models in parallel
int total_subs; ///< the total number of subscriptions to all models
unsigned int update_jobs_pending;
GList* velocity_list; ///< Models with non-zero velocity and should have
their poses updated
- unsigned int worker_threads;
- GCond* worker_threads_done;
+ unsigned int worker_threads; ///< the number of worker threads to use
+ GCond* worker_threads_done; ///< signalled when there are no more updates
for the worker threads to do
protected:
@@ -872,7 +872,7 @@
GHashTable* option_table; ///< GUI options (toggles) registered by
models
GList* powerpack_list; ///< List of all the powerpacks attached to
models in the world
GList* ray_list;///< List of rays traced for debug visualization
- stg_usec_t sim_time; ///< the current sim time in this world in ms
+ stg_usec_t sim_time; ///< the current sim time in this world in
microseconds
GHashTable* superregions;
SuperRegion* sr_cached; ///< The last superregion looked up by this world
// GList* update_list; ///< Models that have a subscriber or controller,
and need to be updated
@@ -1426,38 +1426,29 @@
/** energy data packet */
class PowerPack
{
- friend class World;
+ //friend class World;
friend class WorldGui;
- public:
- class DissEvent
- {
- public:
- Pose pose;
- stg_joules_t joules;
-
- DissEvent( stg_joules_t j, const Pose& p );
- ~DissEvent() { /* empty */ };
-
- void Draw() const;
- };
-
-
-
protected:
- std::vector<DissEvent> dissipation_vec;
-
class DissipationVis : public Visualizer
{
private:
- std::vector<DissEvent>& events;
-
+ unsigned int columns, rows;
+ stg_meters_t width, height;
+ stg_joules_t* cells;
+ double peak_value;
+ double cellsize;
+
public:
- DissipationVis( std::vector<DissEvent>& events );
- virtual ~DissipationVis(){ /* empty */ }
-
+ DissipationVis( stg_meters_t width,
+ stg_meters_t height,
+ stg_meters_t cellsize
);
+
+ virtual ~DissipationVis();
virtual void Visualize( Model* mod, Camera* cam );
+
+ void Accumulate( stg_meters_t x, stg_meters_t y, stg_joules_t
amount );
};
DissipationVis event_vis;
@@ -1876,7 +1867,7 @@
void Say( const char* str );
/** Attach a user supplied visualization to a model. */
- void AddVisualizer( Visualizer* custom_visual );
+ void AddVisualizer( Visualizer* custom_visual, bool on_by_default );
/** remove user supplied visualization to a model - supply the same
ptr passed to AddCustomVisualizer */
void RemoveVisualizer( Visualizer* custom_visual );
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2009-03-29 01:03:23 UTC (rev
7557)
+++ code/stage/trunk/libstage/worldgui.cc 2009-03-30 05:55:10 UTC (rev
7558)
@@ -420,13 +420,12 @@
status_stream << str;
- snprintf( str, 255, "<stored: %.0f/%.0fKJ input: %.0fKJ dissipated:
%.0fKJ power: %.2f(%.2f)W>",
+ snprintf( str, 255, "<stored: %.0f/%.0fKJ input: %.0fKJ dissipated:
%.0fKJ power: %.2fKW>",
PowerPack::global_stored / 1e3,
PowerPack::global_capacity /1e3,
PowerPack::global_input / 1e3,
PowerPack::global_dissipated / 1e3,
- PowerPack::global_power,
- PowerPack::global_power_smoothed );
+ (PowerPack::global_dissipated / (sim_time /
1e6)) / 1e3 );
status_stream << str;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit