Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoRefのお試しをやりながらバグを潰していく #163

Merged
merged 24 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crane_msgs/msg/control/RobotCommands.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
std_msgs/Header header
bool on_positive_half
bool is_yellow
RobotCommand[] robot_commands
3 changes: 1 addition & 2 deletions crane_msgs/msg/world_model/WorldModel.msg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
std_msgs/Header header

bool on_positive_half
bool is_yellow

uint8 our_goalie_id
Expand All @@ -14,6 +15,4 @@ BallInfo ball_info
RobotInfoOurs[] robot_info_ours
RobotInfoTheirs[] robot_info_theirs

geometry_msgs/Point ball_placement_target

PlaySituation play_situation
5 changes: 5 additions & 0 deletions crane_play_switcher/src/play_switcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
// TODO(HansRobo): robocup_ssl_msgs/msg/Refereeをもう少しわかりやすい形式にする必要あり
play_situation_msg.stage = msg.stage;

if (latest_raw_referee_command != msg.command) {

Check warning on line 75 in crane_play_switcher/src/play_switcher.cpp

View workflow job for this annotation

GitHub Actions / BuildAndRun (humble)

comparison of integer expressions of different signedness: ‘int’ and ‘const _command_type’ {aka ‘const unsigned int’} [-Wsign-compare]
//-----------------------------------//
// NORMAL_START
//-----------------------------------//
Expand Down Expand Up @@ -170,7 +170,7 @@
// コマンドが更新されているかを調べる
if (
next_play_situation != std::nullopt &&
next_play_situation.value() != play_situation_msg.command) {

Check warning on line 173 in crane_play_switcher/src/play_switcher.cpp

View workflow job for this annotation

GitHub Actions / BuildAndRun (humble)

comparison of integer expressions of different signedness: ‘int’ and ‘crane_msgs::msg::PlaySituation_<std::allocator<void> >::_command_type’ {aka ‘unsigned int’} [-Wsign-compare]
play_situation_msg.command = next_play_situation.value();
play_situation_msg.reason_text = inplay_command_info.reason;
RCLCPP_INFO(get_logger(), "---");
Expand All @@ -187,6 +187,11 @@
last_command_changed_state.stamp = now();
last_command_changed_state.ball_position = world_model->ball.pos;

if (msg.designated_position.size() > 0) {
play_situation_msg.placement_position.x = msg.designated_position[0].x;
play_situation_msg.placement_position.y = msg.designated_position[0].y;
}

// パブリッシュはコマンド更新時のみ
play_situation_pub->publish(play_situation_msg);
}
Expand Down
2 changes: 1 addition & 1 deletion crane_sender/src/ibis_sender_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class IbisSenderNode : public SenderBase

for (auto command : msg.robot_commands) {
//
if (msg.is_yellow) {
if (not msg.on_positive_half) {
command.target_velocity.x *= -1;
command.target_velocity.y *= -1;
command.target_velocity.theta *= -1;
Expand Down
1 change: 1 addition & 0 deletions crane_simple_ai/include/crane_commander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ROSNode : public rclcpp::Node
crane_msgs::msg::RobotCommands msg;
msg.header = world_model->getMsg().header;
msg.is_yellow = world_model->isYellow();
msg.on_positive_half = world_model->onPositiveHalf();
msg.robot_commands.push_back(latest_msg);
publisher_robot_commands->publish(msg);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class WorldModelPublisherComponent : public rclcpp::Node

Color their_color;

bool on_positive_half;

uint8_t our_goalie_id, their_goalie_id;

uint8_t max_id;
Expand Down
31 changes: 17 additions & 14 deletions crane_world_model_publisher/src/world_model_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ WorldModelPublisherComponent::WorldModelPublisherComponent(const rclcpp::NodeOpt
declare_parameter("team_name", "ibis-ssl");
team_name = get_parameter("team_name").as_string();

declare_parameter("initial_team_color", "BLUE");
auto initial_team_color = get_parameter("initial_team_color").as_string();
if (initial_team_color == "BLUE") {
our_color = Color::BLUE;
their_color = Color::YELLOW;
} else {
our_color = Color::YELLOW;
their_color = Color::BLUE;
}

sub_referee = this->create_subscription<robocup_ssl_msgs::msg::Referee>(
"/referee", 1, [this](const robocup_ssl_msgs::msg::Referee & msg) {
if (msg.yellow.name == team_name) {
Expand All @@ -46,12 +56,18 @@ WorldModelPublisherComponent::WorldModelPublisherComponent(const rclcpp::NodeOpt
their_color = Color::BLUE;
our_goalie_id = msg.yellow.goalkeeper;
their_goalie_id = msg.blue.goalkeeper;
if (not msg.blue_team_on_positive_half.empty()) {
on_positive_half = not msg.blue_team_on_positive_half[0];
}
} else if (msg.blue.name == team_name) {
// BLUE
our_color = Color::BLUE;
their_color = Color::YELLOW;
our_goalie_id = msg.blue.goalkeeper;
their_goalie_id = msg.yellow.goalkeeper;
if (not msg.blue_team_on_positive_half.empty()) {
on_positive_half = msg.blue_team_on_positive_half[0];
}
} else {
std::stringstream what;
what << "Cannot find our team name, " << team_name << " in referee message. ";
Expand All @@ -64,17 +80,6 @@ WorldModelPublisherComponent::WorldModelPublisherComponent(const rclcpp::NodeOpt
ball_placement_target_y = msg.designated_position.front().y / 1000.;
}
});

declare_parameter("initial_team_color", "BLUE");
auto initial_team_color = get_parameter("initial_team_color").as_string();
if (initial_team_color == "BLUE") {
our_color = Color::BLUE;
their_color = Color::YELLOW;

} else {
our_color = Color::YELLOW;
their_color = Color::BLUE;
}
}

void WorldModelPublisherComponent::visionDetectionsCallback(
Expand Down Expand Up @@ -164,6 +169,7 @@ void WorldModelPublisherComponent::publishWorldModel()
crane_msgs::msg::WorldModel wm;

wm.is_yellow = (our_color == Color::YELLOW);
wm.on_positive_half = on_positive_half;
wm.ball_info = ball_info;

updateBallContact();
Expand Down Expand Up @@ -196,9 +202,6 @@ void WorldModelPublisherComponent::publishWorldModel()
wm.goal_size.x = goal_h;
wm.goal_size.y = goal_w;

wm.ball_placement_target.x = ball_placement_target_x;
wm.ball_placement_target.y = ball_placement_target_y;

wm.our_goalie_id = our_goalie_id;
wm.their_goalie_id = their_goalie_id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class PlannerBase
status = latest_status;
crane_msgs::msg::RobotCommands msg;
msg.is_yellow = world_model->isYellow();
for (auto command : robot_commands) {
msg.on_positive_half = world_model->onPositiveHalf();
for (const auto & command : robot_commands) {
msg.robot_commands.emplace_back(command);
}
return msg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ SessionControllerComponent::SessionControllerComponent(const rclcpp::NodeOptions
world_model->addCallback([this]() {
crane_msgs::msg::RobotCommands msg;
msg.header = world_model->getMsg().header;
msg.on_positive_half = world_model->onPositiveHalf();
msg.is_yellow = world_model->isYellow();
for (const auto & planner : available_planners) {
auto commands_msg = planner->getRobotCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ struct WorldModelWrapper
defense_area_size << world_model.defense_area_size.x, world_model.defense_area_size.y;

goal_size << world_model.goal_size.x, world_model.goal_size.y;
goal << (isYellow() ? field_size.x() * 0.5 : -field_size.x() * 0.5), 0.;
goal << getOurSideSign() * field_size.x() * 0.5, 0.;

if (goal.x() > 0) {
if (onPositiveHalf()) {
ours.defense_area.max_corner() << goal.x(), goal.y() + world_model.defense_area_size.y / 2.;
ours.defense_area.min_corner() << goal.x() - world_model.defense_area_size.x,
goal.y() - world_model.defense_area_size.y / 2.;
Expand All @@ -274,19 +274,14 @@ struct WorldModelWrapper
theirs.defense_area.min_corner()
<< std::min(-ours.defense_area.max_corner().x(), -ours.defense_area.min_corner().x()),
ours.defense_area.min_corner().y();

if (
world_model.play_situation.command == crane_msgs::msg::PlaySituation::OUR_BALL_PLACEMENT or
world_model.play_situation.command == crane_msgs::msg::PlaySituation::THEIR_BALL_PLACEMENT) {
*ball_placement_target << world_model.ball_placement_target.x,
world_model.ball_placement_target.y;
} else {
ball_placement_target = std::nullopt;
}
}

[[nodiscard]] const crane_msgs::msg::WorldModel & getMsg() const { return latest_msg; }

[[nodiscard]] bool onPositiveHalf() const { return (latest_msg.on_positive_half); }

[[nodiscard]] double getOurSideSign() const { return onPositiveHalf() ? 1.0 : -1.0; }

[[nodiscard]] bool isYellow() const { return (latest_msg.is_yellow); }

[[nodiscard]] bool hasUpdated() const { return has_updated; }
Expand Down Expand Up @@ -456,16 +451,24 @@ struct WorldModelWrapper

[[nodiscard]] std::optional<Point> getBallPlacementTarget() const
{
return ball_placement_target;
if (
play_situation.getSituationCommandID() ==
crane_msgs::msg::PlaySituation::OUR_BALL_PLACEMENT or
play_situation.getSituationCommandID() ==
crane_msgs::msg::PlaySituation::THEIR_BALL_PLACEMENT) {
return play_situation.placement_position;
} else {
return std::nullopt;
}
}

// rule 8.4.3
[[nodiscard]] std::optional<Capsule> getBallPlacementArea() const
{
if (ball_placement_target) {
if (auto target = getBallPlacementTarget()) {
Capsule area;
area.segment.first = ball.pos;
area.segment.second = ball_placement_target.value();
area.segment.second = target.value();
area.radius = 0.5;
return area;
} else {
Expand Down
2 changes: 1 addition & 1 deletion utility/crane_msg_wrappers/src/play_situation_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ auto PlaySituationWrapper::update(const crane_msgs::msg::PlaySituation & msg) ->
situation_command.id = msg.command;
situation_command.text = situation_command_map[msg.command];

placement_position << msg.placement_position.x, msg.placement_position.y;
placement_position << msg.placement_position.x / 1000., msg.placement_position.y / 1000.;
}

auto PlaySituationWrapper::getRefereeCommandText(uint32_t id) -> std::string
Expand Down
Loading