Skip to content

Commit

Permalink
fix: messages MakeFile
Browse files Browse the repository at this point in the history
  • Loading branch information
maa134340 committed Nov 7, 2024
1 parent 47b6fcf commit 7f5587f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ robocin_cpp_library(
messaging_receiver
messaging_sender
processing
messages
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ void ConsumerController::exec(std::span<const Payload> payloads) {
return;
}

if (std::optional<NavigationMessage> navigation_msg = navigation_processor_->process(payloads);
if (std::optional<::protocols::navigation::Navigation> navigation_msg
= navigation_processor_->process(payloads);
navigation_msg != std::nullopt) {
message_sender_->send(navigation_msg->toProto());
message_sender_->send(*navigation_msg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ robocin_cpp_library(
DEPS navigation_entities
navigation_utils
motion_parser
messages
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ robocin_cpp_library(
HDRS behavior/behavior_message.h
common/peripheral_actuation/peripheral_actuation.h
common/robot_id/robot_id_message.h
common/robot_dribbler/robot_dribbler_message.h
common/robot_kick/kick_command.h
common/robot_pose/robot_pose_message.h
common/game_command/game_command_message.h
common/game_event/game_event_message.h
decision/decision_message.h
Expand All @@ -14,10 +16,13 @@ robocin_cpp_library(
perception/field/field_message.h
perception/detection/detection_message.h
referee/game_status_message.h
navigation/navigation_message.h
SRCS behavior/behavior_message.cpp
common/peripheral_actuation/peripheral_actuation.cpp
common/robot_id/robot_id_message.cpp
common/robot_dribbler/robot_dribbler_message.cpp
common/robot_kick/kick_command.cpp
common/robot_pose/robot_pose_message.cpp
common/game_command/game_command_message.cpp
common/game_event/game_event_message.cpp
decision/decision_message.cpp
Expand All @@ -28,6 +33,7 @@ robocin_cpp_library(
perception/field/field_message.cpp
perception/detection/detection_message.cpp
referee/game_status_message.cpp
navigation/navigation_message.cpp
DEPS common::utility
common::output
protocols::protobufs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ namespace navigation {

class RobotPoseMessage : public robocin::IProtoConvertible<protocols::common::RobotPose> {
public:
explicit RobotPoseMessage(robocin::Point2Df position, float orientation);
explicit RobotPoseMessage(const protocols::common::RobotPose& robot_pose_proto);
robocin::Point2Df position;
float orientation;

RobotPoseMessage(robocin::Point2Df position = robocin::Point2Df{0, 0}, float orientation = 0.0F);

explicit RobotPoseMessage(const protocols::common::RobotPose& robot_pose_proto);

[[nodiscard]] protocols::common::RobotPose toProto() const override;

void fromProto(const protocols::common::RobotPose& robot_pose_proto) override;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
#include "navigation/processing/messages/navigation/navigation_message.h"

#include "navigation_message.h"

#include <algorithm>
#include <utility>

namespace navigation {

void NavigationMessage::fromProto(
const protocols::navigation::Navigation& unification_behavior_proto) {
for (const auto& output_proto : unification_behavior_proto.output()) {
output.emplace_back(output_proto);
void NavigationMessage::fromProto(const protocols::navigation::Navigation& navigation_proto) {
for (const auto& output_proto : navigation_proto.output()) {
output->emplace_back(output_proto);
}
}
NavigationMessage::NavigationMessage(
const protocols::navigation::Navigation& unification_behavior_proto) {
NavigationMessage::fromProto(unification_behavior_proto);
NavigationMessage::NavigationMessage(const protocols::navigation::Navigation& navigation_proto) {
NavigationMessage::fromProto(navigation_proto);
}

void NavigationOutputMessage::fromProto(const protocols::navigation::Output& output_proto) {
Expand Down Expand Up @@ -64,7 +57,7 @@ protocols::navigation::Output NavigationOutputMessage::toProto() const {
return protocols::navigation::Output{};
};

NavigationMessage::NavigationMessage(std::vector<NavigationOutputMessage> output) :
NavigationMessage::NavigationMessage(std::optional<std::vector<NavigationOutputMessage>> output) :
output(std::move(output)) {}

protocols::navigation::Navigation NavigationMessage::toProto() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include <cstdint>
#include <optional>
#include <protocols/common/robot_id.pb.h>
#include <protocols/common/robot_pose.pb.h>
#include <protocols/navigation/navigation.pb.h>
#include <robocin/geometry/point2d.h>
#include <robocin/utility/iproto_convertible.h>
Expand Down Expand Up @@ -51,15 +49,16 @@ class NavigationOutputMessage : public robocin::IProtoConvertible<protocols::nav

class NavigationMessage : public robocin::IProtoConvertible<protocols::navigation::Navigation> {
public:
explicit NavigationMessage(std::vector<NavigationOutputMessage> output = {});
explicit NavigationMessage(std::optional<std::vector<NavigationOutputMessage>> output
= std::nullopt);

explicit NavigationMessage(const protocols::navigation::Navigation& unification_behavior_proto);
explicit NavigationMessage(const protocols::navigation::Navigation& navigation_proto);

std::vector<NavigationOutputMessage> output;
std::optional<std::vector<NavigationOutputMessage>> output;

[[nodiscard]] protocols::navigation::Navigation toProto() const override;

void fromProto(const protocols::navigation::Navigation& unification_behavior_proto) override;
void fromProto(const protocols::navigation::Navigation& navigation_proto) override;
};

} // namespace navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <optional>
#include <protocols/behavior/behavior_unification.pb.h>
#include <protocols/navigation/navigation.pb.h>
#include <protocols/perception/detection.pb.h>
#include <protocols/referee/game_status.pb.h>
#include <ranges>
Expand Down Expand Up @@ -48,16 +49,15 @@ std::vector<rc::GameStatus> gameStatusFromPayloads(std::span<const Payload> payl
NavigationProcessor::NavigationProcessor(std::unique_ptr<IMotionParser> motion_parser) :
motion_parser_(std::move(motion_parser)) {}

std::optional<NavigationMessage> NavigationProcessor::process(std::span<const Payload> payloads) {
NavigationMessage navigation_output;

std::optional<::protocols::navigation::Navigation>
NavigationProcessor::process(std::span<const Payload> payloads) {
if (std::vector<rc::Behavior> behaviors = behaviorFromPayloads(payloads); !behaviors.empty()) {
last_behavior_ = BehaviorUnificationMessage(behaviors.back());
last_behavior_ = behaviors.back();
}

if (std::vector<rc::GameStatus> game_statuses = gameStatusFromPayloads(payloads);
!game_statuses.empty()) {
last_game_status_ = GameStatusMessage(game_statuses.back());
last_game_status_ = game_statuses.back();
}

if (!last_behavior_ or !last_game_status_) {
Expand All @@ -69,55 +69,13 @@ std::optional<NavigationMessage> NavigationProcessor::process(std::span<const Pa
// a new package must be generated only when a new detection is received.
return std::nullopt;
}
DetectionMessage last_detection = DetectionMessage(detections.back());
::protocols::perception::Detection last_detection = detections.back();

///////////////////////////////////////////////////////////////////////////
for (const auto& behavior : last_behavior_->behavior_outputs) {
NavigationOutputMessage output;
RobotMessage ally;

for (auto& robot : last_detection.robots) {
if (robot.robot_id->number == behavior.robot_id->number) {
ally = RobotMessage(robot);
break;
}
}
if (ally.robot_id) {
output.robot_id = ally.robot_id;

if (behavior.motion) {
RobotMove move;
if (behavior.motion->go_to_point) {
move = motion_parser_->fromGoToPoint(behavior.motion->go_to_point.value(), ally);
} else if (behavior.motion->rotate_in_point) {
move = motion_parser_->fromRotateInPoint(behavior.motion->rotate_in_point.value(), ally);
} else if (behavior.motion->rotate_on_self) {
move = motion_parser_->fromRotateOnSelf(behavior.motion->rotate_on_self.value(), ally);
} else {
// PROCESSAMENTO DO GO_TO_POINT_WITH_TRAJECTORY
}

output.left_velocity = move.velocity().y;
output.forward_velocity = move.velocity().x;
output.angular_velocity = move.angularVelocity();

if (behavior.motion->peripheral_actuation) {
output.peripheral_actuation = behavior.motion->peripheral_actuation;
}

// TODO: Add other fields to output

} else if (behavior.planning) {
// PROCESSAMENTO DO PLANNING
} else {
// PROCESSAMENTO DO NAVIGATION
}
}

navigation_output.output.emplace_back(output);
}
::protocols::navigation::Navigation navigation_proto;

////////////////////////////////////////////////////////////////////////////
return navigation_output;
return navigation_proto;
}

} // namespace navigation
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

#include <memory>
#include <optional>
#include <protocols/behavior/behavior_unification.pb.h>
#include <protocols/navigation/navigation.pb.h>
#include <protocols/referee/game_status.pb.h>
#include <robocin/parameters/parameters.h>

namespace navigation {
Expand All @@ -27,19 +29,21 @@ class INavigationProcessor {

virtual ~INavigationProcessor() = default;

virtual std::optional<NavigationMessage> process(std::span<const Payload> payloads) = 0;
virtual std::optional<::protocols::navigation::Navigation>
process(std::span<const Payload> payloads) = 0;
};

class NavigationProcessor : public INavigationProcessor {
public:
explicit NavigationProcessor(std::unique_ptr<IMotionParser> motion_parser);

std::optional<NavigationMessage> process(std::span<const Payload> payloads) override;
std::optional<::protocols::navigation::Navigation>
process(std::span<const Payload> payloads) override;

private:
std::unique_ptr<IMotionParser> motion_parser_;
std::optional<BehaviorUnificationMessage> last_behavior_;
std::optional<GameStatusMessage> last_game_status_;
std::optional<::protocols::behavior::unification::Behavior> last_behavior_;
std::optional<::protocols::referee::GameStatus> last_game_status_;
};

} // namespace navigation
Expand Down

0 comments on commit 7f5587f

Please sign in to comment.