rm_control
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
data.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BSD 3-Clause License
3 *
4 * Copyright (c) 2021, Qiayuan Liao
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * * Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33
34//
35// Created by peter on 2021/7/17.
36//
37
38#pragma once
39
40#include <ros/ros.h>
41#include <unistd.h>
42#include <serial/serial.h>
43#include <nav_msgs/Odometry.h>
44#include <sensor_msgs/JointState.h>
45#include <std_msgs/Float64.h>
46#include <std_msgs/Int8MultiArray.h>
47#include <tf2_ros/buffer.h>
48#include <tf2_ros/transform_listener.h>
49#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
50#include "std_msgs/UInt32.h"
51#include "rm_msgs/VisualizeStateData.h"
52
54
55#include <rm_msgs/ShootCmd.h>
56#include <rm_msgs/ShootState.h>
57#include <rm_msgs/DbusData.h>
58#include <rm_msgs/StateCmd.h>
59#include <rm_msgs/EventData.h>
60#include <rm_msgs/GimbalCmd.h>
61#include <rm_msgs/RobotHurt.h>
62#include <rm_msgs/ShootData.h>
63#include <rm_msgs/DartStatus.h>
64#include <rm_msgs/ChassisCmd.h>
65#include <rm_msgs/GameStatus.h>
66#include <rm_msgs/RfidStatus.h>
67#include <rm_msgs/EngineerUi.h>
68#include <rm_msgs/GameRobotHp.h>
69#include <rm_msgs/BalanceState.h>
70#include <rm_msgs/DartClientCmd.h>
71#include <rm_msgs/ActuatorState.h>
72#include <rm_msgs/MapSentryData.h>
73#include <rm_msgs/RadarMarkData.h>
74#include <rm_msgs/PowerHeatData.h>
75#include <rm_msgs/GimbalDesError.h>
76#include <rm_msgs/BulletAllowance.h>
77#include <rm_msgs/GameRobotStatus.h>
78#include <rm_msgs/ManualToReferee.h>
79#include <rm_msgs/ClientMapSendData.h>
80#include <rm_msgs/RobotsPositionData.h>
81#include <rm_msgs/DartInfo.h>
82#include <rm_msgs/StatusChangeRequest.h>
83#include <rm_msgs/ClientMapReceiveData.h>
84#include <rm_msgs/SupplyProjectileAction.h>
85#include <rm_msgs/IcraBuffDebuffZoneStatus.h>
86#include <rm_msgs/GameRobotPosData.h>
87#include "rm_msgs/SentryInfo.h"
88#include "rm_msgs/SentryCmd.h"
89#include "rm_msgs/RadarInfo.h"
90#include "rm_msgs/Buff.h"
91#include "rm_msgs/TrackData.h"
92#include "rm_msgs/SentryAttackingTarget.h"
93#include "rm_msgs/RadarToSentry.h"
94#include <rm_msgs/PowerManagementSampleAndStatusData.h>
95#include <rm_msgs/PowerManagementSystemExceptionData.h>
96#include <rm_msgs/PowerManagementInitializationExceptionData.h>
97#include <rm_msgs/PowerManagementProcessStackOverflowData.h>
98#include <rm_msgs/PowerManagementUnknownExceptionData.h>
99
100namespace rm_referee
101{
103{
107 double cap_power;
108 bool is_online = false;
109};
110
111class Base
112{
113public:
114 serial::Serial serial_;
115
116 int client_id_ = 0; // recipient's id
117 int robot_id_ = 0; // recent robot's id
119 std::string robot_color_;
121
123 {
124 serial::Timeout timeout = serial::Timeout::simpleTimeout(50);
125 serial_.setPort("/dev/usbReferee");
126 serial_.setBaudrate(115200);
127 serial_.setTimeout(timeout);
128 if (serial_.isOpen())
129 return;
130 try
131 {
132 serial_.open();
133 }
134 catch (serial::IOException& e)
135 {
136 ROS_ERROR("Cannot open referee port");
137 }
138 }
139
140 // CRC check
141 uint8_t getCRC8CheckSum(unsigned char* pch_message, unsigned int dw_length, unsigned char uc_crc_8)
142 {
143 unsigned char uc_index;
144 while (dw_length--)
145 {
146 uc_index = uc_crc_8 ^ (*pch_message++);
147 uc_crc_8 = rm_referee::kCrc8Table[uc_index];
148 }
149 return (uc_crc_8);
150 }
151
152 uint32_t verifyCRC8CheckSum(unsigned char* pch_message, unsigned int dw_length)
153 {
154 unsigned char uc_expected;
155 if ((pch_message == nullptr) || (dw_length <= 2))
156 return 0;
157 uc_expected = getCRC8CheckSum(pch_message, dw_length - 1, rm_referee::kCrc8Init);
158 return (uc_expected == pch_message[dw_length - 1]);
159 }
160
161 void appendCRC8CheckSum(unsigned char* pch_message, unsigned int dw_length)
162 {
163 unsigned char uc_crc;
164 if ((pch_message == nullptr) || (dw_length <= 2))
165 return;
166 uc_crc = getCRC8CheckSum((unsigned char*)pch_message, dw_length - 1, rm_referee::kCrc8Init);
167 pch_message[dw_length - 1] = uc_crc;
168 }
169
170 uint16_t getCRC16CheckSum(uint8_t* pch_message, uint32_t dw_length, uint16_t w_crc)
171 {
172 uint8_t chData;
173 if (pch_message == nullptr)
174 return 0xFFFF;
175 while (dw_length--)
176 {
177 chData = *pch_message++;
178 (w_crc) = (static_cast<uint16_t>(w_crc) >> 8) ^
179 rm_referee::wCRC_table[(static_cast<uint16_t>(w_crc) ^ static_cast<uint16_t>(chData)) & 0x00ff];
180 }
181 return w_crc;
182 }
183
184 uint32_t verifyCRC16CheckSum(uint8_t* pch_message, uint32_t dw_length)
185 {
186 uint16_t w_expected;
187 if ((pch_message == nullptr) || (dw_length <= 2))
188 return 0;
189 w_expected = getCRC16CheckSum(pch_message, dw_length - 2, rm_referee::kCrc16Init);
190 return ((w_expected & 0xff) == pch_message[dw_length - 2] &&
191 ((w_expected >> 8) & 0xff) == pch_message[dw_length - 1]);
192 }
193
194 void appendCRC16CheckSum(uint8_t* pch_message, uint32_t dw_length)
195 {
196 uint16_t wCRC;
197 if ((pch_message == nullptr) || (dw_length <= 2))
198 return;
199 wCRC = getCRC16CheckSum(static_cast<uint8_t*>(pch_message), dw_length - 2, rm_referee::kCrc16Init);
200 pch_message[dw_length - 2] = static_cast<uint8_t>((wCRC & 0x00ff));
201 pch_message[dw_length - 1] = static_cast<uint8_t>(((wCRC >> 8) & 0x00ff));
202 }
203};
204} // namespace rm_referee
Definition data.h:112
serial::Serial serial_
Definition data.h:114
int capacity_recent_mode_
Definition data.h:118
int client_id_
Definition data.h:116
uint8_t getCRC8CheckSum(unsigned char *pch_message, unsigned int dw_length, unsigned char uc_crc_8)
Definition data.h:141
std::string robot_color_
Definition data.h:119
void appendCRC8CheckSum(unsigned char *pch_message, unsigned int dw_length)
Definition data.h:161
void appendCRC16CheckSum(uint8_t *pch_message, uint32_t dw_length)
Definition data.h:194
uint32_t verifyCRC8CheckSum(unsigned char *pch_message, unsigned int dw_length)
Definition data.h:152
void initSerial()
Definition data.h:122
bool referee_data_is_online_
Definition data.h:120
int robot_id_
Definition data.h:117
uint16_t getCRC16CheckSum(uint8_t *pch_message, uint32_t dw_length, uint16_t w_crc)
Definition data.h:170
int capacity_expect_mode_
Definition data.h:118
uint32_t verifyCRC16CheckSum(uint8_t *pch_message, uint32_t dw_length)
Definition data.h:184
Definition data.h:101
const uint8_t kCrc8Init
Definition protocol.h:693
const uint8_t kCrc8Table[256]
Definition protocol.h:694
const uint16_t kCrc16Init
Definition protocol.h:710
const uint16_t wCRC_table[256]
Definition protocol.h:711
Definition data.h:103
double chassis_power
Definition data.h:104
double limit_power
Definition data.h:105
double cap_power
Definition data.h:107
bool is_online
Definition data.h:108
double buffer_power
Definition data.h:106