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

Position Override created to allow position testing #2263

Merged
merged 25 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f381c84
Added UI
jvogt23 Jun 2, 2024
c67d840
Partial copy of main_window changes
jvogt23 Jun 2, 2024
0340e89
partial message addition
jvogt23 Jun 2, 2024
c44ad84
OverridePosition.msg
jvogt23 Jun 25, 2024
5b17f1f
Merge branch 'ros2' into test-mode
jvogt23 Jun 25, 2024
dfa6e38
Set up working override positions, needs refactor
jvogt23 Jun 26, 2024
8d2c07b
Working position override created
jvogt23 Jul 1, 2024
0036b6e
Fix bug where changing the goalie num to a robot that is not auto doe…
jvogt23 Jul 1, 2024
907aa11
Fixes based on code review
jvogt23 Oct 15, 2024
9de5737
force test rerun
jvogt23 Nov 23, 2024
a501d4e
Fix Code Style On test-mode (#2264)
github-actions[bot] Nov 23, 2024
c84a54a
Resolving final conversations for review
jvogt23 Dec 9, 2024
2673072
Merge branch 'test-mode' of github.com:RoboJackets/robocup-software i…
jvogt23 Dec 9, 2024
cd5bffd
Fix Code Style On test-mode (#2315)
github-actions[bot] Dec 9, 2024
d86225e
Merge branch 'ros2' into test-mode
jvogt23 Jan 20, 2025
3175848
Removed LENGTH enum value
jvogt23 Jan 20, 2025
7e4c95d
asdf
jvogt23 Jan 20, 2025
bd5bff0
Update soccer/src/soccer/strategy/agent/position/robot_factory_positi…
jvogt23 Jan 27, 2025
a217a0e
Fix braces on if statement
jvogt23 Jan 27, 2025
d476111
Style fixes
jvogt23 Jan 27, 2025
5ca24d4
Made different topic for each robot id's overriding position
jvogt23 Jan 27, 2025
4030e05
FixStyle on changes
jvogt23 Jan 27, 2025
18ac7b9
Rename topic to fit convention
jvogt23 Jan 28, 2025
b150791
Fix naming conventions and comments
jvogt23 Jan 29, 2025
64cbc9d
Last thing
jvogt23 Jan 29, 2025
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 rj_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ rosidl_generate_interfaces(
msg/TeamInfo.msg
msg/Trajectory.msg
msg/WorldState.msg
msg/OverridePosition.msg

# Communication
msg/AgentRequest.msg
Expand Down
5 changes: 5 additions & 0 deletions rj_msgs/msg/OverridePosition.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contains unsigned int overriding_position - the position
# to set for that ID, based on the enum OverridingPositions,
# which is contained in soccer/src/soccer/strategy/agent/position/overriding_positions.hpp

uint32 overriding_position
27 changes: 27 additions & 0 deletions soccer/src/soccer/strategy/agent/position/overriding_positions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <map>
#include <string>
#include <vector>

namespace Strategy {
/*
OverridingPositions refers to the positions that can be manually set in the UI.
Normally, all robots are set to Auto. If you want to add a new position, add a new value
to this enum, add a string to the overriding_position_labels vector in
main_window.hpp, and add a case to the set_position_override_if_requested method in
RobotFactoryPosition.
*/
enum OverridingPositions {
AUTO,
OFFENSE,
DEFENSE,
FREE_KICKER,
PENALTY_PLAYER,
PENALTY_NON_KICKER,
SOLO_OFFENSE,
SMART_IDLE,
ZONER,
IDLE,
};

} // namespace Strategy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
} else {
current_position_ = std::make_unique<Defense>(robot_id_);
}

std::string node_name{"robot_factory_position_"};
_node = std::make_shared<rclcpp::Node>(node_name.append(std::to_string(robot_id_)));
override_play_sub_ = _node->create_subscription<rj_msgs::msg::OverridePosition>(
"override_position/robot_" + std::to_string(robot_id_), 1,
[this](const rj_msgs::msg::OverridePosition::SharedPtr msg) { test_play_callback(msg); });

Check warning on line 23 in soccer/src/soccer/strategy/agent/position/robot_factory_position.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

the const qualified parameter 'msg' is copied for each invocation; consider making it a reference
_executor.add_node(_node);
_executor_thread = std::thread([this]() { _executor.spin(); });
}

std::optional<RobotIntent> RobotFactoryPosition::derived_get_task([
Expand Down Expand Up @@ -118,7 +126,12 @@
}
}

void RobotFactoryPosition::update_position() {

Check warning on line 129 in soccer/src/soccer/strategy/agent/position/robot_factory_position.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

function 'update_position' has cognitive complexity of 42 (threshold 25)
bool manual_position_set = set_position_override_if_requested();
if (manual_position_set) {
return;
}

switch (current_play_state_.state()) {
case PlayState::State::Playing: {
// We just became regular playing.
Expand Down Expand Up @@ -338,4 +351,58 @@
return current_position_->get_current_state();
}

void RobotFactoryPosition::test_play_callback(
const rj_msgs::msg::OverridePosition::SharedPtr message) {

Check warning on line 355 in soccer/src/soccer/strategy/agent/position/robot_factory_position.cpp

View workflow job for this annotation

GitHub Actions / build-and-test

the const qualified parameter 'message' is copied for each invocation; consider making it a reference
override_play_position_ =
static_cast<Strategy::OverridingPositions>(message->overriding_position);
}

/**
* Checks override_play_position_, which automatically updates when an override is set.
* If it is anything but auto, set the current position to that position and return true.
*/
bool RobotFactoryPosition::set_position_override_if_requested() {
switch (override_play_position_) {
case Strategy::OverridingPositions::OFFENSE: {
set_current_position<Offense>();
return true;
}
case Strategy::OverridingPositions::DEFENSE: {
set_current_position<Defense>();
return true;
}
case Strategy::OverridingPositions::FREE_KICKER: {
set_current_position<FreeKicker>();
return true;
}
case Strategy::OverridingPositions::PENALTY_PLAYER: {
set_current_position<PenaltyPlayer>();
return true;
}
case Strategy::OverridingPositions::PENALTY_NON_KICKER: {
set_current_position<PenaltyNonKicker>();
return true;
}
case Strategy::OverridingPositions::SMART_IDLE: {
set_current_position<SmartIdle>();
return true;
}
case Strategy::OverridingPositions::SOLO_OFFENSE: {
set_current_position<SoloOffense>();
return true;
}
case Strategy::OverridingPositions::ZONER: {
set_current_position<Zoner>();
return true;
}
case Strategy::OverridingPositions::IDLE: {
set_current_position<Idle>();
return true;
}
default: {
return false;
}
}
}

} // namespace strategy
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
#include <rj_msgs/action/robot_move.hpp>

#include "game_state.hpp"
#include "overriding_positions.hpp"
#include "planning/instant.hpp"
#include "position.hpp"
#include "rj_common/field_dimensions.hpp"
#include "rj_common/time.hpp"
#include "rj_constants/constants.hpp"
#include "rj_geometry/geometry_conversions.hpp"
#include "rj_msgs/msg/override_position.hpp"
#include "strategy/agent/position/defense.hpp"
#include "strategy/agent/position/free_kicker.hpp"
#include "strategy/agent/position/goal_kicker.hpp"
#include "strategy/agent/position/goalie.hpp"
#include "strategy/agent/position/line.hpp"
#include "strategy/agent/position/offense.hpp"
#include "strategy/agent/position/overriding_positions.hpp"
#include "strategy/agent/position/penalty_non_kicker.hpp"
#include "strategy/agent/position/penalty_player.hpp"
#include "strategy/agent/position/pivot_test.hpp"
Expand Down Expand Up @@ -110,6 +113,14 @@
private:
std::unique_ptr<Position> current_position_;

// subscription for test mode - Allows position overriding
rclcpp::Subscription<rj_msgs::msg::OverridePosition>::SharedPtr override_play_sub_;
rclcpp::executors::SingleThreadedExecutor _executor;

Check warning on line 118 in soccer/src/soccer/strategy/agent/position/robot_factory_position.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

invalid case style for private member '_executor'
std::thread _executor_thread;

Check warning on line 119 in soccer/src/soccer/strategy/agent/position/robot_factory_position.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

invalid case style for private member '_executor_thread'
void test_play_callback(const rj_msgs::msg::OverridePosition::SharedPtr message);

Check warning on line 120 in soccer/src/soccer/strategy/agent/position/robot_factory_position.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

parameter 'message' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions
Strategy::OverridingPositions override_play_position_{Strategy::OverridingPositions::AUTO};
rclcpp::Node::SharedPtr _node;

Check warning on line 122 in soccer/src/soccer/strategy/agent/position/robot_factory_position.hpp

View workflow job for this annotation

GitHub Actions / build-and-test

invalid case style for private member '_node'

std::optional<RobotIntent> derived_get_task(RobotIntent intent) override;

bool am_closest_kicker();
Expand Down Expand Up @@ -154,6 +165,8 @@
current_position_ = std::make_unique<Pos>(*current_position_);
}
}

bool set_position_override_if_requested();
};

} // namespace strategy
2 changes: 1 addition & 1 deletion soccer/src/soccer/strategy/agent/position/solo_offense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::optional<RobotIntent> SoloOffense::state_to_task(RobotIntent intent) {
planning::LinearMotionInstant target{calculate_best_shot()};
// planning::LinearMotionInstant target{last_world_state_->ball.position};
auto kick_cmd =
planning::MotionCommand{"path_target", target, planning::FaceTarget{}, true};
planning::MotionCommand{"line_kick", target, planning::FaceTarget{}, true};
intent.motion_command = kick_cmd;
intent.shoot_mode = RobotIntent::ShootMode::KICK;
intent.trigger_mode = RobotIntent::TriggerMode::ON_BREAK_BEAM;
Expand Down
Loading
Loading