charger.cc
Go to the documentation of this file.
1 
9 #include "stage.hh"
10 #include "worldfile.hh"
11 using namespace Stg;
12 
13 Charger::Charger( World* world )
14  : world( world ), watts( 1000.0 )
15 {
16  //printf( "Charger constructed" );
17 }
18 
19 void Charger::ChargeIfContained( PowerPack* pp, Pose pose )
20 {
21  if( Contains( pose ) )
22  Charge( pp );
23 }
24 
25 bool Charger::Contains( Pose pose )
26 {
27  return( pose.x >= volume.x.min &&
28  pose.x < volume.x.max &&
29  pose.y >= volume.y.min &&
30  pose.y < volume.y.max &&
31  pose.z >= volume.z.min &&
32  pose.z < volume.z.max );
33 }
34 
35 void Charger::Charge( PowerPack* pp )
36 {
37  double given = watts * world->interval_sim * 1e-6;
38 
39  pp->stored += given;
40 
41  // do not exceed capacity
42  pp->stored = MIN( pp->stored, pp->capacity );
43  pp->charging = true;
44  /*
45  printf( "charger %p at [%.2f %.2f] [%.2f %.2f] [%.2f %.2f] gave pack %p %.3f joules\n",
46  this,
47  volume.x.min,
48  volume.x.max,
49  volume.y.min,
50  volume.y.max,
51  volume.z.min,
52  volume.z.max,
53  pp, given );
54 
55  pp->Print( "just charged" );
56  */
57 }
58 
59 void Charger::Visualize()
60 {
61 
62  glPushMatrix();
63  glPolygonMode( GL_FRONT, GL_FILL );
64  glColor4f( 1, 0.5,0,0.4 );
65  glTranslatef( 0,0,volume.z.min);
66  glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
67 
68  glTranslatef( 0,0,volume.z.max );
69  glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
70  glPopMatrix();
71 
72  glPushMatrix();
73  glPolygonMode( GL_FRONT, GL_LINE );
74  glColor4f( 1, 0.5,0,0.8 );
75  glTranslatef( 0,0,volume.z.min);
76  glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
77 
78  glTranslatef( 0,0,volume.z.max );
79  glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
80  glPopMatrix();
81 
82  // ?
83  //glPolygonMode( GL_FRONT, GL_FILL );
84 }
85 
86 void swap( double &a, double &b )
87 {
88  double keep = a;
89  a = b;
90  b = keep;
91 }
92 
93 void Charger::Load( Worldfile* wf, int entity )
94 {
95  if( wf->PropertyExists( entity, "volume" ) )
96  {
97  volume.x.min = wf->ReadTupleLength( entity, "volume", 0, volume.x.min );
98  volume.x.max = wf->ReadTupleLength( entity, "volume", 1, volume.x.max );
99  volume.y.min = wf->ReadTupleLength( entity, "volume", 2, volume.y.min );
100  volume.y.max = wf->ReadTupleLength( entity, "volume", 3, volume.y.max );
101  volume.z.min = wf->ReadTupleLength( entity, "volume", 4, volume.z.min );
102  volume.z.max = wf->ReadTupleLength( entity, "volume", 5, volume.z.max );
103 
104  // force the windings for GL's sake
105  if( volume.x.min > volume.x.max )
106  swap( volume.x.min, volume.x.max );
107 
108  if( volume.y.min > volume.y.max )
109  swap( volume.y.min, volume.y.max );
110 
111  if( volume.z.min > volume.z.max )
112  swap( volume.z.min, volume.z.max );
113 
114  }
115 
116  watts = wf->ReadFloat( entity, "watts", watts );
117 }
joules_t stored
Definition: stage.hh:1667
void swap(double &a, double &b)
Definition: charger.cc:86
WorldGui * world
Definition: canvas.hh:105
World class
Definition: stage.hh:814
The Stage library uses its own namespace.
Definition: canvas.hh:8
meters_t z
location in 3 axes
Definition: stage.hh:251
meters_t y
Definition: stage.hh:251
bool charging
Definition: stage.hh:1673
bool PropertyExists(int section, const char *token)
Definition: worldfile.cc:1324
Worldfile * wf
Definition: canvas.hh:60
double ReadFloat(int entity, const char *name, double value)
Definition: worldfile.cc:1434
joules_t capacity
Definition: stage.hh:1670
meters_t x
Definition: stage.hh:251


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09