Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
ersaraujo committed Oct 26, 2024
1 parent 4c901b4 commit fc68576
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 273 deletions.
2 changes: 1 addition & 1 deletion behavior-ms/behavior-bruxo/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#include "behavior/messaging/receiver/payload.h"
#include "behavior/parameters/parameters.h"

#include <protocols/behavior/motion.pb.h>
#include <protocols/behavior/behavior_unification.pb.h>

#include <protocols/behavior/motion.pb.h>
#include <protocols/decision/decision.pb.h>

#include <protocols/perception/detection.pb.h>

#include <ranges>
#include <robocin/memory/object_ptr.h>
#include <robocin/output/log.h>
#include <ranges>

namespace behavior {

Expand All @@ -25,16 +22,15 @@ using ::robocin::object_ptr;

namespace rc {


using ::protocols::common::RobotId;
using ::protocols::decision::Decision;
using ::protocols::perception::Ball;
using ::protocols::perception::Detection;
using ::protocols::decision::Decision;

using ::protocols::behavior::GoToPoint;
using ::protocols::behavior::unification::Behavior;
using ::protocols::behavior::unification::Motion;
using ::protocols::behavior::unification::Output;
using ::protocols::behavior::unification::Behavior;

} // namespace rc

Expand All @@ -56,36 +52,32 @@ BehaviorProcessor::BehaviorProcessor(

std::optional<rc::Behavior> BehaviorProcessor::process(std::span<const Payload> payloads) {

if(std::vector<rc::Decision> decision_messages = decisionfromPayloads(payloads);
!decision_messages.empty()) {
if (std::vector<rc::Decision> decision_messages = decisionfromPayloads(payloads);
!decision_messages.empty()) {
last_decision_ = decision_messages.back();
}

if(!last_decision_) {
if (!last_decision_) {
return std::nullopt;
}

std::vector<rc::Detection> detection_messages = detectionFromPayloads(payloads);
if(detection_messages.empty()) {
if (detection_messages.empty()) {
// a new package must be generated only when a new detection is received.
return std::nullopt;
}
const rc::Detection last_detection = detection_messages.back();


// TODO: implement the logic to generate the behavior based on the last detection and the last decision
// TODO: implement the logic to generate the behavior based on the last detection and the last
// decision
///////////////////////////////////////////////////////////////////////////////////

BehaviorMessage behavior_message;

for (const auto& robot : last_detection.robots()) {

behavior_message.output.emplace_back(
OutputMessage{
RobotIdMessage{},
MotionMessage{},
PlanningMessage{}
});
OutputMessage{RobotIdMessage{}, MotionMessage{}, PlanningMessage{}});
}

///////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#define BEHAVIOR_PROCESSING_BEHAVIOR_PROCESSOR_H

#include "behavior/messaging/receiver/payload.h"

#include "behavior/processing/messages/behavior/behavior_message.h"
#include "behavior/processing/messages/motion/motion_message.h"
#include "behavior/processing/messages/common/robot_id/robot_id.h"
#include "behavior/processing/messages/motion/motion_message.h"

#include <protocols/behavior/behavior_unification.pb.h>
#include <protocols/decision/decision.pb.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ OutputMessage::OutputMessage(RobotIdMessage robot_id,
motion{std::move(motion)},
planning{std::move(planning)} {}

BehaviorMessage::BehaviorMessage(std::vector<OutputMessage> output) :
output{std::move(output)} {}
BehaviorMessage::BehaviorMessage(std::vector<OutputMessage> output) : output{std::move(output)} {}

} // namespace behavior
} // namespace behavior
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
#include "behavior/processing/messages/motion/motion_message.h"
#include "behavior/processing/messages/common/robot_id/robot_id.h"
#include "behavior/processing/messages/motion/motion_message.h"
#include "behavior/processing/messages/planning/planning_message.h"

#include <protocols/behavior/behavior_unification.pb.h>

#include <robocin/output/log.h>
#include <robocin/utility/iproto_convertible.h>

namespace behavior {

class OutputMessage : public robocin::IProtoConvertible<protocols::behavior::unification::Output> {
public:
OutputMessage(RobotIdMessage robot_id = RobotIdMessage{},
MotionMessage motion = MotionMessage{},
PlanningMessage planning = PlanningMessage{});

[[nodiscard]] protocols::behavior::unification::Output toProto() const override {
protocols::behavior::unification::Output output;
output.mutable_robot_id()->CopyFrom(robot_id.toProto());
output.mutable_motion()->CopyFrom(motion.toProto());
output.mutable_planning()->CopyFrom(planning.toProto());
return output;
};

void fromProto(protocols::behavior::unification::Output output) override {
robot_id.fromProto(output.robot_id());
motion.fromProto(output.motion());
planning.fromProto(output.planning());
};

RobotIdMessage robot_id;
MotionMessage motion;
PlanningMessage planning;
public:
OutputMessage(RobotIdMessage robot_id = RobotIdMessage{},
MotionMessage motion = MotionMessage{},
PlanningMessage planning = PlanningMessage{});

[[nodiscard]] protocols::behavior::unification::Output toProto() const override {
protocols::behavior::unification::Output output;
output.mutable_robot_id()->CopyFrom(robot_id.toProto());
output.mutable_motion()->CopyFrom(motion.toProto());
output.mutable_planning()->CopyFrom(planning.toProto());
return output;
};

void fromProto(protocols::behavior::unification::Output output) override {
robot_id.fromProto(output.robot_id());
motion.fromProto(output.motion());
planning.fromProto(output.planning());
};

RobotIdMessage robot_id;
MotionMessage motion;
PlanningMessage planning;
};

class BehaviorMessage : public robocin::IProtoConvertible<protocols::behavior::unification::Behavior> {
public:
BehaviorMessage(std::vector<OutputMessage> output = std::vector<OutputMessage>{});
class BehaviorMessage
: public robocin::IProtoConvertible<protocols::behavior::unification::Behavior> {
public:
BehaviorMessage(std::vector<OutputMessage> output = std::vector<OutputMessage>{});

[[nodiscard]] protocols::behavior::unification::Behavior toProto() const override {
protocols::behavior::unification::Behavior behavior;
for (const auto& output : output) {
behavior.add_output()->CopyFrom(output.toProto());
}
return behavior;
};
[[nodiscard]] protocols::behavior::unification::Behavior toProto() const override {
protocols::behavior::unification::Behavior behavior;
for (const auto& output : output) {
behavior.add_output()->CopyFrom(output.toProto());
}
return behavior;
};

void fromProto(protocols::behavior::unification::Behavior behavior) override {
// Implementação específica para converter de proto para BehaviorMessage
};
void fromProto(protocols::behavior::unification::Behavior behavior) override {
// Implementação específica para converter de proto para BehaviorMessage
};

std::vector<OutputMessage> output;
std::vector<OutputMessage> output;
};

} // namespace behavior
} // namespace behavior
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RobotIdMessage::RobotIdMessage(std::optional<Color> color, std::optional<uint32_
color{std::move(color)},
number{std::move(number)} {}

} // namespace behavior
} // namespace behavior
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
#ifndef BEHAVIOR_PROCESSING_MESSAGES_COMMON_ROBOT_ID_H
#define BEHAVIOR_PROCESSING_MESSAGES_COMMON_ROBOT_ID_H

#include <robocin/utility/iproto_convertible.h>

#include <protocols/common/robot_id.pb.h>
#include <robocin/utility/iproto_convertible.h>

namespace behavior {

class RobotIdMessage : public robocin::IProtoConvertible<protocols::common::RobotId> {
enum Color {
COLOR_UNSPECIFIED = 0,
COLOR_YELLOW = 1,
COLOR_BLUE = 2,
};

public:
explicit RobotIdMessage(std::optional<Color> color = std::nullopt,
std::optional<uint32_t> number = 0);

[[nodiscard]] protocols::common::RobotId toProto() const override {
protocols::common::RobotId robot_id;
robot_id.set_color(static_cast<::protocols::common::RobotId_Color>(color.value_or(Color::COLOR_UNSPECIFIED)));
robot_id.set_number(number.value_or(0));

return robot_id;
};

void fromProto(protocols::common::RobotId robot_id) override {
color = static_cast<Color>(robot_id.color());
number = robot_id.number();
};

std::optional<Color> color;
std::optional<uint32_t> number;

enum Color {
COLOR_UNSPECIFIED = 0,
COLOR_YELLOW = 1,
COLOR_BLUE = 2,
};

public:
explicit RobotIdMessage(std::optional<Color> color = std::nullopt,
std::optional<uint32_t> number = 0);

[[nodiscard]] protocols::common::RobotId toProto() const override {
protocols::common::RobotId robot_id;
robot_id.set_color(
static_cast<::protocols::common::RobotId_Color>(color.value_or(Color::COLOR_UNSPECIFIED)));
robot_id.set_number(number.value_or(0));

return robot_id;
};

void fromProto(protocols::common::RobotId robot_id) override {
color = static_cast<Color>(robot_id.color());
number = robot_id.number();
};

std::optional<Color> color;
std::optional<uint32_t> number;
};

} // namespace behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ RotateInPointMessage::RotateInPointMessage() {}

RotateOnSelfMessage::RotateOnSelfMessage() {}

MotionMessage::MotionMessage(std::optional<GoToPointMessage> go_to_point,
std::optional<GoToPointWithTrajectoryMessage> go_to_point_with_trajectory,
std::optional<RotateInPointMessage> rotate_in_point,
std::optional<RotateOnSelfMessage> rotate_on_self) :
MotionMessage::MotionMessage(
std::optional<GoToPointMessage> go_to_point,
std::optional<GoToPointWithTrajectoryMessage> go_to_point_with_trajectory,
std::optional<RotateInPointMessage> rotate_in_point,
std::optional<RotateOnSelfMessage> rotate_on_self) :
go_to_point{std::move(go_to_point)},
go_to_point_with_trajectory{std::move(go_to_point_with_trajectory)},
rotate_in_point{std::move(rotate_in_point)},
rotate_on_self{std::move(rotate_on_self)} {}

} // namespace behavior
} // namespace behavior
Loading

0 comments on commit fc68576

Please sign in to comment.