Revision: 7557
http://playerstage.svn.sourceforge.net/playerstage/?rev=7557&view=rev
Author: rtv
Date: 2009-03-29 01:03:23 +0000 (Sun, 29 Mar 2009)
Log Message:
-----------
working on energy monitoring
Modified Paths:
--------------
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_draw.cc
code/stage/trunk/libstage/model_load.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 00:31:56 UTC (rev 7556)
+++ code/stage/trunk/libstage/model.cc 2009-03-29 01:03:23 UTC (rev 7557)
@@ -690,7 +690,7 @@
{
// consume energy stored in the power pack
stg_joules_t consumed = watts * (world->interval_sim * 1e-6);
- pp->Subtract( consumed );
+ pp->Dissipate( consumed, this->pose );
}
}
@@ -776,7 +776,7 @@
// detach charger from all the packs charged last time
for( GList* it = pps_charging; it; it = it->next )
- ((PowerPack*)it->data)->charging = false;
+ ((PowerPack*)it->data)->ChargeStop();
g_list_free( pps_charging );
pps_charging = NULL;
@@ -798,10 +798,12 @@
//printf ( "moving %.2f joules from %s to %s\n",
// amount, token, toucher->token );
-
+
+ // set his charging flag
+ hispp->ChargeStart();
+
// move some joules from me to him
mypp->TransferTo( hispp, amount );
- hispp->charging = true;
// remember who we are charging so we can detatch next
time
pps_charging = g_list_prepend( pps_charging, hispp );
Modified: code/stage/trunk/libstage/model_draw.cc
===================================================================
--- code/stage/trunk/libstage/model_draw.cc 2009-03-29 00:31:56 UTC (rev
7556)
+++ code/stage/trunk/libstage/model_draw.cc 2009-03-29 01:03:23 UTC (rev
7557)
@@ -312,8 +312,7 @@
float robotAngle = -rtod(gpz.a);
glPushMatrix();
-
-
+
// move above the robot
glTranslatef( 0, 0, 0.5 );
Modified: code/stage/trunk/libstage/model_load.cc
===================================================================
--- code/stage/trunk/libstage/model_load.cc 2009-03-29 00:31:56 UTC (rev
7556)
+++ code/stage/trunk/libstage/model_load.cc 2009-03-29 01:03:23 UTC (rev
7557)
@@ -20,40 +20,30 @@
assert( wf_entity );
PRINT_DEBUG1( "Model \"%s\" loading...", token );
-
if( wf->PropertyExists( wf_entity, "joules" ) )
{
if( !power_pack )
power_pack = new PowerPack( this );
- power_pack->stored =
- wf->ReadFloat( wf_entity, "joules", power_pack->stored );
-
+ stg_joules_t j = wf->ReadFloat( wf_entity, "joules",
+
power_pack->GetStored() ) ;
+
/* assume that the store is full, so the capacity is the same as
the charge */
- power_pack->capacity = power_pack->stored;
+ power_pack->SetStored( j );
+ power_pack->SetCapacity( j );
}
-
+
if( wf->PropertyExists( wf_entity, "joules_capacity" ) )
{
if( !power_pack )
power_pack = new PowerPack( this );
- power_pack->capacity =
- wf->ReadFloat( wf_entity, "joules_capacity",
power_pack->capacity );
+ power_pack->SetCapacity( wf->ReadFloat( wf_entity,
"joules_capacity",
+
power_pack->GetCapacity() ) );
}
-
- /** if the capacity has been specified, limit the store to the capacity */
- if( power_pack && (power_pack->stored > power_pack->capacity) )
- {
- power_pack->stored = power_pack->capacity;
- PRINT_WARN3( "model %s energy storage exceeds capacity (%.2f /
%.2f joules). Limited stored energy to max capactity.",
- token,
- power_pack->stored,
- power_pack->capacity );
- }
-
+
// use my own pack or an ancestor's for the other energy properties
PowerPack* pp = FindPowerPack();
Modified: code/stage/trunk/libstage/powerpack.cc
===================================================================
--- code/stage/trunk/libstage/powerpack.cc 2009-03-29 00:31:56 UTC (rev
7556)
+++ code/stage/trunk/libstage/powerpack.cc 2009-03-29 01:03:23 UTC (rev
7557)
@@ -9,27 +9,43 @@
#include "texture_manager.hh"
using namespace Stg;
+
+stg_joules_t PowerPack::global_stored = 0.0;
+stg_joules_t PowerPack::global_input = 0.0;
+stg_joules_t PowerPack::global_capacity = 0.0;
+stg_joules_t PowerPack::global_dissipated = 0.0;
+stg_watts_t PowerPack::global_power = 0.0;
+stg_watts_t PowerPack::global_power_smoothed = 0.0;
+double PowerPack::global_smoothing_constant = 0.05;
+
+
PowerPack::PowerPack( Model* mod ) :
- mod( mod), stored( 0.0 ), capacity( 0.0 ), charging( false )
+ dissipation_vec(),
+ event_vis( dissipation_vec ),
+ mod( mod),
+ stored( 0.0 ),
+ capacity( 0.0 ),
+ charging( false )
{
// tell the world about this new pp
- mod->world->AddPowerPack( this );
+ mod->world->AddPowerPack( this );
+ //mod->AddVisualizer( &event_vis );
};
PowerPack::~PowerPack()
{
- // tell the world about this new pp
mod->world->RemovePowerPack( this );
+ mod->RemoveVisualizer( &event_vis );
}
-void PowerPack::Print( char* prefix )
+void PowerPack::Print( char* prefix ) const
{
printf( "%s stored %.2f/%.2f joules\n", prefix, stored, capacity );
}
/** OpenGL visualization of the powerpack state */
-void PowerPack::Visualize( Camera* cam )
+void PowerPack::Visualize( Camera* cam ) const
{
const double height = 0.5;
const double width = 0.2;
@@ -107,6 +123,7 @@
glLineWidth( 1.0 );
}
+
// draw the percentage
//gl_draw_string( -0.2, 0, 0, buf );
@@ -115,20 +132,31 @@
}
-stg_joules_t PowerPack::RemainingCapacity()
+stg_joules_t PowerPack::RemainingCapacity() const
{
return( capacity - stored );
}
void PowerPack::Add( stg_joules_t j )
{
- stored += MIN( RemainingCapacity(), j );
+ stg_joules_t amount = MIN( RemainingCapacity(), j );
+ stored += amount;
+ global_stored += amount;
+
+ if( amount > 0 ) charging = true;
}
void PowerPack::Subtract( stg_joules_t j )
{
- if( stored >= 0.0 )
- stored -= MIN( stored, j );
+ if( stored < 0 ) // infinte supply!
+ {
+ global_input += j; // record energy entering the system
+ return;
+ }
+ stg_joules_t amount = MIN( stored, j );
+
+ stored -= amount;
+ global_stored -= amount;
}
void PowerPack::TransferTo( PowerPack* dest, stg_joules_t amount )
@@ -152,3 +180,96 @@
mod->NeedRedraw();
}
+
+
+void PowerPack::SetCapacity( stg_joules_t cap )
+{
+ global_capacity -= capacity;
+ capacity = cap;
+ global_capacity += capacity;
+
+ if( stored > cap )
+ {
+ global_stored -= stored;
+ stored = cap;
+ global_stored += stored;
+ }
+}
+
+stg_joules_t PowerPack::GetCapacity() const
+{
+ return capacity;
+}
+
+stg_joules_t PowerPack::GetStored() const
+{
+ return stored;
+}
+
+void PowerPack::SetStored( stg_joules_t j )
+{
+ global_stored -= stored;
+ stored = j;
+ global_stored += stored;
+}
+
+void PowerPack::Dissipate( stg_joules_t j )
+{
+ stg_joules_t amount = MIN( stored, j );
+
+ Subtract( amount );
+ global_dissipated += amount;
+}
+
+void PowerPack::Dissipate( stg_joules_t j, const Pose& p )
+{
+ Dissipate( j );
+ DissEvent ev( j, p );
+ //dissipation_vec.push_back( ev );
+}
+
+
+//------------------------------------------------------------------------------
+// Dissipation Event class
+
+PowerPack::DissEvent::DissEvent( stg_joules_t j, const Pose& p )
+ : pose(p), joules(j)
+{
+ // empty
+}
+
+void PowerPack::DissEvent::Draw() const
+{
+ 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 );
+}
+
+//------------------------------------------------------------------------------
+// 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();
+ }
+
+ glPopMatrix();
+}
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-03-29 00:31:56 UTC (rev 7556)
+++ code/stage/trunk/libstage/stage.hh 2009-03-29 01:03:23 UTC (rev 7557)
@@ -625,6 +625,26 @@
Flag( stg_color_t color, double size );
Flag* Nibble( double portion );
};
+
+ /** Abstract class for adding visualizations to models. DataVisualize must
be overloaded, and is then called in the models local coord system */
+ class Visualizer {
+ private:
+ const std::string menu_name;
+ const std::string worldfile_name;
+
+ public:
+ Visualizer( const std::string& menu_name,
+ const std::string& worldfile_name )
+ : menu_name( menu_name ),
+ worldfile_name( worldfile_name )
+ { }
+
+ virtual ~Visualizer( void ) { }
+ virtual void Visualize( Model* mod, Camera* cam ) = 0;
+
+ const std::string& GetMenuName() { return menu_name; }
+ const std::string& GetWorldfileName() { return worldfile_name; }
+ };
typedef int(*stg_model_callback_t)(Model* mod, void* user );
@@ -1403,35 +1423,79 @@
virtual void RemoveChild( Model* mod );
};
-
/** energy data packet */
class PowerPack
{
+ friend class World;
+ friend class WorldGui;
+
public:
- PowerPack( Model* mod );
- ~PowerPack();
+ 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;
+
+ public:
+ DissipationVis( std::vector<DissEvent>& events );
+ virtual ~DissipationVis(){ /* empty */ }
+
+ virtual void Visualize( Model* mod, Camera* cam );
+ };
+
+ DissipationVis event_vis;
+
/** The model that owns this object */
Model* mod;
/** Energy stored */
stg_joules_t stored;
-
+
/** Energy capacity */
stg_joules_t capacity;
-
+
/** TRUE iff the device is receiving energy */
bool charging;
+
+ static stg_joules_t global_stored;
+ static stg_joules_t global_capacity;
+ static stg_joules_t global_dissipated;
+ static stg_joules_t global_input;
+ static stg_watts_t global_power;
+ static stg_watts_t global_power_smoothed;
+ static double global_smoothing_constant;
+
+ public:
+ PowerPack( Model* mod );
+ ~PowerPack();
+
/** OpenGL visualization of the powerpack state */
- void Visualize( Camera* cam );
+ void Visualize( Camera* cam ) const;
/** Print human-readable status on stdout, prefixed with the
argument string */
- void Print( char* prefix );
+ void Print( char* prefix ) const;
/** Returns the energy capacity minus the current amount stored */
- stg_joules_t RemainingCapacity();
+ stg_joules_t RemainingCapacity() const;
/** Add to the energy store */
void Add( stg_joules_t j );
@@ -1442,11 +1506,28 @@
/** Transfer some stored energy to another power pack */
void TransferTo( PowerPack* dest, stg_joules_t amount );
- double ProportionRemaining()
+ double ProportionRemaining() const
{ return( stored / capacity ); }
- void Print( const char* prefix )
+ void Print( const char* prefix ) const
{ printf( "%s PowerPack %.2f/%.2f J\n", prefix, stored, capacity ); }
+
+ stg_joules_t GetStored() const;
+ stg_joules_t GetCapacity() const;
+ void SetCapacity( stg_joules_t j );
+ void SetStored( stg_joules_t j );
+
+ /** Returns true iff the device received energy at the last timestep */
+ bool GetCharging() const { return charging; }
+
+ void ChargeStart(){ charging = true; }
+ void ChargeStop(){ charging = false; }
+
+ /** Lose energy as work or heat */
+ void Dissipate( stg_joules_t j );
+
+ /** Lose energy as work or heat, and record the event */
+ void Dissipate( stg_joules_t j, const Pose& p );
};
class Visibility
@@ -1464,25 +1545,6 @@
void Load( Worldfile* wf, int wf_entity );
};
- /** Abstract class for adding visualizations to models. DataVisualize must
be overloaded, and is then called in the models local coord system */
- class Visualizer {
- private:
- const std::string menu_name;
- const std::string worldfile_name;
-
- public:
- Visualizer( const std::string& menu_name,
- const std::string& worldfile_name )
- : menu_name( menu_name ),
- worldfile_name( worldfile_name )
- { }
-
- virtual ~Visualizer( void ) { }
- virtual void Visualize( Model* mod, Camera* cam ) = 0;
-
- const std::string& GetMenuName() { return menu_name; }
- const std::string& GetWorldfileName() { return worldfile_name; }
- };
/* Hooks for attaching special callback functions (not used as
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2009-03-29 00:31:56 UTC (rev
7556)
+++ code/stage/trunk/libstage/worldgui.cc 2009-03-29 01:03:23 UTC (rev
7557)
@@ -390,9 +390,9 @@
std::string WorldGui::ClockString()
{
const uint32_t usec_per_hour = 3600000000U;
- const uint32_t usec_per_minute = 60000000;
- const uint32_t usec_per_second = 1000000;
- const uint32_t usec_per_msec = 1000;
+ const uint32_t usec_per_minute = 60000000U;
+ const uint32_t usec_per_second = 1000000U;
+ const uint32_t usec_per_msec = 1000U;
uint32_t hours = sim_time / usec_per_hour;
uint32_t minutes = (sim_time % usec_per_hour) / usec_per_minute;
@@ -415,11 +415,21 @@
status_stream << std::setw( 2 ) << minutes << "m"
<< std::setw( 2 ) << seconds << "." << std::setprecision( 3 ) <<
std::setw( 3 ) << msec << "s ";
- char str[ 80 ];
- snprintf( str, 80, "[%.2f]", localratio );
+ char str[ 256 ];
+ snprintf( str, 255, "[%.2f]", localratio );
status_stream << str;
+
+
+ snprintf( str, 255, "<stored: %.0f/%.0fKJ input: %.0fKJ dissipated:
%.0fKJ power: %.2f(%.2f)W>",
+ PowerPack::global_stored / 1e3,
+ PowerPack::global_capacity /1e3,
+ PowerPack::global_input / 1e3,
+ PowerPack::global_dissipated / 1e3,
+ PowerPack::global_power,
+ PowerPack::global_power_smoothed );
+
+ status_stream << str;
-
if( paused == true )
status_stream << " [ PAUSED ]";
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