rm_control
Loading...
Searching...
No Matches
referee.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/5/17.
36//
37#pragma once
38
39#include <cstdint>
40#include <vector>
41#include <ros/ros.h>
42
45
46namespace rm_referee
47{
49{
50public:
51 Referee(ros::NodeHandle& nh) : referee_ui_(nh, base_), last_get_data_time_(ros::Time::now())
52 {
53 ROS_INFO("New serial protocol loading.");
54 // pub
55 game_robot_status_pub_ = nh.advertise<rm_msgs::GameRobotStatus>("game_robot_status", 1);
56 game_status_pub_ = nh.advertise<rm_msgs::GameStatus>("game_status", 1);
57 power_heat_data_pub_ = nh.advertise<rm_msgs::PowerHeatData>("power_heat_data", 1);
58 game_robot_hp_pub_ = nh.advertise<rm_msgs::GameRobotHp>("game_robot_hp", 1);
59 buff_pub_ = nh.advertise<rm_msgs::Buff>("robot_buff", 1);
60 event_data_pub_ = nh.advertise<rm_msgs::EventData>("event_data", 1);
61 dart_status_pub_ = nh.advertise<rm_msgs::DartStatus>("dart_status_data", 1);
63 nh.advertise<rm_msgs::IcraBuffDebuffZoneStatus>("icra_buff_debuff_zone_status_data", 1);
64 supply_projectile_action_pub_ = nh.advertise<rm_msgs::SupplyProjectileAction>("supply_projectile_action_data", 1);
65 dart_info_pub_ = nh.advertise<rm_msgs::DartInfo>("dart_info_data", 1);
66 robot_hurt_pub_ = nh.advertise<rm_msgs::RobotHurt>("robot_hurt_data", 1);
67 shoot_data_pub_ = nh.advertise<rm_msgs::ShootData>("shoot_data", 1);
68 bullet_allowance_pub_ = nh.advertise<rm_msgs::BulletAllowance>("bullet_allowance_data", 1);
69 rfid_status_pub_ = nh.advertise<rm_msgs::RfidStatus>("rfid_status_data", 1);
70 dart_client_cmd_pub_ = nh.advertise<rm_msgs::DartClientCmd>("dart_client_cmd_data", 1);
71 client_map_receive_pub_ = nh.advertise<rm_msgs::ClientMapReceiveData>("client_map_receive", 1);
72 robots_position_pub_ = nh.advertise<rm_msgs::RobotsPositionData>("robot_position", 1);
73 radar_mark_pub_ = nh.advertise<rm_msgs::RadarMarkData>("radar_mark", 1);
74 client_map_send_data_pub_ = nh.advertise<rm_msgs::ClientMapSendData>("client_map_send_data", 1);
75 game_robot_pos_pub_ = nh.advertise<rm_msgs::GameRobotPosData>("game_robot_pos", 1);
76 sentry_info_pub_ = nh.advertise<rm_msgs::SentryInfo>("sentry_info", 1);
77 radar_info_pub_ = nh.advertise<rm_msgs::RadarInfo>("radar_info", 1);
78 sentry_to_radar_pub_ = nh.advertise<rm_msgs::SentryAttackingTarget>("sentry_target_to_radar", 1);
79 radar_to_sentry_pub_ = nh.advertise<rm_msgs::RadarToSentry>("radar_to_sentry", 1);
81 nh.advertise<rm_msgs::RadarWirelessEnemyRobotPos>("radar_wireless_enemy_robot_pos", 1);
83 nh.advertise<rm_msgs::RadarWirelessEnemyRobotHp>("radar_wireless_enemy_robot_hp", 1);
85 nh.advertise<rm_msgs::RadarWirelessEnemyProjectileAllowance>("radar_wireless_enemy_projectile_allowance", 1);
87 nh.advertise<rm_msgs::RadarWirelessEnemyCoinAndFieldStatus>("radar_wireless_enemy_coin_and_field_status", 1);
89 nh.advertise<rm_msgs::RadarWirelessEnemyRobotBuff>("radar_wireless_enemy_robot_buff", 1);
91 nh.advertise<rm_msgs::RadarWirelessEnemyCallSign>("radar_wireless_enemy_call_sign", 1);
92
93 ros::NodeHandle power_management_nh = ros::NodeHandle(nh, "power_management");
95 power_management_nh.advertise<rm_msgs::PowerManagementSampleAndStatusData>("sample_and_status", 1);
97 power_management_nh.advertise<rm_msgs::PowerManagementInitializationExceptionData>("initialization_exception",
98 1);
100 power_management_nh.advertise<rm_msgs::PowerManagementSystemExceptionData>("system_exception", 1);
102 power_management_nh.advertise<rm_msgs::PowerManagementProcessStackOverflowData>("stack_overflow", 1);
104 power_management_nh.advertise<rm_msgs::PowerManagementUnknownExceptionData>("unknown_exception", 1);
105 // initSerial
107 };
108 void read();
110 {
111 rx_buffer_.clear();
112 rx_len_ = 0;
113 }
114
116 ros::Publisher game_status_pub_;
117 ros::Publisher power_heat_data_pub_;
118 ros::Publisher game_robot_hp_pub_;
119 ros::Publisher sentry_to_radar_pub_;
120 ros::Publisher event_data_pub_;
121 ros::Publisher dart_status_pub_;
122 ros::Publisher buff_pub_;
125 ros::Publisher dart_info_pub_;
126 ros::Publisher robot_hurt_pub_;
127 ros::Publisher shoot_data_pub_;
128 ros::Publisher bullet_allowance_pub_;
129 ros::Publisher rfid_status_pub_;
130 ros::Publisher dart_client_cmd_pub_;
132 ros::Publisher robots_position_pub_;
133 ros::Publisher radar_mark_pub_;
134 ros::Publisher game_robot_pos_pub_;
135 ros::Publisher sentry_info_pub_;
136 ros::Publisher radar_info_pub_;
138 ros::Publisher radar_to_sentry_pub_;
150
152 std::vector<uint8_t> rx_buffer_;
155
156private:
157 int unpack(uint8_t* rx_data);
158 void getRobotInfo();
159 void publishCapacityData();
160
161 ros::Time last_get_data_time_;
162 const int k_frame_length_ = 128, k_header_length_ = 5, k_cmd_id_length_ = 2, k_tail_length_ = 2;
163 const int k_unpack_buffer_length_ = 256;
164 uint8_t unpack_buffer_[256]{};
165};
166
167} // namespace rm_referee
Definition data.h:119
void initSerial()
Definition data.h:129
Definition referee_base.h:20
Definition referee.h:49
ros::Publisher power_heat_data_pub_
Definition referee.h:117
void read()
Definition referee.cpp:42
ros::Publisher radar_wireless_enemy_robot_hp_pub_
Definition referee.h:140
ros::Publisher dart_client_cmd_pub_
Definition referee.h:130
ros::Publisher game_robot_hp_pub_
Definition referee.h:118
ros::Publisher game_robot_pos_pub_
Definition referee.h:134
ros::Publisher robot_hurt_pub_
Definition referee.h:126
Referee(ros::NodeHandle &nh)
Definition referee.h:51
ros::Publisher radar_wireless_enemy_robot_buff_pub_
Definition referee.h:143
ros::Publisher dart_status_pub_
Definition referee.h:121
ros::Publisher buff_pub_
Definition referee.h:122
ros::Publisher radar_wireless_enemy_robot_pos_pub_
Definition referee.h:139
ros::Publisher power_management_system_exception_data_
Definition referee.h:147
ros::Publisher radar_mark_pub_
Definition referee.h:133
ros::Publisher game_robot_status_pub_
Definition referee.h:115
ros::Publisher event_data_pub_
Definition referee.h:120
ros::Publisher radar_info_pub_
Definition referee.h:136
int rx_len_
Definition referee.h:154
ros::Publisher robots_position_pub_
Definition referee.h:132
ros::Publisher game_status_pub_
Definition referee.h:116
ros::Publisher icra_buff_debuff_zone_status_pub_
Definition referee.h:123
ros::Publisher shoot_data_pub_
Definition referee.h:127
ros::Publisher dart_info_pub_
Definition referee.h:125
ros::Publisher bullet_allowance_pub_
Definition referee.h:128
ros::Publisher rfid_status_pub_
Definition referee.h:129
ros::Publisher sentry_to_radar_pub_
Definition referee.h:119
ros::Publisher radar_wireless_enemy_call_sign_pub_
Definition referee.h:144
ros::Publisher radar_to_sentry_pub_
Definition referee.h:138
rm_referee::RefereeBase referee_ui_
Definition referee.h:153
ros::Publisher power_management_initialization_exception_pub_
Definition referee.h:146
ros::Publisher power_management_sample_and_status_data_pub_
Definition referee.h:145
ros::Publisher radar_wireless_enemy_projectile_allowance_pub_
Definition referee.h:141
ros::Publisher sentry_info_pub_
Definition referee.h:135
ros::Publisher client_map_receive_pub_
Definition referee.h:131
std::vector< uint8_t > rx_buffer_
Definition referee.h:152
Base base_
Definition referee.h:151
ros::Publisher radar_wireless_enemy_coin_and_field_status_pub_
Definition referee.h:142
ros::Publisher power_management_unknown_exception_pub_
Definition referee.h:149
ros::Publisher power_management_process_stack_overflow_pub_
Definition referee.h:148
ros::Publisher client_map_send_data_pub_
Definition referee.h:137
void clearRxBuffer()
Definition referee.h:109
ros::Publisher supply_projectile_action_pub_
Definition referee.h:124
Definition data.h:108