g30esli.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 2017-2019 Autoware Foundation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef G30ESLI_H
  17. #define G30ESLI_H
  18. #include <iostream>
  19. #include <sstream>
  20. #include <string>
  21. #include <vector>
  22. #include <cstdint>
  23. #include <cstring>
  24. #include <cansend.h>
  25. #define G30ESLI_WHEEL_BASE 2.14
  26. #define G30ESLI_MODE_MANUAL 3
  27. #define G30ESLI_MODE_AUTO 8
  28. #define G30ESLI_BRAKE_NONE 0
  29. #define G30ESLI_BRAKE_SMOOTH 1
  30. #define G30ESLI_BRAKE_SEMIEMG 2
  31. #define G30ESLI_BRAKE_EMERGENCY 3
  32. #define G30ESLI_SHIFT_DRIVE 0
  33. #define G30ESLI_SHIFT_REVERSE 1
  34. #define G30ESLI_SHIFT_NEUTRAL 2
  35. #define G30ESLI_FLASHER_NONE 0
  36. #define G30ESLI_FLASHER_RIGHT 1
  37. #define G30ESLI_FLASHER_LEFT 2
  38. #define G30ESLI_FLASHER_HAZARD 3
  39. #define G30ESLI_FLASHER_CLEAR 4
  40. namespace ymc
  41. {
  42. class G30esli
  43. {
  44. private:
  45. FILE* dev_;
  46. CanSender sender_;
  47. public:
  48. struct Command
  49. {
  50. float speed = 0.0;
  51. float steer = 0.0;
  52. unsigned char mode = 3;
  53. unsigned char brake = 0;
  54. unsigned char shift = 0;
  55. unsigned char alive = 0;
  56. unsigned char turn = 0;
  57. unsigned char flasher = 0;
  58. };
  59. struct SpeedStatus
  60. {
  61. float target;
  62. float actual;
  63. float desired;
  64. };
  65. struct SteerStatus
  66. {
  67. float target;
  68. float actual;
  69. };
  70. struct BatteryStatus
  71. {
  72. float charge;
  73. float voltage;
  74. float amperage;
  75. };
  76. struct WarningStatus
  77. {
  78. bool warning[21];
  79. };
  80. struct OverrideStatus
  81. {
  82. unsigned short steer;
  83. unsigned char accel;
  84. unsigned char brake;
  85. unsigned char flasher;
  86. };
  87. struct Status
  88. {
  89. SpeedStatus speed;
  90. SteerStatus steer;
  91. BatteryStatus battery;
  92. WarningStatus warning;
  93. OverrideStatus override;
  94. unsigned char mode;
  95. unsigned char shift;
  96. unsigned char brake;
  97. unsigned char turn;
  98. };
  99. G30esli();
  100. ~G30esli();
  101. bool openDevice(const std::string& device);
  102. void sendCommand(const Command& command);
  103. void readStatus(Status& status);
  104. static std::string dumpCommand(const Command& command);
  105. static std::string dumpStatus(const Status& status);
  106. };
  107. } // namespace
  108. #endif // G30ESLI_H