My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
ServoCommand.h
Go to the documentation of this file.
1 #ifndef SERVOCOMMAND_H
2 #define SERVOCOMMAND_H
3 
12 #include <string>
13 #include <map>
14 #include <vector>
15 
16 // The hard limit -- pmac can't process more than this in a single
17 // message
18 
19 #define SERVO_DATA_MAX_LEN 1600
20 #define MILLI_SECOND_SAMPLE_RATE 200
21 #define MAX_RESPONSE_SAMPLES 1000/MILLI_SECOND_SAMPLE_RATE*4+2
22 
23 namespace gcp {
24  namespace antenna {
25  namespace control {
26 
27 
28  class ServoComms;
29 
30  class ServoCommand {
31  public:
32 
36  enum Request {
37 
38  /* need a PACKBLAHBLAH function to deal with each of these. */
39  INVALID, // Default which will be used to
40  // indicate that a command has not
41  // been initialized
42  /* First set is for the Douloi box */
43  GET_AZEL ,
44  GET_PRIOR_LOC ,
45  GET_PPS_TICK ,
46  SEND_POS ,
47  BEGIN_PPS_LOOP ,
48  BEGIN_TRACK_LOOP,
49  LOAD_LOOP_PARAMS,
50  STOP_ALL ,
51  CAL_ENCODERS ,
52  CLEAR_OFFSETS ,
53  POSITION_OFFSET ,
54  VELOCITY_OFFSET ,
55  POSITION_ERRORS ,
56  SET_ENCODERS ,
57  QUERY_STATUS ,
58  AZ_BRAKE_ON ,
59  AZ_BRAKE_OFF ,
60  EL_BRAKE_ON ,
61  EL_BRAKE_OFF ,
62  SET_AZ_TORQUE ,
63  SET_EL_TORQUE ,
64  QUERY_VERSION ,
65  SET_AZ_TORQUES ,
66  READ_AZ_ENCODERS,
67  NUMBER_ERRORS ,
68 
69  /* Second set is for the electronics card */
70  START_AMP_COMMS ,
71  ENABLE_AZ_AMP1 ,
72  ENABLE_AZ_AMP2 ,
73  ENABLE_EL_AMP ,
74  DISABLE_AZ_AMP1 ,
75  DISABLE_AZ_AMP2 ,
76  DISABLE_EL_AMP ,
77  STATUS_AZ_AMP1 ,
78  STATUS_AZ_AMP2 ,
79  STATUS_EL_AMP ,
80  ALIVE_AZ_AMP1 ,
81  ALIVE_AZ_AMP2 ,
82  ALIVE_EL_AMP ,
83  ACTUAL_CURR_AZ1 ,
84  ACTUAL_CURR_AZ2 ,
85  ACTUAL_CURR_EL ,
86  COMMAND_CURR_AZ1 ,
87  COMMAND_CURR_AZ2 ,
88  COMMAND_CURR_EL
89 
90  // /* First set is for the Douloi box
91  // INVALID = '';
92  // GET_AZEL = 'GAE';
93  // GET_PRIOR_LOC = 'GIM';
94  // GET_PPS_TICK = 'GPPS';
95  // SEND_POS = 'AEL'; // needs further input
96  // BEGIN_PPS_LOOP = 'TIM';
97  // BEGIN_TRACK_LOOP = 'TON';
98  // LOAD_LOOP_PARAMS = 'LPR'; //needs further input
99  // STOP_ALL = 'SPA';
100  // CAL_ENCODERS = 'CLE';
101  // CLEAR_OFFSETS = 'CLO';
102  // POSITION_OFFSET = 'POF'; //needs more input
103  // VELOCITY_OFFSET = 'VOF'; //needs more input
104  // POSITION_ERRORS = 'ERR';
105  // SET_ENCODERS = 'SEN'; //needs more input
106  // QUERY_STATUS = 'STS';
107  // AZ_BRAKE_ON = 'ABN';
108  // AZ_BRAKE_OFF = 'ABF';
109  // EL_BRAKE_ON = 'EBN';
110  // EL_BRAKE_OFF = 'EBF';
111  // SET_AZ_TORQUE = 'AZV'; //needs more input
112  // SET_EL_TORQUE = 'ELV'; //needs more input
113  // QUERY_VERSION = 'VER';
114  // SET_AZ_TORQUES = 'AZS'; //needs more input
115  // READ_AZ_ENCODERS = 'ENC';
116  // REPORT_ERRORS = 'ERR';
117  // */
118  //
119  // /* Second set is for the electronics card
120  // START_AMP_COMMS = '2A01'; // if not completed, no >
121  // ENABLE_AZ_AMP1 = '2A01EN1'; // if not completed, no >
122  // ENABLE_AZ_AMP2 = '2A02EN1';
123  // ENABLE_EL_AMP = '2A03EN1';
124  // DISABLE_AZ_AMP1 = '2A01EN0'; // 2A01> if not completed, no >
125  // DISABLE_AZ_AMP2 = '2A02EN0';
126  // DISABLE_EL_AMP = '2A03EN0';
127  // QUERY_AZ_AMP1 = '2A01EN'; // 2A01(0-1) for disable/enable
128  // QUERY_AZ_AMP2 = '2A02EN';
129  // STATUS_EL_AMP = '2A03EN';
130  // ALIVE_AZ_AMP1 = '2A01RST'; // if 2A01>, the amp is communicating.
131  // ALIVE_AZ_AMP2 = '2A02RST';
132  // ALIVE_EL_AMP = '2A03RST';
133  // ACTUAL_CURR_AZ1 = '2A01SIA'; // 2A01VAL (in abs term)
134  // ACTUAL_CURR_AZ2 = '2A02SIA';
135  // ACTUAL_CURR_EL = '2A03SIA';
136  // COMMAND_CURR_AZ1 = '2A01SIC'; // 2A01+-VAL
137  // COMMAND_CURR_AZ2 = '2A02SIC';
138  // COMMAND_CURR_EL = '2A03SIC';
139  // */
140  };
141 
145  std::map<Request, std::string> commandMap_;
146 
150  void constructMap();
151 
155  unsigned char request_;
156 
160  std::string messageToSend_;
161 
165  std::string expectedResponse_;
166 
170  char responseReceived_[SERVO_DATA_MAX_LEN];
171 
175  ServoCommand();
176 
180  ~ServoCommand();
181 
185  void packCommand(Request req);
186  void packCommand(Request req, std::vector<float>& values);
187 
188 
192  void checkOneOutput();
193 
197  void checkTwoOutputs();
198 
202  void checkManyOutputs();
203 
204 
208  void interpretStatusResponse(const char* response);
209 
213  void packStartAmpComms();
214 
218  void packEnableElAmp();
219 
223  void packDisableElAmp();
224 
228  void packEnableAzAmp1();
229 
233  void packDisableAzAmp1();
234 
238  void interpretResponse();
239 
243  bool simpleValidityCheck();
244 
248  size_t responseLength();
249 
250 
251  // private:
252 
253  friend class ServoComms;
254 
258  unsigned short cmdSize_;
259 
264 
269  unsigned short responseLength_;
270 
274  unsigned char readData_[SERVO_DATA_MAX_LEN];
275 
280  unsigned char tmpBuffer_[SERVO_DATA_MAX_LEN];
281 
286 
291 
296 
300  float responseValue_[MAX_RESPONSE_SAMPLES];
301 
305  size_t size();
306 
307 
308  }; // End class ServoCommand
309 
310  }; // End namespace control
311  }; // End namespace antenna
312 }; // End namespace gcp
313 
314 #endif // End #ifndef
unsigned char readData_[SERVO_DATA_MAX_LEN]
Definition: ServoCommand.h:274
float responseValue_[MAX_RESPONSE_SAMPLES]
Definition: ServoCommand.h:300
void packDisableElAmp()
Definition: ServoCommand.cc:338
void constructMap()
Definition: ServoCommand.cc:736
char responseReceived_[SERVO_DATA_MAX_LEN]
Definition: ServoCommand.h:170
void packEnableElAmp()
Definition: ServoCommand.cc:324
bool responseValid_
Definition: ServoCommand.h:285
std::string expectedResponse_
Definition: ServoCommand.h:165
std::map< Request, std::string > commandMap_
Definition: ServoCommand.h:145
void checkTwoOutputs()
Definition: ServoCommand.cc:645
void interpretStatusResponse(const char *response)
Definition: ServoCommand.cc:612
void packEnableAzAmp1()
Definition: ServoCommand.cc:352
unsigned short cmdSize_
Definition: ServoCommand.h:258
Definition: ServoCommand.h:30
size_t responseLength()
Definition: ServoCommand.cc:391
void packCommand(Request req)
Definition: ServoCommand.cc:38
~ServoCommand()
Definition: ServoCommand.cc:33
void interpretResponse()
Definition: ServoCommand.cc:399
void packDisableAzAmp1()
Definition: ServoCommand.cc:366
void packStartAmpComms()
Definition: ServoCommand.cc:309
void checkOneOutput()
Definition: ServoCommand.cc:530
unsigned char tmpBuffer_[SERVO_DATA_MAX_LEN]
Definition: ServoCommand.h:280
size_t size()
Definition: ServoCommand.cc:383
unsigned short responseLength_
Definition: ServoCommand.h:269
bool ppsPresent_
Definition: ServoCommand.h:295
void checkManyOutputs()
Definition: ServoCommand.cc:679
ServoCommand()
Definition: ServoCommand.cc:24
Request
Definition: ServoCommand.h:36
std::string messageToSend_
Definition: ServoCommand.h:160
bool expectsResponse_
Definition: ServoCommand.h:263
bool simpleValidityCheck()
Definition: ServoCommand.cc:511
Definition: ServoComms.h:42
bool responseValueValid_
Definition: ServoCommand.h:290
unsigned char request_
Definition: ServoCommand.h:155