Skip to content

Commit

Permalink
fix alive robots
Browse files Browse the repository at this point in the history
  • Loading branch information
sid-parikh committed Apr 29, 2024
1 parent 6ec0a0b commit 92aaa9e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions soccer/src/soccer/radio/network_radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ NetworkRadio::NetworkRadio()
: control_message_socket_(io_service_),
robot_status_socket_(io_service_),
alive_robots_socket_(io_service_),
send_buffers_(kNumShells) {
send_buffers_(kNumShells),
Radio() {
control_message_socket_.open(udp::v4());
control_message_socket_.bind(udp::endpoint(udp::v4(), kControlMessageSocketPort));

Expand Down Expand Up @@ -111,6 +112,7 @@ void NetworkRadio::receive_robot_status(const boost::system::error_code& error,
}

void NetworkRadio::receive_alive_robots(const boost::system::error_code& error, size_t num_bytes) {
SPDLOG_INFO("Receiving Alive Robots");
if (static_cast<bool>(error)) {
SPDLOG_ERROR("Error Receiving Alive Robots: {}", error.message());
start_alive_robots_receive();
Expand All @@ -123,14 +125,20 @@ void NetworkRadio::receive_alive_robots(const boost::system::error_code& error,
return;
}

uint16_t alive = (alive_robots_buffer_[0] << 8) | (alive_robots_buffer_[0]);
uint16_t alive = (((uint16_t) alive_robots_buffer_[1]) << 8) | (alive_robots_buffer_[0]);
SPDLOG_INFO("Alive: {}", alive);

// uint16_t alive = (alive_robots_buffer_[0] << 8) | (alive_robots_buffer_[0]);
for (uint8_t robot_id = 0; robot_id < kNumShells; robot_id++) {
if ((alive & (1 << robot_id)) != 0) {
alive_robots_[robot_id] = true;
} else {
alive_robots_[robot_id] = false;
}
}
for (int robot_id = 0; robot_id < 16; robot_id++) {
SPDLOG_INFO("Robot {} is Alive {}", robot_id, alive_robots_[robot_id]);
}

rj_msgs::msg::AliveRobots alive_message{};
alive_message.alive_robots = alive_robots_;
Expand Down
2 changes: 2 additions & 0 deletions soccer/src/soccer/radio/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void Radio::publish_robot_status(int robot_id, const rj_msgs::msg::RobotStatus&
}

void Radio::publish_alive_robots(const rj_msgs::msg::AliveRobots& alive_robots) {
// SPDLOG_INFO("publishing alive robots {}", alive_robots);
SPDLOG_INFO("publishing alive robots");
alive_robots_pub_->publish(alive_robots);
}

Expand Down
2 changes: 1 addition & 1 deletion soccer/src/soccer/strategy/agent/position/offense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::optional<RobotIntent> Offense::derived_get_task(RobotIntent intent) {
if (current_state_ != new_state) {
reset_timeout();

SPDLOG_INFO("Robot {}: now {}", robot_id_, state_to_name(current_state_));
// SPDLOG_INFO("Robot {}: now {}", robot_id_, state_to_name(current_state_));
if (current_state_ == SEEKING) {
broadcast_seeker_request(rj_geometry::Point{}, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ std::optional<RobotIntent> RobotFactoryPosition::derived_get_task([
current_play_state_);
}



// Update our state
process_play_state();

Expand Down

0 comments on commit 92aaa9e

Please sign in to comment.