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


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 Feb 28 2022 23:48:55