CARMA C++
Loberotator.h
Go to the documentation of this file.
1 
13 #ifndef CARMA_LOBEROTATOR_H
14 #define CARMA_LOBEROTATOR_H
15 
16 // UNIX includes, usleep...
17 #include <unistd.h>
18 
19 // C++ Standard library includes
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 
25 // Carma includes
26 #include "carma/corba/corba.h"
28 #include "carma/monitor/LoberotatorSubsystem.h"
29 #include "carma/util/QuadraticInterpolatorNormal.h"
31 
34 #include "carma/loberotator/LoberotatorControl_skel.h"
35 
36 #include <log4cpp/CategoryStream.hh>
37 
38 namespace log4cpp {
39  // Forward declaration
40  class Category;
41 } // End namespace log4cpp
42 
43 namespace carma {
44 
45 namespace monitor {
46  // Forward declaration
47  class QuadMod;
48  class Xac;
49 } // End namespace monitor
50 
51 
100 namespace loberotator {
101 
102 // Forward declaration
103 class LoberotatorMaster;
104 
114 class Loberotator :
117 {
118 public:
119 
144  carma::monitor::LoberotatorSubsystem* mon);
145 
149  virtual ~Loberotator();
150 
154  void updatePhaseAndRate();
155 
159  void sendMulDiv();
160 
164  void sendPhaseAndRate();
165 
166 
167  //------------------------------------------------------------
168  // External API
169  //------------------------------------------------------------
170 #if 0
171  void setDelay(const carma::loberotator::LoberotatorControl::Delays& delay )
172  __attribute__((deprecated));
173 
174  void setLOFreq(
175  const carma::loberotator::LoberotatorControl::Frequencies& freq)
176  __attribute__((deprecated));
177 #endif
178 
179  void updateDelayAndFreq(
181 
182  void loadPhaseSwitchColumn( CORBA::Long inputId, CORBA::Short columnId);
183 
184  void assignWalshColumn(
186 
187  void enableDDS(CORBA::Long chan, bool state);
188 
189  void enable90PhaseSwitching(CORBA::Long chan, bool state);
190 
191  void enable180PhaseSwitching(CORBA::Long chan, bool state);
192 
193  void enablePhaseSwitching(CORBA::Long chan, bool state);
194 
195  void enableFringeTracking(CORBA::Long chan, bool state);
196 
197  void enableDDSfringeTracking(CORBA::Long chan, bool state );
198 
199  void resetBoard(CORBA::Long BoardNo);
200 
201  void hardReset();
202 
203  void enableTrace(CORBA::Long chan, bool enable);
204 
205  void enableUpdate(bool enable);
206 
207  //------------------------------------------------------------
208  // Offset (artificial) fringe tracking.
209  //------------------------------------------------------------
210  void setOffsetControl(CORBA::Long chan, bool state);
211 
212  void setOffsetPhase(CORBA::Long chan, double phaseOffset);
213 
214  void setOffsetRate(CORBA::Long chan, double rateOffset);
215 
216  //------------------------------------------------------------
217  // External interface helper methods
218  //------------------------------------------------------------
219  void enableFringeTracking(bool state);
220  void setOffsetControl(bool state);
221  void setOffsetPhase(double phaseOffset);
222  void setOffsetRate(double rateOffset);
223 
224 private:
225  // Copy and assignment not permitted for this class.
226  Loberotator( const Loberotator& );
227  Loberotator& operator=( const Loberotator& );
228  //------------------------------------------------------------
229  // Internal fringe tracking methods
230  //------------------------------------------------------------
231 
232  // Update the delay interpolator for a DDS channel
233  void setDelay(
235 
236  // Send phase and rate to the XAC,
237  // to be clocked in on the next half-second boundary.
238  void setPhaseAndRate(CORBA::Long ddsId,
239  CORBA::ULong phase,
240  CORBA::Long dphase);
241  // Send walsh column to the XAC
242  void sendWalshColumn(unsigned char walshColumn);
243 
244  //------------------------------------------------------------
245  // Utility methods
246  //------------------------------------------------------------
247  // Board index [0-5], derived from the node numbers (1,5,9...)
248  int getBoardIndex();
249  // Get a ref to another loberotator; chanIndex=0 gives nodeID=1
250  Loberotator& lr(int chanIndex);
251  // CORBA range check channelNo input [1-N_CHAN];
252  // throws CORBA UserException if out of range
253  void checkChanRange(int chanNo);
254  // CORBA range check channelNo input [0-N_CHAN], including broadcast chan
255  // throws CORBA UserException if out of range
256  void checkFullChanRange(int chanNo);
257  // Create a message destined for a specific channel
258  carma::canbus::Message createMsgToChan(int chanNo,
259  carma::canbus::msgType msgID);
260  // Puts a bogus guard message into the output queue.
261  void sendGuardMessage();
262  // Get the monitor channel in which to put command values
263  monitor::LoberotatorSubsystem::Channel& getMonCommandChannel();
264  // As above, but input LR channel number
265  monitor::LoberotatorSubsystem::Channel& getMonCommandChannel(int chan);
266 
267  //------------------------------------------------------------
268  // Monitoring methods
269  //------------------------------------------------------------
270  // Methods to process individual CAN messages. These routines
271  // are called by processMsg.
272  void processPhasePacket(std::vector<carma::canbus::byteType> &data, int pkt);
273  void processPacket5(std::vector<carma::canbus::byteType> &data);
274  void processPacket6(std::vector<carma::canbus::byteType> &data);
275  void processPacket7(std::vector<carma::canbus::byteType> &data);
276  void processPacket8(std::vector<carma::canbus::byteType> &data);
277  void processPacket9(std::vector<carma::canbus::byteType> &data);
278  void processPacket10(std::vector<carma::canbus::byteType> &data);
279  void processPacket11(std::vector<carma::canbus::byteType> &data);
280 
281  void processFastMonitorChan1(std::vector<carma::canbus::byteType> &data);
282  void processFastMonitorChan2(std::vector<carma::canbus::byteType> &data);
283  void processFastMonitorChan1Data(
284  std::vector<carma::canbus::byteType> &data );
285  void processFastMonitorChan2Data(
286  std::vector<carma::canbus::byteType> &data );
287 
288  //------------------------------------------------------------
289  // Data members
290  //------------------------------------------------------------
291  // Reference to masterLoberotator
292  LoberotatorMaster& master_;
293  LoberotatorMaster& master();
294 
295  //------------------------------------------------------------
296  // Data members, simulators
297  //------------------------------------------------------------
298  SimData* phaseSim_;
299  SimData& phaseSim();
300  SimData* rateSim_;
301  SimData& rateSim();
302  SimData* tempSim_;
303  SimData& tempSim();
304  SimData* ps5vaSim_;
305  SimData& ps5vaSim();
306  SimData* ps5vdSim_;
307  SimData& ps5vdSim();
308  SimData* psNeg5vSim_;
309  SimData& psNeg5vSim();
310  SimData* ps24vSim_;
311  SimData& ps24vSim();
312  SimIntegerData* psColumnStateSim_;
313  SimIntegerData& psColumnStateSim();
314  SimIntegerData* controlStateSim_;
315  SimIntegerData& controlStateSim();
316  SimIntegerData* ppsStateSim_;
317  SimIntegerData& ppsStateSim();
318  SimIntegerData* hbStateSim_;
319  SimIntegerData& hbStateSim();
320  SimIntegerData* psStateSim_;
321  SimIntegerData& psStateSim();
322  SimIntegerData* dataValidSim_;
323  SimIntegerData& dataValidSim();
324  SimIntegerData* timeOffsetSim_;
325  SimIntegerData& timeOffsetSim();
326 
327  // Data items for calculating and controlling phase and rate
329  double LO1Freq_; // In GHz
330  long multiplier_;
331  long divisor_;
332  long sign_;
333  double phaseOffset_; // Phase in turns
334  double rateOffset_; // Rate in Hz (turns/sec)
335  bool offsetControl_; // Turn on/off
336  bool fringeTracking_; // Turn on/off
337  double delayUpdateTimestamp_; // Time of last update
338  static bool updateEnabled_;
339  unsigned long outputPhase_;
340  long outputRate_;
341  short outputMul_;
342  short outputDiv_;
343 
344  carma::util::PhaseSwitchTable* phaseSwitchTable_;
345 
346  // Reference to the monitor subsystem
347  carma::monitor::LoberotatorSubsystem* mon_;
348  carma::monitor::LoberotatorSubsystem& mon();
349 
350  // Logger
351  log4cpp::Category& logger_;
352  log4cpp::Category& log();
353 
354  // Command log
355  bool cmdLoggingEnabled();
356  // Maybe needs to be DEBUG?
357  static const log4cpp::Priority::PriorityLevel
358  CMD_LOG_PRIORITY = log4cpp::Priority::INFO;
359  log4cpp::CategoryStream cmdlog();
360 
361  // Trace
362  bool traceEnabled_;
363  static const int traceInterval_ = 2;
364 
365  // Override device methods
366  std::map<carma::canbus::msgType, std::string> getHalfSecMonitors() const;
367  std::map<carma::canbus::msgType, std::string> getSlowMonitors() const;
369 
370  static const carma::canbus::apiType API_ID = 113;
371  static carma::canbus::apiType getApiId();
372 
373  // Message processing
374  void processMsg(carma::canbus::msgType mid,
375  std::vector<carma::canbus::byteType> &data, bool sim);
376  carma::canbus::Message simPhasePacket(int chanNo);
377  carma::canbus::Message simPacket5();
378  carma::canbus::Message simPacket6();
379  carma::canbus::Message simPacket7();
380 
381  // Commands
382  static const carma::canbus::msgType NODE_RESET = 0x000;
383  static const carma::canbus::msgType SET_PHASE_AND_RATE = 0x040;
384  static const carma::canbus::msgType SET_MULTIPLIER = 0x041;
385  static const carma::canbus::msgType DISABLE_PHASESWITCH90 = 0x042;
386  static const carma::canbus::msgType DISABLE_PHASESWITCH180 = 0x043;
387  static const carma::canbus::msgType DISABLE_LOBEROTATION = 0x044;
388  static const carma::canbus::msgType BEGIN_LOAD_COLUMN = 0x045;
389  static const carma::canbus::msgType LOAD_COLUMN = 0x046;
390  static const carma::canbus::msgType SELECT_WALSH_COLUMN = 0x047;
391 
392  // Half second packets
393  static const carma::canbus::msgType BLANK_FRAME_PACKET_1 = 0x0E0;
394  static const carma::canbus::msgType BLANK_FRAME_PACKET_2 = 0x0E1;
395  static const carma::canbus::msgType BLANK_FRAME_PACKET_3 = 0x0E2;
396  static const carma::canbus::msgType BLANK_FRAME_PACKET_4 = 0x0E3;
397  static const carma::canbus::msgType BLANK_FRAME_PACKET_5 = 0x0E4;
398  static const carma::canbus::msgType BLANK_FRAME_PACKET_6 = 0x0E5;
399  static const carma::canbus::msgType BLANK_FRAME_PACKET_7 = 0x0E6;
400  static const carma::canbus::msgType BLANK_FRAME_PACKET_8 = 0x0E7;
401  static const carma::canbus::msgType BLANK_FRAME_PACKET_9 = 0x0E8;
402  static const carma::canbus::msgType BLANK_FRAME_PACKET_10 = 0x0E9;
403  static const carma::canbus::msgType BLANK_FRAME_PACKET_11 = 0x0EA;
404 
405 
406  // Fast monitoring packets
407  static const carma::canbus::msgType FAST_CHAN_1 = 0x110;
408  static const carma::canbus::msgType FAST_CHAN_2 = 0x111;
409  static const carma::canbus::msgType FAST_CHAN_1_DATA = 0x112;
410  static const carma::canbus::msgType FAST_CHAN_2_DATA = 0x113;
411 
412 }; // Class Loberotator
413 
414 
415 } // Namespace loberotator
416 } // Namespace carma
417 
418 
419 #endif // CARMA_LOBEROTATOR_H
Simulated data generator class.
Definition: SimData.h:24
Class to encapsulate a CAN message.
Definition: Message.h:21
void sendPhaseAndRate()
Send phase and rates for this channel to the CANnode.
A delay and frequency element structure The frequency items apply to all channels in the packet...
Class to receive phase switching tables which then triggers more processing.
XacDevice canbus::device class implementation.
Definition: XacDevice.h:37
Loberotator(carma::canbus::nodeType node, carma::loberotator::LoberotatorMaster *master, carma::monitor::LoberotatorSubsystem *mon)
Constructor for a loberotator channel.
unsigned short apiType
Carma API id type.
Definition: Types.h:64
Class for interpolating normal (non-angle) ordinates.
void sendMulDiv()
Send multiplier/divisor for this channel to the CANnode.
virtual ~Loberotator()
Destructor.
sequence< WalshAssignment > WalshAssignmentSeq
Sequence of walsh columns.
unsigned short nodeType
Carma Node Type id type.
Definition: Types.h:66
This is the chassis that holds the loberotators.
Carma Loberotator CAN Master class.
carma::canbus::devices::XacDevice class declaration.
Simulated integer data generator class.
Definition: SimData.h:84
Simple linear data simulator.
unsigned short msgType
Carma Message id type.
Definition: Types.h:69
void updatePhaseAndRate()
Compute phase and rates for this channel and leave internally.
Loberotator implementation.
Definition: Loberotator.h:114
A triplet of time tagged delays, associated with a specific channel.
Phaseswitching corba server DO implementation.
The PhaseSwitchTable class provides a generic way of reading, writing and retreiving specific PhaseSw...