CARMA C++
LoberotatorMaster.h
Go to the documentation of this file.
1 
11 #ifndef CARMA_LOBEROTATORMASTER_H
12 #define CARMA_LOBEROTATORMASTER_H
13 
14 // System includes
15 #include <pthread.h>
16 
17 // Carma includes
18 #include "carma/canbus/Master.h"
21 #include "carma/switchyard/Switchyard.h"
22 #include "carma/monitor/LoberotatorSubsystem.h"
23 #include "carma/monitor/SignalPathSubsystem.h"
24 #include "carma/util/Time.h"
25 
26 #include <utility>
27 
28 namespace carma {
29 
30 namespace corba {
31 
32  class Server;
33 
34 }
35 
36 
37 namespace loberotator {
38 
44  public carma::canbus::Master {
45  public:
46 
57  LoberotatorMaster(int holdoff, double autoWriteDelayInS,
58  double syautoWriteDelayInS);
59 
70  LoberotatorMaster( int board, int bus,
71  int holdoff, bool simulate,
72  double autoWriteDelayInS,
73  double syautoWriteDelayInS);
74 
79 
83  carma::switchyard::Switchyard & getLoSwitchyard();
84 
88  carma::switchyard::Switchyard & getLlSwitchyard();
89 
95  bool isDone();
96 
97  protected:
98 
108  void updateStatus();
109 
116  virtual ~LoberotatorMaster();
117 
118  private:
119 
120  // The timer delay after the frame boundary for updating
121  // the phase and rate
122  // There is an inherent statistical delay of about 1.5msec
123  // before the timer is serviced. It also takes on average
124  // 0.7msec to actually do the update. Additionally, the messages take
125  // about 3msec on the wire to go out. So we have a fixed delay of
126  // 1.5 + 0.7 + 1.5 = 4,
127  static const int FIXED_HOLDOFF = 4;
128  int holdoff_;
129 
130  // Copying and assignment are not allowed
132  LoberotatorMaster &operator=(const LoberotatorMaster &);
133 
134  // Helper routines to consolidate initialization among 3 constructors.
135  void initialize(double autoWriteDelayInS, double syautoWriteDelayInS);
136  void addDevices( );
137 
138  // Consolidate removal of devices - used on destruction.
139  void removeDevices();
140 
141  // DEBUG
142  void quit();
143 
144  // Run thread entry point. Entry points are needed in order to assure
145  // that the actual run method is not subject to the c-style linkage
146  // rules (static) that are required of the pthread entry point.
147  static void *runThreadEntry(void *arg);
148 
149  // Redefine run such that it is private. Since the carmaLoberotatorHost app
150  // is a CORBA server, it will block on runOrb - thus we call run in
151  // a separate thread in the LoberotatorMaster constructor to get the
152  // CANbus side of things moving independently.
153  void run();
154 
155  // Keep the run thread id around so that we can properly destroy the
156  // thread upon destruction.
157  pthread_t runThreadId_;
158 
159  // Node 0 'Global control' device objects. (Aren't added to Master
160  // device map via addDevice).
162  carma::util::Time time_;
163  carma::monitor::LoberotatorSubsystem* mon_;
164 
165  carma::monitor::SignalPathSubsystem signalPathMon_;
166  carma::switchyard::Switchyard loSwitchyard_;
167  carma::switchyard::Switchyard llSwitchyard_;
168 
169  // Are we emulating the underlying Janz hardware?
170  const bool emulate_;
171 
172  std::string hostname_;
173 
174  // Static needed to call update in thread
175  static void updateThreadStaticWrapper(LoberotatorMaster& lrm);
176  // Thread scheduled update of phase & rate
177  void updateThread();
178  pthread_t updateThread_;
179  void updatePhaseAndRate() const;
180 
181  // DEBUG
182  pthread_mutex_t doneMutex_;
183  bool done_;
184 
185  }; // End LoberotatorMaster class
186  }; // End loberotator namespace
187 }; // End carma namespace
188 
189 #endif // CARMA_LOBEROTATORMASTER_H
Common time functions.
Loberotator Device class definition for Carma CANbus API 113.
bool isDone()
Query to see if the System::quit() method has been invoked.
Declaration of carma::canbus::Master class.
void updateStatus()
Update the status of the Loberotator CAN Master.
carma::switchyard::Switchyard & getLoSwitchyard()
Retrieve reference to LO Switchyard instance.
carma::switchyard::Switchyard & getLlSwitchyard()
Retrieve reference to LL Switchyard instance.
This is the chassis that holds the loberotators.
Carma Loberotator CAN Master class.
carma::loberotator::Loberotator & getGlobalLoberotator()
Get &#39;global&#39; (node 0 control device) loberotator.
LoberotatorMaster(int holdoff, double autoWriteDelayInS, double syautoWriteDelayInS)
Constructor for emulation mode Runs without accessing any hardware, directing all canbus writes to de...
This class deals primarily with Frames and Times.
Definition: Time.h:74
Carma Canbus Master class.
Definition: Master.h:110
Loberotator implementation.
Definition: Loberotator.h:114
Provides storage for Loberotator objects.
Definition: Chassis.h:29
virtual ~LoberotatorMaster()
Destructor.