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 <array>
40#include <cstdint>
41#include <vector>
42#include <ros/ros.h>
43
46
47namespace rm_referee
48{
50{
51public:
52 Referee(ros::NodeHandle& nh) : referee_ui_(nh, base_), last_get_data_time_(ros::Time::now())
53 {
54 ROS_INFO("New serial protocol loading.");
55 // pub
56 game_robot_status_pub_ = nh.advertise<rm_msgs::GameRobotStatus>("game_robot_status", 1);
57 game_status_pub_ = nh.advertise<rm_msgs::GameStatus>("game_status", 1);
58 power_heat_data_pub_ = nh.advertise<rm_msgs::PowerHeatData>("power_heat_data", 1);
59 game_robot_hp_pub_ = nh.advertise<rm_msgs::GameRobotHp>("game_robot_hp", 1);
60 buff_pub_ = nh.advertise<rm_msgs::Buff>("robot_buff", 1);
61 event_data_pub_ = nh.advertise<rm_msgs::EventData>("event_data", 1);
62 dart_status_pub_ = nh.advertise<rm_msgs::DartStatus>("dart_status_data", 1);
64 nh.advertise<rm_msgs::IcraBuffDebuffZoneStatus>("icra_buff_debuff_zone_status_data", 1);
65 supply_projectile_action_pub_ = nh.advertise<rm_msgs::SupplyProjectileAction>("supply_projectile_action_data", 1);
66 dart_info_pub_ = nh.advertise<rm_msgs::DartInfo>("dart_info_data", 1);
67 robot_hurt_pub_ = nh.advertise<rm_msgs::RobotHurt>("robot_hurt_data", 1);
68 shoot_data_pub_ = nh.advertise<rm_msgs::ShootData>("shoot_data", 1);
69 bullet_allowance_pub_ = nh.advertise<rm_msgs::BulletAllowance>("bullet_allowance_data", 1);
70 rfid_status_pub_ = nh.advertise<rm_msgs::RfidStatus>("rfid_status_data", 1);
71 dart_client_cmd_pub_ = nh.advertise<rm_msgs::DartClientCmd>("dart_client_cmd_data", 1);
72 client_map_receive_pub_ = nh.advertise<rm_msgs::ClientMapReceiveData>("client_map_receive", 1);
73 robots_position_pub_ = nh.advertise<rm_msgs::RobotsPositionData>("robot_position", 1);
74 radar_mark_pub_ = nh.advertise<rm_msgs::RadarMarkData>("radar_mark", 1);
75 client_map_send_data_pub_ = nh.advertise<rm_msgs::ClientMapSendData>("client_map_send_data", 1);
76 game_robot_pos_pub_ = nh.advertise<rm_msgs::GameRobotPosData>("game_robot_pos", 1);
77 sentry_info_pub_ = nh.advertise<rm_msgs::SentryInfo>("sentry_info", 1);
78 radar_info_pub_ = nh.advertise<rm_msgs::RadarInfo>("radar_info", 1);
79 sentry_to_radar_pub_ = nh.advertise<rm_msgs::SentryAttackingTarget>("sentry_target_to_radar", 1);
80 radar_to_sentry_pub_ = nh.advertise<rm_msgs::RadarToSentry>("radar_to_sentry", 1);
81
82 ros::NodeHandle power_management_nh = ros::NodeHandle(nh, "power_management");
84 power_management_nh.advertise<rm_msgs::PowerManagementSampleAndStatusData>("sample_and_status", 1);
86 power_management_nh.advertise<rm_msgs::PowerManagementInitializationExceptionData>("initialization_exception",
87 1);
89 power_management_nh.advertise<rm_msgs::PowerManagementSystemExceptionData>("system_exception", 1);
91 power_management_nh.advertise<rm_msgs::PowerManagementProcessStackOverflowData>("stack_overflow", 1);
93 power_management_nh.advertise<rm_msgs::PowerManagementUnknownExceptionData>("unknown_exception", 1);
94 // initSerial
95 base_.initSerial(nh);
96 };
97 void read();
98
99 ros::Publisher game_robot_status_pub_;
100 ros::Publisher game_status_pub_;
101 ros::Publisher power_heat_data_pub_;
102 ros::Publisher game_robot_hp_pub_;
103 ros::Publisher sentry_to_radar_pub_;
104 ros::Publisher event_data_pub_;
105 ros::Publisher dart_status_pub_;
106 ros::Publisher buff_pub_;
109 ros::Publisher dart_info_pub_;
110 ros::Publisher robot_hurt_pub_;
111 ros::Publisher shoot_data_pub_;
112 ros::Publisher bullet_allowance_pub_;
113 ros::Publisher rfid_status_pub_;
114 ros::Publisher dart_client_cmd_pub_;
116 ros::Publisher robots_position_pub_;
117 ros::Publisher radar_mark_pub_;
118 ros::Publisher game_robot_pos_pub_;
119 ros::Publisher sentry_info_pub_;
120 ros::Publisher radar_info_pub_;
122 ros::Publisher radar_to_sentry_pub_;
128
131
132private:
133 static constexpr int k_frame_length_ = 128;
134 static constexpr int k_header_length_ = 5;
135 static constexpr int k_cmd_id_length_ = 2;
136 static constexpr int k_tail_length_ = 2;
137 static constexpr int k_unpack_buffer_length_ = 256;
138
139 struct SerialRxState
140 {
141 std::vector<uint8_t> rx_buffer;
142 int rx_len = 0;
143 std::array<uint8_t, k_unpack_buffer_length_> unpack_buffer{};
144 };
145
146 bool handlePortBytes(size_t port_index, const std::vector<uint8_t>& data, const ros::Time& stamp);
147 void clearRxBuffer(size_t port_index);
148 void resetPortState(size_t port_index);
149 int unpack(size_t port_index, uint8_t* rx_data, int rx_data_len, const ros::Time& stamp);
150 void getRobotInfo();
151 void publishCapacityData();
152
153 ros::Time last_get_data_time_;
154 const ros::Duration port_freshness_timeout_{ 0.1 };
155 std::array<SerialRxState, Base::kMaxSerialPorts> rx_states_{};
156};
157
158} // namespace rm_referee
Definition data.h:115
void initSerial(ros::NodeHandle &nh)
Definition data.h:139
Definition referee_base.h:20
Definition referee.h:50
ros::Publisher power_heat_data_pub_
Definition referee.h:101
void read()
Definition referee.cpp:106
ros::Publisher dart_client_cmd_pub_
Definition referee.h:114
ros::Publisher game_robot_hp_pub_
Definition referee.h:102
ros::Publisher game_robot_pos_pub_
Definition referee.h:118
ros::Publisher robot_hurt_pub_
Definition referee.h:110
Referee(ros::NodeHandle &nh)
Definition referee.h:52
ros::Publisher dart_status_pub_
Definition referee.h:105
ros::Publisher buff_pub_
Definition referee.h:106
ros::Publisher power_management_system_exception_data_
Definition referee.h:125
ros::Publisher radar_mark_pub_
Definition referee.h:117
ros::Publisher game_robot_status_pub_
Definition referee.h:99
ros::Publisher event_data_pub_
Definition referee.h:104
ros::Publisher radar_info_pub_
Definition referee.h:120
ros::Publisher robots_position_pub_
Definition referee.h:116
ros::Publisher game_status_pub_
Definition referee.h:100
ros::Publisher icra_buff_debuff_zone_status_pub_
Definition referee.h:107
ros::Publisher shoot_data_pub_
Definition referee.h:111
ros::Publisher dart_info_pub_
Definition referee.h:109
ros::Publisher bullet_allowance_pub_
Definition referee.h:112
ros::Publisher rfid_status_pub_
Definition referee.h:113
ros::Publisher sentry_to_radar_pub_
Definition referee.h:103
ros::Publisher radar_to_sentry_pub_
Definition referee.h:122
rm_referee::RefereeBase referee_ui_
Definition referee.h:130
ros::Publisher power_management_initialization_exception_pub_
Definition referee.h:124
ros::Publisher power_management_sample_and_status_data_pub_
Definition referee.h:123
ros::Publisher sentry_info_pub_
Definition referee.h:119
ros::Publisher client_map_receive_pub_
Definition referee.h:115
Base base_
Definition referee.h:129
ros::Publisher power_management_unknown_exception_pub_
Definition referee.h:127
ros::Publisher power_management_process_stack_overflow_pub_
Definition referee.h:126
ros::Publisher client_map_send_data_pub_
Definition referee.h:121
ros::Publisher supply_projectile_action_pub_
Definition referee.h:108
Definition data.h:104