00001
00002
00004
00005 #ifndef BHAND_COMMANDS_H
00006 #define BHAND_COMMANDS_H
00007
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <ctype.h>
00011 #include <string.h>
00012
00013 #include "bhand_motors.h"
00014 #include "bhand_misc.h"
00015 #include "PucksInHand.h"
00016
00027
00028
00029 enum BHSupervisoryCommand
00030 {
00031 BHSupervisoryInit = 0,
00032 BHSupervisoryReset,
00033 BHSupervisoryClose,
00034 BHSupervisoryOpen,
00035 BHSupervisoryTorqueClose,
00036 BHSupervisoryTorqueOpen,
00037 BHSupervisoryStepClose,
00038 BHSupervisoryStepOpen,
00039 BHSupervisoryGoToDefault,
00040 BHSupervisoryGoToDifferentPositions,
00041 BHSupervisoryGoToHome,
00042 BHSupervisoryGoToPosition,
00043 BHSupervisoryGet,
00044 BHSupervisorySet,
00045 BHSupervisoryPGet,
00046 BHSupervisoryPSet,
00047 BHSupervisoryDefault,
00048 BHSupervisoryLoad,
00049 BHSupervisorySave,
00050 BHSupervisoryTemperature,
00051 BHSupervisoryCmd,
00052 BHSupervisoryDelay,
00053 BHSupervisoryStopMotor,
00054 BHSupervisoryBaud
00055 };
00056
00058
00059 enum BHSupervisoryResult
00060 {
00061 BHSupervisoryResultReset = 0,
00062 BHSupervisoryResultGet,
00063 BHSupervisoryResultPGet,
00064 BHSupervisoryResultTemperature,
00065 BHSupervisoryResultCmd
00066 };
00067
00068
00070
00071
00072
00074
00075
00076 class BHandSupervisoryCommand
00077 {
00078 public:
00079
00080 BHandSupervisoryCommand(BHSupervisoryCommand command) : m_supervisoryCommand(command) {}
00081 virtual ~BHandSupervisoryCommand() {}
00082
00083 BHSupervisoryCommand getCommand() { return m_supervisoryCommand; }
00084
00085 private:
00086 BHSupervisoryCommand m_supervisoryCommand;
00087 };
00088
00089
00090 class BHandSupervisoryResult
00091 {
00092 public:
00093
00094 BHandSupervisoryResult(BHSupervisoryResult result) : m_supervisoryResult(result) {}
00095 virtual ~BHandSupervisoryResult() {}
00096
00097 private:
00098 BHSupervisoryResult m_supervisoryResult;
00099 };
00100
00101
00103
00104
00105
00107
00108
00110
00112
00113
00114 class BHandCommandInit : public BHandSupervisoryCommand
00115 {
00116 public:
00117 BHandCommandInit(BHMotors motors) :
00118 BHandSupervisoryCommand(BHSupervisoryInit),
00119 Motors(motors) {}
00120 virtual ~BHandCommandInit() {}
00121
00122 BHMotors Motors;
00123 };
00124
00126
00127 class BHandCommandReset : public BHandSupervisoryCommand
00128 {
00129 public:
00130 BHandCommandReset() : BHandSupervisoryCommand(BHSupervisoryReset), Motors(0xffffffff) {}
00131 virtual ~BHandCommandReset() {}
00132
00133 BHMotors Motors;
00134 };
00135
00141 class BHandResultReset : public BHandSupervisoryResult
00142 {
00143 public:
00144 BHandResultReset(bool responseReceived) : BHandSupervisoryResult(BHSupervisoryResultReset), m_responseReceived(responseReceived) {}
00145 virtual ~BHandResultReset() {}
00146
00147 bool responseReceived() { return m_responseReceived; }
00148
00149 private:
00150 bool m_responseReceived;
00151 };
00152
00153
00155
00157
00158 class BHandCommandClose : public BHandSupervisoryCommand
00159 {
00160 public:
00161 BHandCommandClose(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryClose), Motors(motors) {}
00162 virtual ~BHandCommandClose() {}
00163
00164 BHMotors Motors;
00165 };
00166
00168
00169 class BHandCommandOpen : public BHandSupervisoryCommand
00170 {
00171 public:
00172 BHandCommandOpen(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryOpen), Motors(motors) {}
00173 virtual ~BHandCommandOpen() {}
00174
00175 BHMotors Motors;
00176 };
00177
00179
00180 class BHandCommandTorqueClose : public BHandSupervisoryCommand
00181 {
00182 public:
00183 BHandCommandTorqueClose(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryTorqueClose), Motors(motors) {}
00184 virtual ~BHandCommandTorqueClose() {}
00185
00186 BHMotors Motors;
00187 };
00188
00190
00191 class BHandCommandTorqueOpen : public BHandSupervisoryCommand
00192 {
00193 public:
00194 BHandCommandTorqueOpen(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryTorqueOpen), Motors(motors) {}
00195 virtual ~BHandCommandTorqueOpen() {}
00196
00197 BHMotors Motors;
00198 };
00199
00201
00202 class BHandCommandStepClose : public BHandSupervisoryCommand
00203 {
00204 public:
00205 BHandCommandStepClose(BHMotors motors, bool valueIncluded, int stepAmount) :
00206 BHandSupervisoryCommand(BHSupervisoryStepClose),
00207 Motors(motors), ValueIncluded(valueIncluded), StepAmount(stepAmount) {}
00208 virtual ~BHandCommandStepClose() {}
00209
00210 BHMotors Motors;
00211 bool ValueIncluded;
00212 int StepAmount;
00213 };
00214
00216
00217 class BHandCommandStepOpen : public BHandSupervisoryCommand
00218 {
00219 public:
00220 BHandCommandStepOpen(BHMotors motors, bool valueIncluded, int stepAmount) :
00221 BHandSupervisoryCommand(BHSupervisoryStepOpen),
00222 Motors(motors), ValueIncluded(valueIncluded), StepAmount(stepAmount) {}
00223 virtual ~BHandCommandStepOpen() {}
00224
00225 BHMotors Motors;
00226 bool ValueIncluded;
00227 int StepAmount;
00228 };
00229
00231
00232 class BHandCommandGoToDefault : public BHandSupervisoryCommand
00233 {
00234 public:
00235 BHandCommandGoToDefault(BHMotors motors, bool valueIncluded = false, int defaultPosition = 0) :
00236 BHandSupervisoryCommand(BHSupervisoryGoToDefault),
00237 Motors(motors), ValueIncluded(valueIncluded), DefaultPosition(defaultPosition) {}
00238 virtual ~BHandCommandGoToDefault() {}
00239
00240 BHMotors Motors;
00241 bool ValueIncluded;
00242 int DefaultPosition;
00243 };
00244
00246
00247 class BHandCommandGoToDifferentPositions : public BHandSupervisoryCommand
00248 {
00249 public:
00250
00251 BHandCommandGoToDifferentPositions(const int *encoderPositions, unsigned int numEncoderPositions)
00252 : BHandSupervisoryCommand(BHSupervisoryGoToDifferentPositions)
00253 {
00254 m_encoderPositions = new int[numEncoderPositions];
00255
00256 for (unsigned int i = 0; i < numEncoderPositions; i++)
00257 m_encoderPositions[i] = encoderPositions[i];
00258
00259 m_numEncoderPositions = numEncoderPositions;
00260 }
00261
00262 virtual ~BHandCommandGoToDifferentPositions() { delete[] m_encoderPositions; }
00263
00264 const int * getEncoderPositions() { return m_encoderPositions; }
00265 unsigned int getNumEncoderPositions() { return m_numEncoderPositions; }
00266
00267 private:
00268 int *m_encoderPositions;
00269 unsigned int m_numEncoderPositions;
00270 };
00271
00273
00274 class BHandCommandGoToHome : public BHandSupervisoryCommand
00275 {
00276 public:
00277 BHandCommandGoToHome(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryGoToHome), Motors(motors) {}
00278 virtual ~BHandCommandGoToHome() {}
00279
00280 BHMotors Motors;
00281 };
00282
00284
00285 class BHandCommandGoToPosition : public BHandSupervisoryCommand
00286 {
00287 public:
00288 BHandCommandGoToPosition(BHMotors motors, unsigned int encoderPositionTickCount) : BHandSupervisoryCommand(BHSupervisoryGoToPosition), Motors(motors), EncoderPositionTickCount(encoderPositionTickCount) {}
00289 virtual ~BHandCommandGoToPosition() {}
00290
00291 BHMotors Motors;
00292 unsigned int EncoderPositionTickCount;
00293 };
00294
00295
00296
00297
00299
00301
00302 class BHandCommandSet : public BHandSupervisoryCommand
00303 {
00304 public:
00305 BHandCommandSet(BHMotors motors, const char *property, int value) : BHandSupervisoryCommand(BHSupervisorySet), Motors(motors), Value(value)
00306 {
00307 m_property = new char[strlen(property) + 1];
00308 strcpy(m_property, property);
00309 }
00310 virtual ~BHandCommandSet() { delete[] m_property; }
00311
00312 const char * getProperty() { return m_property; }
00313
00314 BHMotors Motors;
00315 int Value;
00316
00317 private:
00318 char *m_property;
00319 };
00320
00322
00323 class BHandCommandPSet : public BHandSupervisoryCommand
00324 {
00325 public:
00326 BHandCommandPSet(const char *property, int value) : BHandSupervisoryCommand(BHSupervisoryPSet), Value(value)
00327 {
00328 m_property = new char[strlen(property) + 1];
00329 strcpy(m_property, property);
00330 }
00331 virtual ~BHandCommandPSet() {}
00332
00333 const char * getProperty() { return m_property; }
00334
00335 int Value;
00336
00337 private:
00338 char *m_property;
00339 };
00340
00342
00343 class BHandCommandGet : public BHandSupervisoryCommand
00344 {
00345 public:
00346 BHandCommandGet(BHMotors motors, const char *property) : BHandSupervisoryCommand(BHSupervisoryGet), Motors(motors)
00347 {
00348 m_property = new char[strlen(property) + 1];
00349 strcpy(m_property, property);
00350 }
00351 virtual ~BHandCommandGet() { delete[] m_property; }
00352
00353 const char * getProperty() { return m_property; }
00354
00355 BHMotors Motors;
00356
00357 private:
00358 char *m_property;
00359 };
00360
00362
00368 class BHandResultGet : public BHandSupervisoryResult
00369 {
00370 public:
00371 BHandResultGet(BHMotors motors, const int *results)
00372 : BHandSupervisoryResult(BHSupervisoryResultGet)
00373 {
00374
00375 m_numResults = countMotors(motors);
00376
00377
00378 m_results = new int[m_numResults];
00379 for (unsigned i = 0; i < m_numResults; i++)
00380 m_results[i] = results[i];
00381 }
00382 BHandResultGet(BHMotors motors, const int *results, int numResults)
00383 : BHandSupervisoryResult(BHSupervisoryResultGet)
00384 {
00385
00386 m_numResults = numResults;
00387
00388
00389 m_results = new int[m_numResults];
00390 for (unsigned i = 0; i < m_numResults; i++)
00391 m_results[i] = results[i];
00392 }
00393 virtual ~BHandResultGet()
00394 {
00395 delete[] m_results;
00396 }
00397
00398 int getResult(unsigned int i) { return m_results[i]; }
00399 unsigned int getNumResults() { return m_numResults; }
00400
00401 private:
00402 int *m_results;
00403 unsigned int m_numResults;
00404 };
00405
00406
00408
00409 class BHandCommandPGet : public BHandSupervisoryCommand
00410 {
00411 public:
00412 BHandCommandPGet(const char *property) : BHandSupervisoryCommand(BHSupervisoryPGet)
00413 {
00414 m_property = new char[strlen(property) + 1];
00415 strcpy(m_property, property);
00416 }
00417 virtual ~BHandCommandPGet() { delete[] m_property; }
00418
00419 const char * getProperty() { return m_property; }
00420
00421 private:
00422 char *m_property;
00423 };
00424
00426
00432 class BHandResultPGet : public BHandSupervisoryResult
00433 {
00434 public:
00435 BHandResultPGet(int result) : BHandSupervisoryResult(BHSupervisoryResultPGet), m_result(result) {}
00436 virtual ~BHandResultPGet() {}
00437
00438 int getResult() { return m_result; }
00439
00440 private:
00441 int m_result;
00442 };
00443
00444
00446
00447 class BHandCommandSave : public BHandSupervisoryCommand
00448 {
00449 public:
00450 BHandCommandSave(BHMotors motors) : BHandSupervisoryCommand(BHSupervisorySave), Motors(motors) {}
00451 virtual ~BHandCommandSave() {}
00452
00453 BHMotors Motors;
00454 };
00455
00457
00458 class BHandCommandLoad : public BHandSupervisoryCommand
00459 {
00460 public:
00461 BHandCommandLoad(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryLoad), Motors(motors) {}
00462 virtual ~BHandCommandLoad() {}
00463
00464 BHMotors Motors;
00465 };
00466
00468
00469 class BHandCommandDefault : public BHandSupervisoryCommand
00470 {
00471 public:
00472 BHandCommandDefault(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryDefault), Motors(motors) {}
00473 virtual ~BHandCommandDefault() {}
00474
00475 BHMotors Motors;
00476 };
00477
00479
00480 class BHandCommandTemperature : public BHandSupervisoryCommand
00481 {
00482 public:
00483 BHandCommandTemperature(BHMotors motors = 15) : BHandSupervisoryCommand(BHSupervisoryTemperature), Motors(motors) {}
00484 virtual ~BHandCommandTemperature() {}
00485
00486 BHMotors Motors;
00487 };
00488
00494 class BHandResultTemperature : public BHandSupervisoryResult
00495 {
00496 public:
00497 BHandResultTemperature(int temperature) : BHandSupervisoryResult(BHSupervisoryResultTemperature)
00498 {
00499 m_temperatures = new int[1];
00500 m_temperatures[0] = temperature;
00501 m_numTemperatures = 1;
00502 }
00503 BHandResultTemperature(const int *temperatures, unsigned int numTemperatures) : BHandSupervisoryResult(BHSupervisoryResultTemperature)
00504 {
00505 m_temperatures = new int[numTemperatures];
00506 for (unsigned int i = 0; i < numTemperatures; i++)
00507 m_temperatures[i] = temperatures[i];
00508 m_numTemperatures = numTemperatures;
00509 }
00510 virtual ~BHandResultTemperature()
00511 {
00512 delete[] m_temperatures;
00513 }
00514
00515 int getTemperature()
00516 {
00517 if (m_numTemperatures > 1)
00518 {
00519 int maxTemperature = 0;
00520 for (unsigned int i = 0; i < m_numTemperatures; i++)
00521 maxTemperature = MAX(maxTemperature, m_temperatures[i]);
00522 return maxTemperature;
00523 }
00524 else
00525 return m_temperatures[0];
00526 }
00527
00528 private:
00529 int *m_temperatures;
00530 unsigned int m_numTemperatures;
00531 };
00532
00533
00535
00537
00538 class BHandCommandDelay : public BHandSupervisoryCommand
00539 {
00540 public:
00541 BHandCommandDelay(unsigned int msec) : BHandSupervisoryCommand(BHSupervisoryDelay), MilliSeconds(msec) {}
00542 virtual ~BHandCommandDelay() {}
00543
00544 unsigned int MilliSeconds;
00545 };
00546
00548
00549 class BHandCommandStopMotor : public BHandSupervisoryCommand
00550 {
00551 public:
00552 BHandCommandStopMotor(BHMotors motors) : BHandSupervisoryCommand(BHSupervisoryStopMotor), Motors(motors) {}
00553 virtual ~BHandCommandStopMotor() {}
00554
00555 BHMotors Motors;
00556 };
00557
00559
00560 class BHandCommandBaud : public BHandSupervisoryCommand
00561 {
00562 public:
00563 BHandCommandBaud(unsigned int newBaud) : BHandSupervisoryCommand(BHSupervisoryBaud), NewBaud(newBaud) {}
00564 virtual ~BHandCommandBaud() {}
00565
00566 unsigned int NewBaud;
00567 };
00568
00570
00571 class BHandCommandCommand : public BHandSupervisoryCommand
00572 {
00573 public:
00574 BHandCommandCommand(const char * send) :
00575 BHandSupervisoryCommand(BHSupervisoryCmd)
00576 {
00577 m_send = new char[strlen(send) + 1];
00578 strcpy(m_send, send);
00579 }
00580 virtual ~BHandCommandCommand() { delete[] m_send; }
00581
00582 const char * getSend() { return m_send; }
00583
00584 private:
00585 char *m_send;
00586 };
00587
00593 class BHandResultCommand : public BHandSupervisoryResult
00594 {
00595 public:
00596 BHandResultCommand(const char * receive) :
00597 BHandSupervisoryResult(BHSupervisoryResultCmd)
00598 {
00599 if (receive != NULL)
00600 {
00601 m_receive = new char[strlen(receive) + 1];
00602 strcpy(m_receive, receive);
00603 }
00604 else
00605 {
00606 m_receive = new char[1];
00607 m_receive[0] = 0;
00608 }
00609 }
00610 virtual ~BHandResultCommand() { delete[] m_receive; }
00611
00612 const char * getReceive() { return m_receive; }
00613
00614 private:
00615 char *m_receive;
00616 };
00617
00619
00620 #endif