Skip to content

Commit fdff555

Browse files
committed
working waller coord
1 parent f54f23f commit fdff555

File tree

5 files changed

+9
-32
lines changed

5 files changed

+9
-32
lines changed

src/rj_strategy/include/rj_strategy/coordinator/waller.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class Waller
3131
private:
3232
std::array<u_int8_t, kNumShells> walling_robots_;
3333
u_int8_t num_wallers_ = 0;
34-
WorldState last_world_state_;
35-
rclcpp::Subscription<rj_msgs::msg::WorldState>::SharedPtr world_state_sub_;
3634
static constexpr int kMaxWallers = 4;
3735

3836
void update_wallers();

src/rj_strategy/src/agent/position/defense.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ Defense::State Defense::update_state() {
2626
rj_geometry::Point ball_position = world_state->ball.position;
2727
double distance_to_ball = robot_position.dist_to(ball_position);
2828

29-
if (current_state_ != WALLING && current_state_ != JOINING_WALL) {
30-
client_handles_->waller->leave_group();
31-
}
32-
3329
switch (current_state_) {
3430
case IDLING:
3531
next_state = JOINING_WALL;
@@ -65,6 +61,7 @@ Defense::State Defense::update_state() {
6561
if (check_is_done()) {
6662
next_state = IDLING;
6763
}
64+
break;
6865
case MARKING:
6966
if (marker_.get_target() == -1 || marker_.target_out_of_bounds(world_state)) {
7067
next_state = ENTERING_MARKING;
@@ -182,9 +179,7 @@ void Defense::derived_acknowledge_ball_in_transit() {
182179

183180

184181
void Defense::die() {
185-
if (current_state_ == WALLING) {
186-
client_handles_->waller->leave_group();
187-
}
182+
client_handles_->waller->leave_group();
188183
}
189184

190185
void Defense::revive() { current_state_ = JOINING_WALL; }

src/rj_strategy/src/agent/position/offense.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ std::optional<RobotIntent> Offense::derived_get_task(RobotIntent intent) {
1515
if (current_state_ != new_state) {
1616
reset_timeout();
1717

18-
SPDLOG_INFO("Robot {}: now {}", robot_id_, state_to_name(current_state_));
18+
// SPDLOG_INFO("Robot {}: now {}", robot_id_, state_to_name(current_state_));
1919
if (current_state_ == SEEKING) {
2020
broadcast_seeker_request(rj_geometry::Point{}, false);
2121
}

src/rj_strategy/src/coordinator/waller.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ namespace strategy {
55
Waller::Waller()
66
: Coordinator("waller_srv", "waller_data", "waller_node") {
77
walling_robots_.fill(-1);
8-
world_state_sub_ = this->create_subscription<rj_msgs::msg::WorldState>(
9-
vision_filter::topics::kWorldStateTopic, rclcpp::QoS(1),
10-
[this](rj_msgs::msg::WorldState::SharedPtr world_state) { // NOLINT
11-
last_world_state_ = rj_convert::convert_from_ros(*world_state);
12-
update_wallers();
13-
});
148
}
159

1610
void Waller::service_callback(RequestPtr request, ResponsePtr response) {
@@ -30,25 +24,16 @@ void Waller::service_callback(RequestPtr request, ResponsePtr response) {
3024
if (it != walling_robots_.end()) {
3125
num_wallers_--;
3226
*it = -1;
33-
response->success = true;
3427
update_wallers();
35-
} else {
36-
response->success = false;
3728
}
29+
response->success = true;
3830
}
3931
}
4032

4133
void Waller::update_wallers() {
4234
auto prev_wallers = walling_robots_;
4335
std::sort(walling_robots_.begin(), walling_robots_.end());
44-
auto must_republish = false;
45-
for (int i = 0; i < num_wallers_ && !must_republish; i++) {
46-
if (prev_wallers[i] != walling_robots_[i]) must_republish = true;
47-
}
48-
49-
if (must_republish) {
50-
publisher_->publish(rj_msgs::msg::Waller().set__wall_list(walling_robots_).set__wall_size(num_wallers_));
51-
}
36+
publisher_->publish(rj_msgs::msg::Waller().set__wall_list(walling_robots_).set__wall_size(num_wallers_));
5237
}
5338

5439
} // namespace strategy

src/rj_strategy/src/coordinator/waller_client.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void WallerClient::join_group(StatusCallback callback) {
4444
walling_robots_ = msg->wall_list;
4545
num_wallers_ = msg->wall_size;
4646
am_i_member_ = std::find(walling_robots_.begin(), walling_robots_.end(), robot_id_) != walling_robots_.end();
47-
47+
4848
if (callback) {
4949
callback(Result{am_i_member_});
5050
}
@@ -56,7 +56,7 @@ void WallerClient::join_group(StatusCallback callback) {
5656
}
5757

5858
void WallerClient::leave_group(StatusCallback callback) {
59-
if (!am_i_member_) {
59+
if (!am_i_member_ && !request_pending_) {
6060
if (callback) {
6161
callback(Result{false});
6262
}
@@ -95,7 +95,7 @@ bool WallerClient::am_i_member() const { return am_i_member_; }
9595

9696
std::optional<rj_geometry::Point> WallerClient::get_walling_point(const WorldState* world_state,
9797
FieldDimensions field_dimensions) const {
98-
if (!am_i_member_) return nullopt;
98+
if (!am_i_member_) return std::nullopt;
9999

100100
// Creates Minimum wall radius is slightly greater than box bounds
101101
// Dimension accessors should be edited when we figure out how we are doing dimensions realtime
@@ -122,8 +122,7 @@ std::optional<rj_geometry::Point> WallerClient::get_walling_point(const WorldSta
122122
auto wall_spacing = kRobotDiameterMultiplier * kRobotDiameter + kBallRadius;
123123

124124
auto it = std::find(walling_robots_.begin(), walling_robots_.end(), robot_id_);
125-
if (it == walling_robots_.end()) return std::nullopt;
126-
auto waller_pos = std::distance(walling_robots_.begin(), it);
125+
auto waller_pos = std::distance(walling_robots_.begin(), it)+1;
127126

128127
rj_geometry::Point target_point{};
129128
auto angle = (mid_point - goal_pos).angle();

0 commit comments

Comments
 (0)