FlightGear next
gyro.cxx
Go to the documentation of this file.
1// gyro.cxx - simple implementation of a spinning gyro model.
2
3// Todo: this should be really modelled physically correctly and initialize its own properties etc.
4// this way, instruments using a gyro can just refer to it and read the data from the gyro.
5
6#include "gyro.hxx"
7
9 : _serviceable(true),
10 _power_norm(0.0),
11 _spin_norm(0.0)
12{
13}
14
16{
17}
18
19void Gyro::reinit(void)
20{
21 _power_norm = 0.0;
22 _spin_norm = 0.0;
23 _spin_down = 180.0; // about 3 minutes from full spin
24 _spin_up = 4.0; // up to power-norm; about 4 seconds to full spin
25}
26
27void
28Gyro::update (double delta_time_sec)
29{
30 // spin decays 0.5% every second
31 double spin_decay = (1.0 / _spin_down) * delta_time_sec;
32 _spin_norm -= spin_decay;
33
34 // power can increase spin by 25%
35 // every second, but only up to the
36 // level of power available
37 if (_serviceable) {
38 double step = spin_decay + (1.0 / _spin_up) * _power_norm * delta_time_sec;
39 if ((_spin_norm + step) <= _power_norm)
40 _spin_norm += step;
41 } else {
42 _spin_norm = 0; // stop right away if the gyro breaks
43 }
44
45 // clamp the spin to 0.0:1.0
46 if (_spin_norm < 0.0)
47 _spin_norm = 0.0;
48 else if (_spin_norm > 1.0)
49 _spin_norm = 1.0;
50}
51
52void
53Gyro::set_power_norm (double power_norm)
54{
55 _power_norm = power_norm;
56}
57
58double
60{
61 return _spin_norm;
62}
63
64void
65Gyro::set_spin_norm (double spin_norm)
66{
67 _spin_norm = spin_norm;
68}
69
70bool
72{
73 return _serviceable;
74}
75
76void
77Gyro::set_serviceable (bool serviceable)
78{
79 _serviceable = serviceable;
80}
81
82void Gyro::set_spin_up(double spin_up)
83{
84 _spin_up = spin_up;
85}
86
87void Gyro::set_spin_down(double spin_down)
88{
89 _spin_down = spin_down;
90}
91
92
93// end of gyro.cxx
94
virtual void set_spin_up(double spin_up)
Set the gyro's spin up time in seconds (from 0 to full spin).
Definition gyro.cxx:82
virtual void set_spin_down(double spin_down)
Set the gyro's spin down time in seconds (from full spin to 0).
Definition gyro.cxx:87
virtual void set_spin_norm(double spin_norm)
Set the gyro's current spin.
Definition gyro.cxx:65
virtual void set_power_norm(double power_norm)
Set the power available to the gyro.
Definition gyro.cxx:53
Gyro()
Constructor.
Definition gyro.cxx:8
virtual void update(double delta_time_sec)
Update the gyro.
Definition gyro.cxx:28
virtual bool is_serviceable() const
Test if the gyro is serviceable.
Definition gyro.cxx:71
void reinit(void)
Reset the gyro.
Definition gyro.cxx:19
virtual double get_spin_norm() const
Get the gyro's current spin.
Definition gyro.cxx:59
virtual void set_serviceable(bool serviceable)
Set the gyro's serviceability.
Definition gyro.cxx:77
virtual ~Gyro()
Destructor.
Definition gyro.cxx:15