My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ServoComms.h
Go to the documentation of this file.
1 #ifndef SERVOCOMMS_H
2 #define SERVOCOMMS_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/ServoCommand.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 ServoComms : public Board {
43 
44  public:
45 
49  ServoComms(SpecificShare* share, std::string name, bool sim);
50 
54  ServoComms();
55 
59  ~ServoComms();
60 
65  void hardStopAntenna(); // not nice on drives. don't use.
66  void haltAntenna();
67  void calibrateEncoders();
68  void initializeAntenna(int antNum=1);
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 
80  void setMaxAzVel(int antNum, float vMax);
81 
85  void finishInitialization();
86 
87 
92 
93 
98  void fillUtc(gcp::util::TimeVal& currTime);
99 
100 
106  bool connect();
107 
111  void disconnect();
112 
116  bool servoIsConnected();
117 
121  void sendCommand(ServoCommand& command);
122 
128  int readResponse(ServoCommand& command);
129 
130  // Return true if the servo is not ready for another command
131 
132  bool isBusy();
133 
134  // Return true if we have a 1PPS
135  bool isPpsPresent();
136 
137  // Return true if the encoders are calibrated
138  bool isCalibrated();
139 
140  // Returns the value of the tracking loop (1 -TON, 3 - Cal encoders, 5 - Time loop)
141  int checkTrackLoop();
142 
143  unsigned readPositionFault();
144 
145  //------------------------------------------------------------
146  // Methods which will be used to read and write register values.
147  // These methods will send a the appropriate command to the servo,
148  // and time out waiting for a response.
149  //------------------------------------------------------------
150 
154  int writeString(std::string message);
155 
156  private:
157 
158  bool sim_;
159 
163  int fd_;
164 
168  struct termios termioSave_;
169 
173  RegMapBlock* utc_;
174  RegMapBlock* azPositions_;
175  RegMapBlock* azErrors_;
176  RegMapBlock* elPositions_;
177  RegMapBlock* elErrors_;
178  RegMapBlock* errorCount_;
179  RegMapBlock* slowAzPos_;
180  RegMapBlock* slowElPos_;
181  RegMapBlock* az1CommI_;
182  RegMapBlock* az2CommI_;
183  RegMapBlock* el1CommI_;
184  RegMapBlock* az1ActI_;
185  RegMapBlock* az2ActI_;
186  RegMapBlock* el1ActI_;
187  RegMapBlock* az1Enable_;
188  RegMapBlock* az2Enable_;
189  RegMapBlock* el1Enable_;
190  RegMapBlock* taskLoop_;
191  RegMapBlock* encStatus_;
192  RegMapBlock* lowSoftAz_;
193  RegMapBlock* lowHardAz_;
194  RegMapBlock* hiSoftAz_;
195  RegMapBlock* hiHardAz_;
196  RegMapBlock* lowSoftEl_;
197  RegMapBlock* lowHardEl_;
198  RegMapBlock* hiSoftEl_;
199  RegMapBlock* hiHardEl_;
200  RegMapBlock* azWrap_;
201  RegMapBlock* azBrake_;
202  RegMapBlock* elBrake_;
203  RegMapBlock* eStop_;
204  RegMapBlock* simulator_;
205  RegMapBlock* ppsPresent_;
206 
210  gcp::util::FdSet fdSet_;
211 
215  bool connected_;
216 
222  public:
224 
225  private:
229  ServoCommand issueCommand(ServoCommand::Request req, std::vector<float>& values);
230  ServoCommand issueCommand(ServoCommand::Request req);
231 
235  bool responsePending_;
236 
240  int calibrationStatus_;
241 
245  bool initializationComplete_;
246 
250  void serviceMsgQ();
251 
256  void zeroReadFds();
257 
262  void registerReadFd(int fd);
263 
268  int waitForNextMessage();
269 
273  int readSerialPort(ServoCommand& command);
274 
278  void waitForResponse();
279 
283  void recordStatusResponse(ServoCommand& command);
284 
288  void wait(long nsec=100000000);
289 
290 
291  }; // End class ServoComms
292 
293  }; // End namespace control
294  }; // End namespace antenna
295 }; // End namespace gcp
296 
297 
298 
299 
300 #endif // End #ifndef
301 
302 
void setMaxAzVel(int antNum, float vMax)
int readResponse(ServoCommand &command)
Definition: ServoComms.cc:168
int writeString(std::string message)
Definition: ServoComms.cc:444
void setAzEl(gcp::util::Angle &az, gcp::util::Angle &el)
Definition: Board.h:24
Definition: FdSet.h:16
void sendCommand(ServoCommand &command)
Definition: ServoComms.cc:142
int inactiveCount_
Definition: ServoComms.h:91
Definition: ServoCommand.h:30
Definition: Model.h:33
bool servoIsConnected()
Definition: ServoComms.cc:436
ServoComms()
Definition: ServoComms.cc:122
void fillUtc(gcp::util::TimeVal &currTime)
Definition: Angle.h:20
ServoCommand command_
Definition: ServoComms.h:223
bool connect()
Definition: ServoComms.cc:285
Definition: TimeVal.h:55
~ServoComms()
Definition: ServoComms.cc:132
Definition: PmacTarget.h:28
Definition: AxisPositions.h:38
void disconnect()
Definition: ServoComms.cc:260
Request
Definition: ServoCommand.h:36
Definition: ServoComms.h:42