motor_message.h
Go to the documentation of this file.
1 
31 #ifndef MOTORMESSAGE_H
32 #define MOTORMESSAGE_H
33 
34 #include <stdint.h>
35 #include <boost/array.hpp>
36 #include <vector>
37 
38 typedef boost::array<uint8_t, 8> RawMotorMessage;
39 
40 class MotorMessage {
41 public:
42  // Using default constructor and destructor
45 
46  // MessageTypes enum in class to avoid global namespace pollution
47  enum MessageTypes {
48  TYPE_READ = 0xA,
49  TYPE_WRITE = 0xB,
51  TYPE_ERROR = 0xD
52  };
53 
54  // Registers enum in class to avoid global namespace pollution
55  enum Registers {
59 
60  REG_LEFT_PWM = 0x03,
61  REG_RIGHT_PWM = 0x04,
62 
63  // skip 0x05 and 0x06
64 
67 
68  REG_LEFT_RAMP = 0x09,
70 
71  REG_LEFT_ODOM = 0x0B,
73 
74  REG_DEADMAN = 0x0D,
75 
78 
85  REG_5V_AUX_OL = 0x16,
90 
91  REG_PARAM_P = 0x1B,
92  REG_PARAM_I = 0x1C,
93  REG_PARAM_D = 0x1D,
94  REG_PARAM_C = 0x1E,
95 
96  REG_LED_1 = 0x1F,
97  REG_LED_2 = 0x20,
98 
101 
107 
110 
113 
117 
118  DEBUG_50 = 0x50,
119  DEBUG_51 = 0x51,
120  DEBUG_52 = 0x52,
121  DEBUG_53 = 0x53,
122  DEBUG_54 = 0x54,
123  DEBUG_55 = 0x55,
124  DEBUG_56 = 0x56,
125  DEBUG_57 = 0x57,
126  DEBUG_58 = 0x58
127  };
128 
129  // Bitfield indicating which limits have been reached
130  enum Limits {
131  LIM_M1_PWM = 0x10,
132  LIM_M2_PWM = 0x01,
135  };
136 
139 
142 
143  void setData(int32_t data);
144  int32_t getData() const;
145 
146  RawMotorMessage serialize() const;
147 
148  int deserialize(const RawMotorMessage &serialized);
149 
150 private:
151  // Type of message should be in MotorMessage::MessageTypes
152  uint8_t type;
153  // Register address should be in MotorMessage::Registers
154  uint8_t register_addr;
155 
156  // 4 bytes of data, numbers should be in big endian format
157  boost::array<uint8_t, 4> data;
158 
159  const static uint8_t delimeter =
160  0x7E; // Hard coded for now, should be parameterized
161  const static uint8_t protocol_version =
162  0x03; // Hard coded for now, should be parameterized
163 
164  const static uint8_t valid_types[];
165  const static uint8_t valid_registers[];
166 
167  static int verifyType(uint8_t t);
168  static int verifyRegister(uint8_t r);
169 
170  static uint8_t generateChecksum(const std::vector<uint8_t> &data);
171  static uint8_t generateChecksum(const RawMotorMessage &data);
172 };
173 
174 #endif
static const uint8_t delimeter
MotorMessage::MessageTypes getType() const
void setData(int32_t data)
static uint8_t generateChecksum(const std::vector< uint8_t > &data)
MotorMessage::Registers getRegister() const
boost::array< uint8_t, 8 > RawMotorMessage
Definition: motor_message.h:38
static const uint8_t protocol_version
static const uint8_t valid_types[]
static int verifyType(uint8_t t)
uint8_t register_addr
RawMotorMessage serialize() const
boost::array< uint8_t, 4 > data
void setRegister(MotorMessage::Registers reg)
void setType(MotorMessage::MessageTypes type)
static const uint8_t valid_registers[]
static int verifyRegister(uint8_t r)
int deserialize(const RawMotorMessage &serialized)
int32_t getData() const


ubiquity_motor
Author(s):
autogenerated on Mon Jun 10 2019 15:37:24