My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ServoCommsSa.h
Go to the documentation of this file.
1 #ifndef SERVOCOMMSSA_H
2 #define SERVOCOMMSSA_H
3 
12 // Required C header files from the array control code
13 
14 #include "gcp/control/code/unix/libunix_src/common/regmap.h" // RegMapBlock
15 
16 #include "gcp/antenna/control/specific/AxisPositions.h"
17 #include "gcp/antenna/control/specific/Board.h"
18 #include "gcp/antenna/control/specific/Model.h"
19 #include "gcp/antenna/control/specific/ServoCommandSa.h"
20 #include "gcp/antenna/control/specific/PmacTarget.h"
21 
22 #include "gcp/util/common/Angle.h"
23 #include "gcp/util/common/FdSet.h"
24 
25 #include <termios.h>
26 
27 #include <string>
28 
34 #define SERVO_TIMEOUT_USEC 150000
35 
36 namespace gcp {
37  namespace antenna {
38  namespace control {
39 
40  class SpecificShare;
41 
42  class ServoCommsSa : public Board {
43 
44  public:
45 
49  ServoCommsSa(SpecificShare* share, std::string name, bool sim);
50 
54  ServoCommsSa();
55 
59  ~ServoCommsSa();
60 
66  void haltAntenna();
67  void hardStopAntenna();
68  void initializeAntenna();
69  void queryStatus();
70  void queryStatus(gcp::util::TimeVal& currTime);
71  void queryAntPositions();
72  void queryAntPositions(gcp::util::TimeVal& currTime);
73 
74  bool readPosition(AxisPositions* axes, Model* model);
75  void commandNewPosition(PmacTarget* pmac);
76  void commandNewPosition(PmacTarget* pmac, PmacTarget* pmac1, PmacTarget* pmac2, gcp::util::TimeVal& mjd);
77 
82  bool isThermalTripped();
83  bool isLidOpen();
84  bool isBrakeOn();
85  bool isSim();
86  bool isInitialized();
87 
88  /*
89  * Check for first part of initialization
90  */
91  bool isPartOneComplete();
92 
96  void finishInitialization();
97 
102  void fillUtc(gcp::util::TimeVal& currTime);
103 
104 
110  bool connect();
111 
115  void disconnect();
116 
120  bool servoIsConnected();
121 
125  void sendCommand(ServoCommandSa& command);
126 
132  int readResponse(ServoCommandSa& command);
133 
134  // Return true if the servo is not ready for another command
135 
136  bool isBusy();
137 
138  unsigned readPositionFault();
139 
140  //------------------------------------------------------------
141  // Methods which will be used to read and write register values.
142  // These methods will send a the appropriate command to the servo,
143  // and time out waiting for a response.
144  //------------------------------------------------------------
145 
149  int writeString(std::string message);
150 
151  private:
152 
153  bool sim_;
154 
158  int fd_;
159 
163  struct termios termioSave_;
164 
168  RegMapBlock* utc_;
169  RegMapBlock* azPositions_;
170  RegMapBlock* azErrors_;
171  RegMapBlock* elPositions_;
172  RegMapBlock* elErrors_;
173  RegMapBlock* slowAzPos_;
174  RegMapBlock* slowElPos_;
175  RegMapBlock* servoStatus_;
176  RegMapBlock* servoThermalCutouts_;
177  RegMapBlock* servoContactors_;
178  RegMapBlock* servoCircuitBreakers_;
179  RegMapBlock* servoBrakes_;
180  RegMapBlock* driveLids_;
181  RegMapBlock* azWrap_;
182  RegMapBlock* azWrapSwitch_;
183  RegMapBlock* servoSeconds_;
184  RegMapBlock* servouSeconds_;
185  RegMapBlock* az_tacho1_;
186  RegMapBlock* az_tacho2_;
187  RegMapBlock* el_tacho1_;
188  RegMapBlock* el_tacho2_;
189  RegMapBlock* az_pid1_;
190  RegMapBlock* az_pid2_;
191  RegMapBlock* el_pid1_;
192  RegMapBlock* el_pid2_;
193 
197  gcp::util::FdSet fdSet_;
198 
202  bool connected_;
203 
209  public:
210  ServoCommandSa command_;
211 
215  ServoCommandSa issueCommand(ServoCommandSa::Request req, std::vector<float>& values);
216  ServoCommandSa issueCommand(ServoCommandSa::Request req);
217 
218  private:
222  bool responsePending_;
223 
227  bool initializationPartOne_;
228 
232  bool initializationComplete_;
233 
237  bool alarmStatus_;
238 
242  bool antennaHalted_;
246  void serviceMsgQ();
247 
252  void zeroReadFds();
253 
258  void registerReadFd(int fd);
259 
264  int waitForNextMessage();
265 
269  int readTCPPort(ServoCommandSa& command);
270 
274  int waitForResponse();
275 
279  void recordStatusResponse(ServoCommandSa& command);
280 
284  void wait(long nsec=100000000);
285 
286 
287  }; // End class ServoCommsSa
288 
289  }; // End namespace control
290  }; // End namespace antenna
291 }; // End namespace gcp
292 
293 
294 
295 
296 #endif // End
297 
ServoCommandSa command_
Definition: servoCommsSa.h:198
void fillUtc(gcp::util::TimeVal &currTime)
Definition: servoCommsSa.cc:785
ServoCommandSa issueCommand(ServoCommandSa::Request req, std::vector< float > &values)
Definition: servoCommsSa.cc:171
bool connect()
Definition: servoCommsSa.cc:260
void queryAntPositions()
Definition: servoCommsSa.cc:700
Request
Definition: ServoCommandSa.h:37
void initializeAntenna()
Definition: servoCommsSa.cc:551
~ServoCommsSa()
Definition: servoCommsSa.cc:106
void queryStatus()
Definition: servoCommsSa.cc:629
void setAzEl(gcp::util::Angle &az, gcp::util::Angle &el)
void disconnect()
Definition: servoCommsSa.cc:236
void sendCommand(ServoCommandSa &command)
Definition: servoCommsSa.cc:116
Definition: FdSet.h:16
bool isSim()
Definition: ServoCommsSa.cc:418
ServoCommsSa()
Definition: servoCommsSa.cc:96
int readResponse(ServoCommandSa &command)
Definition: servoCommsSa.cc:143
void finishInitialization()
Definition: servoCommsSa.cc:998
void haltAntenna()
Definition: servoCommsSa.cc:519
bool isBrakeOn()
Definition: servoCommsSa.cc:1131
bool servoIsConnected()
Definition: servoCommsSa.cc:372
bool readPosition(AxisPositions *axes, Model *model)
Definition: servoCommsSa.cc:825
bool isCircuitBreakerTripped()
Definition: servoCommsSa.cc:1079
bool isLidOpen()
Definition: servoCommsSa.cc:1119
Definition: Angle.h:20
Definition: TimeVal.h:55
int writeString(std::string message)
Definition: servoCommsSa.cc:380
bool isThermalTripped()
Definition: servoCommsSa.cc:1098
bool isInitialized()
Definition: servoCommsSa.cc:1143
void hardStopAntenna()
Definition: servoCommsSa.cc:536