Skip to content

Commit f9a6ae5

Browse files
committed
Merge remote-tracking branch 'origin/develop' into fix/robot_receiver
# Conflicts: # crane_robot_receiver/src/robot_receiver_node.cpp
2 parents 5c40017 + b514657 commit f9a6ae5

File tree

9 files changed

+111
-51
lines changed

9 files changed

+111
-51
lines changed

crane_local_planner/include/crane_local_planner/simple_planner.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class SimplePlanner
4444
for (auto & command : commands.robot_commands) {
4545
if ((not command.target_x.empty()) && (not command.target_y.empty())) {
4646
auto robot = world_model->getOurRobot(command.robot_id);
47+
command.current_pose.x = robot->pose.pos.x();
48+
command.current_pose.y = robot->pose.pos.y();
49+
command.current_pose.theta = robot->pose.theta;
4750
Point target;
4851
target << command.target_x.front(), command.target_y.front();
4952

crane_robot_receiver/src/robot_receiver_node.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
// license that can be found in the LICENSE file or at
55
// https://opensource.org/licenses/MIT.
66

7-
//#include <arpa/inet.h>
8-
//#include <netinet/in.h>
9-
//#include <stdio.h>
10-
//#include <stdlib.h>
11-
//#include <string.h>
12-
//#include <sys/socket.h>
13-
//#include <sys/types.h>
14-
//#include <time.h>
15-
16-
//#include <atomic>
177
#include <boost/asio.hpp>
188
#include <boost/thread.hpp>
199
#include <crane_msgs/msg/robot_feedback.hpp>
@@ -33,7 +23,7 @@ struct RobotInterfaceConfig
3323
auto makeConfig(uint8_t id) -> RobotInterfaceConfig
3424
{
3525
RobotInterfaceConfig config;
36-
config.ip = "224.5.20.10" + std::to_string(id);
26+
config.ip = "224.5.20." + std::to_string(id + 100);
3727
config.port = 50100 + id;
3828
return config;
3929
}
@@ -293,40 +283,5 @@ int main(int argc, char * argv[])
293283
exe.add_node(node->get_node_base_interface());
294284
exe.spin();
295285
rclcpp::shutdown();
296-
// try {
297-
// boost::asio::io_service io_service;
298-
//
299-
// // ローカルホストの指定したポートでUDPソケットを開く
300-
// udp::socket socket(io_service);
301-
// auto listen_address = boost::asio::ip::address::from_string("224.5.20.100");
302-
// boost::asio::ip::udp::endpoint listen_endpoint(listen_address, 50100);
303-
//
304-
// socket.open(listen_endpoint.protocol());
305-
//
306-
// if (socket.is_open()) {
307-
// std::cout << "socket opened" << std::endl;
308-
// } else {
309-
// std::cout << "socket not opened" << std::endl;
310-
// }
311-
// socket.set_option(boost::asio::ip::udp::socket::reuse_address(true));
312-
// socket.bind(listen_endpoint);
313-
//
314-
// // Join the multicast group.
315-
// socket.set_option(boost::asio::ip::multicast::join_group(listen_address));
316-
//
317-
//
318-
// std::cout << "joined multicast group" << std::endl;
319-
//
320-
// for (;;) { // 無限ループでパケットを待ち受ける
321-
// char data[1024];
322-
// udp::endpoint sender_endpoint;
323-
// size_t length = socket.receive_from(boost::asio::buffer(data), sender_endpoint);
324-
//
325-
// std::cout << "Received packet: " << std::string(data, length) << std::endl;
326-
// }
327-
// } catch (std::exception & e) {
328-
// std::cerr << "Exception: " << e.what() << "\n";
329-
// }
330-
331286
return 0;
332287
}

crane_sender/include/crane_sender/sim_sender.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class SimSenderComponent : public SenderBase
3535

3636
void sendCommands(const crane_msgs::msg::RobotCommands & msg) override
3737
{
38+
if (checkNan(msg)) {
39+
return;
40+
}
41+
3842
const double MAX_KICK_SPEED = 8.0; // m/s
3943
robocup_ssl_msgs::msg::Commands commands;
4044
commands.isteamyellow = msg.is_yellow;
@@ -75,6 +79,34 @@ class SimSenderComponent : public SenderBase
7579
pub_commands->publish(commands);
7680
}
7781

82+
bool checkNan(const crane_msgs::msg::RobotCommands & msg)
83+
{
84+
bool is_nan = false;
85+
for (const auto & command : msg.robot_commands) {
86+
if (std::isnan(command.target_velocity.x)) {
87+
std::cout << "id: " << command.robot_id << " target_velocity.x is nan" << std::endl;
88+
is_nan = true;
89+
}
90+
if (std::isnan(command.target_velocity.y)) {
91+
std::cout << "id: " << command.robot_id << "target_velocity.y is nan" << std::endl;
92+
is_nan = true;
93+
}
94+
if (std::isnan(command.target_velocity.theta)) {
95+
std::cout << "id: " << command.robot_id << "target_velocity.theta is nan" << std::endl;
96+
is_nan = true;
97+
}
98+
if (std::isnan(command.kick_power)) {
99+
std::cout << "id: " << command.robot_id << "kick_power is nan" << std::endl;
100+
is_nan = true;
101+
}
102+
if (std::isnan(command.dribble_power)) {
103+
std::cout << "id: " << command.robot_id << "dribble_power is nan" << std::endl;
104+
is_nan = true;
105+
}
106+
}
107+
return is_nan;
108+
}
109+
78110
// void send_replacement(const consai2r2_msgs::msg::Replacements::SharedPtr msg) const
79111
// {
80112
//

crane_sender/src/real_sender_node.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int check;
3333
int sock;
3434
struct sockaddr_in addr;
3535

36-
const char * opt = "enx00e04c696e2b";
36+
const char * opt = "enp4s0";
3737

3838
namespace crane
3939
{
@@ -132,8 +132,13 @@ class RealSenderNode : public SenderBase
132132

133133
// Vision角度
134134
// -pi ~ pi -> 0 ~ 32767 ~ 65534
135+
packet.VISION_GLOBAL_X = command.current_pose.x;
136+
packet.VISION_GLOBAL_Y = command.current_pose.y;
135137
packet.VISION_GLOBAL_THETA = command.current_pose.theta;
136138

139+
packet.BALL_GLOBAL_X = command.current_ball_x;
140+
packet.BALL_GLOBAL_Y = command.current_ball_y;
141+
137142
// 目標座標
138143
packet.TARGET_GLOBAL_X = [&]() -> float {
139144
if (not command.target_x.empty()) {

docs/vision.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ Thread0の「ImageCapture/CaptureControl」の「start capture」
6060
- Number of Line Segments
6161
- Number of Arcs
6262

63+
※ロボットがオフセットしているように感じたら...
64+
- 「Global/Robot Detection/BlueTeam」などからチームを確認
65+
- 「Global/Robot Detection/Teams/ER-Force」などからロボットの高さを調整
66+
ロボットの高さをゼロにするとオフセットがなくなることがある
67+
68+
6369
## 色の設定
6470

6571
右側の「Auto Color Calibration」タブを使って設定する

scripts/camera.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ device_id=0
33
# manual: 1
44
v4l2-ctl -d $device_id -c exposure_auto=1
55
#v4l2-ctl -d $device_id -c exposure_time_absolute=120
6-
v4l2-ctl -d $device_id -c exposure_absolute=170
6+
v4l2-ctl -d $device_id -c exposure_absolute=300
77

88
#v4l2-ctl -d $device_id -c focus_automatic_continuous=0
99
v4l2-ctl -d $device_id -c focus_auto=0
1010
v4l2-ctl -d $device_id -c focus_absolute=0
1111

1212

1313

14-
v4l2-ctl -d $device_id -c brightness=120
14+
v4l2-ctl -d $device_id -c brightness=170
1515
v4l2-ctl -d $device_id -c sharpness=400

scripts/measure_laytency.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import math
2+
import time
3+
from rclpy.node import Node
4+
import rclpy
5+
from robocup_ssl_msgs.msg import TrackedFrame, RobotId
6+
from crane_msgs.msg import RobotCommands
7+
8+
class MeasureLatency(Node):
9+
def __init__(self):
10+
super().__init__('measure_latency')
11+
self.detection_sub = self.create_subscription(TrackedFrame, '/detection_tracked', self.detection_callback, 10)
12+
self.command_sub = self.create_subscription(RobotCommands, '/robot_commands',self.command_callback, 10)
13+
self.robot_id = 0
14+
self.move_start_time = None
15+
self.pre_vel = 0.0
16+
self.VEL_THRESHOLD = 0.1
17+
# self.is_waiting_for_moving = False
18+
19+
def detection_callback(self, msg: TrackedFrame):
20+
# print("detection_callback")
21+
if self.move_start_time is not None:
22+
robot = None
23+
for r in msg.robots:
24+
if r.robot_id.id == self.robot_id and r.robot_id.team_color == RobotId.TEAM_COLOR_BLUE:
25+
if len(r.vel) > 0:
26+
vel_2d = r.vel[0]
27+
vel = math.sqrt(vel_2d.x ** 2 + vel_2d.y ** 2)
28+
if vel > self.VEL_THRESHOLD:
29+
self.get_logger().info('start detected! latency: {}'.format((time.time() - self.move_start_time) * 1000))
30+
self.move_start_time = None
31+
break
32+
33+
34+
def command_callback(self, msg):
35+
# print("command_callback")
36+
robot = None
37+
for command in msg.robot_commands:
38+
if command.robot_id == self.robot_id:
39+
robot = command
40+
break
41+
if robot is None:
42+
return
43+
# get target velocity size
44+
vel = math.sqrt(robot.target_velocity.x ** 2 + robot.target_velocity.y ** 2)
45+
# print(vel)
46+
if self.pre_vel < self.VEL_THRESHOLD and vel > self.VEL_THRESHOLD and self.move_start_time is None:
47+
print("start moving")
48+
self.move_start_time = time.time()
49+
self.pre_vel = vel
50+
51+
52+
if __name__ == '__main__':
53+
rclpy.init()
54+
node = MeasureLatency()
55+
rclpy.spin(node)
56+
node.destroy_node()
57+
rclpy.shutdown()

scripts/network.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
robot_wifi_device="enp4s0"
22
# Visionパケットをロボットに送信しない
3-
sudo iptables -A OUTPUT -o $robot_wifi_device -d 224.5.23.2 -j DROP
3+
sudo iptables -A FORWARD -o $robot_wifi_device -d 224.5.23.2 -j DROP
44
# Refereeパケットをロボットに送信しない
5-
sudo iptables -A OUTPUT -o $robot_wifi_device -d 224.5.23.1 -j DROP
5+
sudo iptables -A FORWARD -o $robot_wifi_device -d 224.5.23.1 -j DROP
66

session/crane_planner_plugins/include/crane_planner_plugins/goalie_planner.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ class GoaliePlanner : public PlannerBase
130130
[[fallthrough]];
131131
case crane_msgs::msg::PlaySituation::THEIR_PENALTY_START:
132132
inplay(target, false);
133+
break;
133134
default:
134135
inplay(target, true);
136+
break;
135137
}
136138

137139
control_targets.emplace_back(target.getMsg());

0 commit comments

Comments
 (0)