3 static const double MILLION = 1000000.0;
4 static const double BILLION = 1000000000.0;
7 : _port_name(port_name), _baudrate(baudrate), _mode(mode), simple_(simple)
53 uint8_t send_array[20];
58 unsigned char s1 = (
unsigned char)(left_speed >> 24);
59 unsigned char s2 = (
unsigned char)(left_speed >> 16);
60 unsigned char s3 = (
unsigned char)(left_speed >> 8);
61 unsigned char s4 = (
unsigned char)left_speed;
63 unsigned char s5 = (
unsigned char)(right_speed >> 24);
64 unsigned char s6 = (
unsigned char)(right_speed >> 16);
65 unsigned char s7 = (
unsigned char)(right_speed >> 8);
66 unsigned char s8 = (
unsigned char)right_speed;
89 uint8_t send_array[20];
93 unsigned char s1 = (
unsigned char)(left_speed >> 24);
94 unsigned char s2 = (
unsigned char)(left_speed >> 16);
95 unsigned char s3 = (
unsigned char)(left_speed >> 8);
96 unsigned char s4 = (
unsigned char)left_speed;
115 uint8_t send_array[20];
119 unsigned char s5 = (
unsigned char)(right_speed >> 24);
120 unsigned char s6 = (
unsigned char)(right_speed >> 16);
121 unsigned char s7 = (
unsigned char)(right_speed >> 8);
122 unsigned char s8 = (
unsigned char)right_speed;
143 uint8_t send_array[20];
147 unsigned char bytes[4];
153 unsigned char fl_array[4];
154 memcpy(fl_array, &val, 4);
173 }
else if(side ==
'R')
197 send_array[4] = fl_array[3];
198 send_array[5] = fl_array[2];
199 send_array[6] = fl_array[1];
200 send_array[7] = fl_array[0];
209 uint8_t send_array[20];
213 }
else if(side ==
'R'){
220 send_array[4] = (
unsigned char)(value >> 24);
221 send_array[5] = (
unsigned char)(value >> 16);
222 send_array[6] = (
unsigned char)(value >> 8);
223 send_array[7] = (
unsigned char)value;
233 uint8_t send_array[20];
239 send_array[4] = (
unsigned char)(value >> 24);
240 send_array[5] = (
unsigned char)(value >> 16);
241 send_array[6] = (
unsigned char)(value >> 8);
242 send_array[7] = (
unsigned char)value;
251 uint8_t send_array[20];
257 send_array[4] = (
unsigned char)(value >> 24);
258 send_array[5] = (
unsigned char)(value >> 16);
259 send_array[6] = (
unsigned char)(value >> 8);
260 send_array[7] = (
unsigned char)value;
269 uint8_t send_array[20];
275 send_array[4] = (
unsigned char)(value >> 24);
276 send_array[5] = (
unsigned char)(value >> 16);
277 send_array[6] = (
unsigned char)(value >> 8);
278 send_array[7] = (
unsigned char)value;
288 uint8_t send_array[20];
294 send_array[4] = (
unsigned char)value;
303 uint8_t send_array[20];
308 send_array[4] = diag;
318 uint8_t send_array[2];
330 uint8_t send_array[2];
342 uint8_t send_array[2];
353 uint8_t send_array[2];
365 }
else if(param ==
'I'){
371 }
else if(param ==
'D'){
379 else if(side ==
'R'){
386 }
else if(param ==
'I'){
392 }
else if(param ==
'D'){
407 uint8_t send_array[2];
428 uint8_t send_array[2];
440 uint8_t send_array[2];
452 uint8_t send_array[2];
464 uint8_t send_array[2];
476 uint8_t send_array[2];
488 uint8_t send_array[2];
500 uint8_t send_array[2];
512 uint8_t send_array[2];
524 uint8_t send_array[2];
536 uint8_t send_array[2];
547 uint8_t send_array[10];
560 uint8_t send_array[10];
573 uint8_t send_array[10];
587 uint8_t send_array[2];
598 uint8_t send_array[2];
633 uint8_t send_array[2];
644 uint8_t send_array[20];
650 send_array[4] = (
unsigned char)value;
660 uint8_t send_array[2];
672 uint8_t send_array[2];
684 uint8_t send_array[2];
695 struct timeval tv1, tv2;
696 struct timespec ctv1, ctv2;
698 double _time_diff = 0;
701 gettimeofday(&tv1, NULL);
712 gettimeofday(&tv1, NULL);
721 gettimeofday(&tv1, NULL);
722 gettimeofday(&tv2, NULL);
724 clock_gettime(CLOCK_MONOTONIC, &ctv1);
725 clock_gettime(CLOCK_MONOTONIC, &ctv2);
737 clock_gettime(CLOCK_MONOTONIC, &ctv2);
738 _time_diff = ctv2.tv_sec - ctv1.tv_sec + (ctv2.tv_nsec - ctv1.tv_nsec) /
BILLION;
755 clock_gettime(CLOCK_MONOTONIC, &ctv2);
756 _time_diff = ctv2.tv_sec - ctv1.tv_sec + (ctv2.tv_nsec - ctv1.tv_nsec) /
BILLION;
780 uint8_t inData[24] = {0};
781 int recievedData = 0;
791 if (recievedData == 0)
797 return process(inData, recievedData, _command_to_read);
805 uint8_t* ret_data_ =
new uint8_t[recievedData];
806 memcpy( ret_data_, inData, recievedData *
sizeof(uint8_t) );
824 if (recievedData > 0)
829 memcpy(
tempData, inData, recievedData);
833 tempDataIndex += recievedData;
854 if (
tempData[1] != _command_to_read)
877 }
else if(data_len == -1){
892 for (
int i = start; i < start+end; i++)
903 for(
int i=0; i<size; i++)
909 return (ret & 255) - 1;
918 for(
int i=0; i<size; i++)
924 ret = (ret & 0xFF) - 1;
936 for(i = 0; i<size; i++)
938 checksum = checksum + buf[i];
942 checksum = (checksum & 0xFF) - 1;
945 checksum = checksum & 0xFF;
948 if(checksum == buf[size])
966 int total_len = data_len + 5;
977 for (start = 0; start < lastIndex ; start++)
985 lastIndex = lastIndex - start;
1003 _bumpers.push_back((buf[4] >> 3) & 0x01);
1004 _bumpers.push_back((buf[4] >> 2) & 0x01);
1005 _bumpers.push_back((buf[4] >> 1) & 0x01);
1017 int l_speed = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1018 int r_speed= buf[8] + (buf[9] << 8) + (buf[10] << 16) + (buf[11] << 24);
1030 int l_speed = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1041 int r_speed = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1054 val.bytes[0] = buf[4];
1055 val.bytes[1] = buf[5];
1056 val.bytes[2] = buf[6];
1057 val.bytes[3] = buf[7];
1065 val.bytes[0] = buf[4];
1066 val.bytes[1] = buf[5];
1067 val.bytes[2] = buf[6];
1068 val.bytes[3] = buf[7];
1075 val.bytes[0] = buf[4];
1076 val.bytes[1] = buf[5];
1077 val.bytes[2] = buf[6];
1078 val.bytes[3] = buf[7];
1085 val.bytes[0] = buf[4];
1086 val.bytes[1] = buf[5];
1087 val.bytes[2] = buf[6];
1088 val.bytes[3] = buf[7];
1095 val.bytes[0] = buf[4];
1096 val.bytes[1] = buf[5];
1097 val.bytes[2] = buf[6];
1098 val.bytes[3] = buf[7];
1105 val.bytes[0] = buf[4];
1106 val.bytes[1] = buf[5];
1107 val.bytes[2] = buf[6];
1108 val.bytes[3] = buf[7];
1115 _imax_l = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1123 _imax_r = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1131 _maxspeed_fwd = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1136 _maxspeed_rev = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1141 _maxaccel = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1146 _batt_volt = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1151 _batt_current = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1156 _batt_soc = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24);
1162 int l_position = buf[5] + (buf[6] << 8) + (buf[7] << 16) + (buf[8] << 24);
1178 int r_position = buf[5] + (buf[6] << 8) + (buf[7] << 16) + (buf[8] << 24);
1224 _sonars.push_back(buf[4] + (buf[5] << 8));
1225 _sonars.push_back(buf[6] + (buf[7] << 8));
1226 _sonars.push_back(buf[8] + (buf[9] << 8));
1227 _sonars.push_back(buf[10] + (buf[11] << 8));
1228 _sonars.push_back(buf[12] + (buf[13] << 8));
1229 _sonars.push_back(buf[14] + (buf[15] << 8));
1230 _sonars.push_back(buf[16] + (buf[17] << 8));
1241 for (i = 0; i < length; i++)
1244 printf(
"%d ",buf[i] );
void set_estop(bool value)
void set_param_pid(char side, char param, float value)
void set_param_imax(char side, uint32_t value)
void set_read_timeout(double timeout)
int poll_comport(unsigned char *, int)
int send_buf(unsigned char *, int)
int send_and_get_reply(uint8_t _command, uint8_t *send_array, int send_size, bool is_ack)
milvus::SerialComm serial_port
int get_batt_volt(bool update=false)
void clear_diag(int diag)
int write_bytes(unsigned char *, int)
int open_device(uint16_t vendor_id, uint16_t product_id, int ep_in_addr, int ep_out_addr)
bool _diag_aux_lights_err
int get_maxaccel(bool update=false)
std::vector< int > get_sonars(bool update=false)
void set_speed_l(int32_t left_speed)
int get_speed_r(bool update=false)
static const double BILLION
std::vector< int > _sonars
int get_batt_current(bool update=false)
void set_maxspeed_rev(uint32_t value)
int process_simple(uint8_t *inData, int recievedData, uint8_t _command_to_read)
int first_validator(uint8_t *buf)
void set_speed_r(int32_t right_speed)
bool get_estop(bool update=false)
void set_speeds(int32_t left_speed, int32_t right_speed)
bool checksum_match(uint8_t *buf, int size)
MRP2_Serial(std::string port_name, uint32_t baudrate=38400, std::string mode="8N1", bool simple=true)
int get_speed_l(bool update=false)
std::vector< int > get_positions(bool update=false)
void array_chopper(uint8_t *buf, int start, int end)
int get_position_r(bool update=false)
void set_max_accel(uint32_t value)
void print_array(uint8_t *buf, int length)
static const double MILLION
bool get_estop_button(bool update=false)
double get_read_timeout(void)
int execute_command(uint8_t *buf)
std::vector< int > _positions
int open_port(std::string port_name, int baudrate, std::string mode_s)
int process(uint8_t *inData, int recievedData, uint8_t _command_to_read)
bool get_bumper_estop(bool update=false)
int second_validator(uint8_t *buf, int data_len)
int get_position_l(bool update=false)
unsigned char checksum(int size)
void set_bumper_estop(bool value)
std::vector< int > get_speeds(bool update=false)
int get_maxspeed_rev(bool update=false)
int get_batt_soc(bool update=false)
std::vector< int > _bumpers
unsigned char checksum_check_array(uint8_t *arr, int size)
int read_serial(uint8_t _command_to_read)
int read_bytes(unsigned char *, int)
int find_message_start(uint8_t *buf, int lastIndex)
int get_batt_cell_capacity(bool update=false)
std::vector< int > get_param_imax(char side, bool update=false)
bool _diag_motor_drvr_err
void set_maxspeed_fwd(uint32_t value)
float get_param_pid(char side, char param, bool update=false)
std::vector< int > get_bumpers(bool update=false)
std::vector< int > _speeds
int get_maxspeed_fwd(bool update=false)