Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
69 changes: 35 additions & 34 deletions src/proto/message_translation/tbots_protobuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#include "software/logger/logger.h"


std::unique_ptr<TbotsProto::World> createWorld(const World& world)
std::unique_ptr<TbotsProto::World> createWorldProto(const World& world)
{
// create msg
auto world_msg = std::make_unique<TbotsProto::World>();
*(world_msg->mutable_time_sent()) = *createCurrentTimestamp();
*(world_msg->mutable_field()) = *createField(world.field());
*(world_msg->mutable_friendly_team()) = *createTeam(world.friendlyTeam());
*(world_msg->mutable_enemy_team()) = *createTeam(world.enemyTeam());
*(world_msg->mutable_ball()) = *createBall(world.ball());
*(world_msg->mutable_game_state()) = *createGameState(world.gameState());
*(world_msg->mutable_time_sent()) = *createCurrentTimestampProto();
*(world_msg->mutable_field()) = *createFieldProto(world.field());
*(world_msg->mutable_friendly_team()) = *createTeamProto(world.friendlyTeam());
*(world_msg->mutable_enemy_team()) = *createTeamProto(world.enemyTeam());
*(world_msg->mutable_ball()) = *createBallProto(world.ball());
*(world_msg->mutable_game_state()) = *createGameStateProto(world.gameState());
if (world.getDribbleDisplacement().has_value())
{
*(world_msg->mutable_dribble_displacement()) =
Expand All @@ -22,17 +22,17 @@ std::unique_ptr<TbotsProto::World> createWorld(const World& world)
return world_msg;
}

std::unique_ptr<TbotsProto::World> createWorldWithSequenceNumber(
std::unique_ptr<TbotsProto::World> createWorldWithSequenceNumberProto(
const World& world, const uint64_t sequence_number)
{
// create msg
auto world_msg = std::make_unique<TbotsProto::World>();
*(world_msg->mutable_time_sent()) = *createCurrentTimestamp();
*(world_msg->mutable_field()) = *createField(world.field());
*(world_msg->mutable_friendly_team()) = *createTeam(world.friendlyTeam());
*(world_msg->mutable_enemy_team()) = *createTeam(world.enemyTeam());
*(world_msg->mutable_ball()) = *createBall(world.ball());
*(world_msg->mutable_game_state()) = *createGameState(world.gameState());
*(world_msg->mutable_time_sent()) = *createCurrentTimestampProto();
*(world_msg->mutable_field()) = *createFieldProto(world.field());
*(world_msg->mutable_friendly_team()) = *createTeamProto(world.friendlyTeam());
*(world_msg->mutable_enemy_team()) = *createTeamProto(world.enemyTeam());
*(world_msg->mutable_ball()) = *createBallProto(world.ball());
*(world_msg->mutable_game_state()) = *createGameStateProto(world.gameState());
world_msg->set_sequence_number(sequence_number);
if (world.getDribbleDisplacement().has_value())
{
Expand All @@ -43,15 +43,15 @@ std::unique_ptr<TbotsProto::World> createWorldWithSequenceNumber(
}


std::unique_ptr<TbotsProto::Team> createTeam(const Team& team)
std::unique_ptr<TbotsProto::Team> createTeamProto(const Team& team)
{
// create msg
auto team_msg = std::make_unique<TbotsProto::Team>();
const auto& robots = team.getAllRobots();

std::for_each(robots.begin(), robots.end(),
[&](const Robot& robot)
{ *(team_msg->add_team_robots()) = *createRobot(robot); });
{ *(team_msg->add_team_robots()) = *createRobotProto(robot); });

auto goalie_id = team.getGoalieId();
if (goalie_id.has_value())
Expand All @@ -62,13 +62,13 @@ std::unique_ptr<TbotsProto::Team> createTeam(const Team& team)
return team_msg;
}

std::unique_ptr<TbotsProto::Robot> createRobot(const Robot& robot)
std::unique_ptr<TbotsProto::Robot> createRobotProto(const Robot& robot)
{
// create msg
auto robot_msg = std::make_unique<TbotsProto::Robot>();
robot_msg->set_id(robot.id());
*(robot_msg->mutable_current_state()) = *createRobotStateProto(robot);
*(robot_msg->mutable_timestamp()) = *createTimestamp(robot.timestamp());
*(robot_msg->mutable_timestamp()) = *createTimestampProto(robot.timestamp());

for (RobotCapability capability : robot.getUnavailableCapabilities())
{
Expand Down Expand Up @@ -96,17 +96,17 @@ std::unique_ptr<TbotsProto::Robot> createRobot(const Robot& robot)
return robot_msg;
}

std::unique_ptr<TbotsProto::Ball> createBall(const Ball& ball)
std::unique_ptr<TbotsProto::Ball> createBallProto(const Ball& ball)
{
// create msg
auto ball_msg = std::make_unique<TbotsProto::Ball>();
*(ball_msg->mutable_current_state()) = *createBallState(ball);
*(ball_msg->mutable_timestamp()) = *createTimestamp(ball.timestamp());
*(ball_msg->mutable_current_state()) = *createBallStateProto(ball);
*(ball_msg->mutable_timestamp()) = *createTimestampProto(ball.timestamp());

return ball_msg;
}

std::unique_ptr<TbotsProto::Field> createField(const Field& field)
std::unique_ptr<TbotsProto::Field> createFieldProto(const Field& field)
{
// create msg
auto field_msg = std::make_unique<TbotsProto::Field>();
Expand Down Expand Up @@ -146,7 +146,7 @@ std::unique_ptr<TbotsProto::RobotState> createRobotStateProto(
return robot_state_msg;
}

std::unique_ptr<TbotsProto::GameState> createGameState(const GameState& game_state)
std::unique_ptr<TbotsProto::GameState> createGameStateProto(const GameState& game_state)
{
auto game_state_msg = std::make_unique<TbotsProto::GameState>();

Expand Down Expand Up @@ -283,7 +283,7 @@ std::unique_ptr<TbotsProto::GameState> createGameState(const GameState& game_sta
auto ball_state = game_state.getBall();
if (ball_state.has_value())
{
*(game_state_msg->mutable_ball()) = *createBall(ball_state.value());
*(game_state_msg->mutable_ball()) = *createBallProto(ball_state.value());
}

auto ball_placement_point = game_state.getBallPlacementPoint();
Expand All @@ -296,7 +296,7 @@ std::unique_ptr<TbotsProto::GameState> createGameState(const GameState& game_sta
return game_state_msg;
}

std::unique_ptr<TbotsProto::BallState> createBallState(const Ball& ball)
std::unique_ptr<TbotsProto::BallState> createBallStateProto(const Ball& ball)
{
auto position = createPointProto(ball.position());
auto velocity = createVectorProto(ball.velocity());
Expand All @@ -309,23 +309,23 @@ std::unique_ptr<TbotsProto::BallState> createBallState(const Ball& ball)
return ball_state_msg;
}

std::unique_ptr<TbotsProto::Timestamp> createTimestamp(const Timestamp& timestamp)
std::unique_ptr<TbotsProto::Timestamp> createTimestampProto(const Timestamp& timestamp)
{
auto timestamp_msg = std::make_unique<TbotsProto::Timestamp>();
timestamp_msg->set_epoch_timestamp_seconds(timestamp.toSeconds());
return timestamp_msg;
}

std::unique_ptr<TbotsProto::NamedValue> createNamedValue(const std::string name,
float value)
std::unique_ptr<TbotsProto::NamedValue> createNamedValueProto(const std::string name,
float value)
{
auto named_value_msg = std::make_unique<TbotsProto::NamedValue>();
named_value_msg->set_name(name);
named_value_msg->set_value(value);
return named_value_msg;
}

std::unique_ptr<TbotsProto::PlotJugglerValue> createPlotJugglerValue(
std::unique_ptr<TbotsProto::PlotJugglerValue> createPlotJugglerValueProto(
const std::map<std::string, double>& values)
{
auto plot_juggler_value_msg = std::make_unique<TbotsProto::PlotJugglerValue>();
Expand All @@ -340,7 +340,7 @@ std::unique_ptr<TbotsProto::PlotJugglerValue> createPlotJugglerValue(
return plot_juggler_value_msg;
}

std::unique_ptr<TbotsProto::DebugShapes> createDebugShapes(
std::unique_ptr<TbotsProto::DebugShapes> createDebugShapesProto(
const std::vector<TbotsProto::DebugShapes::DebugShape>& debug_shapes)
{
auto debug_shape_list_msg = std::make_unique<TbotsProto::DebugShapes>();
Expand All @@ -349,7 +349,7 @@ std::unique_ptr<TbotsProto::DebugShapes> createDebugShapes(
return debug_shape_list_msg;
}

std::unique_ptr<TbotsProto::Timestamp> createCurrentTimestamp()
std::unique_ptr<TbotsProto::Timestamp> createCurrentTimestampProto()
{
auto timestamp_msg = std::make_unique<TbotsProto::Timestamp>();
const auto clock_time = std::chrono::system_clock::now();
Expand Down Expand Up @@ -378,7 +378,7 @@ BallState createBallState(const TbotsProto::BallState ball_state)
ball_state.distance_from_ground());
}

std::unique_ptr<TbotsProto::PassVisualization> createPassVisualization(
std::unique_ptr<TbotsProto::PassVisualization> createPassVisualizationProto(
const std::vector<PassWithRating>& passes_with_rating)
{
auto pass_visualization_msg = std::make_unique<TbotsProto::PassVisualization>();
Expand All @@ -401,15 +401,16 @@ std::unique_ptr<TbotsProto::PassVisualization> createPassVisualization(
return pass_visualization_msg;
}

std::unique_ptr<TbotsProto::WorldStateReceivedTrigger> createWorldStateReceivedTrigger()
std::unique_ptr<TbotsProto::WorldStateReceivedTrigger>
createWorldStateReceivedTriggerProto()
{
auto world_state_received_trigger_msg =
std::make_unique<TbotsProto::WorldStateReceivedTrigger>();

return world_state_received_trigger_msg;
}

std::unique_ptr<TbotsProto::CostVisualization> createCostVisualization(
std::unique_ptr<TbotsProto::CostVisualization> createCostVisualizationProto(
const std::vector<double>& costs, int num_rows, int num_cols)
{
auto cost_visualization_msg = std::make_unique<TbotsProto::CostVisualization>();
Expand Down
48 changes: 25 additions & 23 deletions src/proto/message_translation/tbots_protobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "software/ai/passing/pass_with_rating.h"
#include "software/world/world.h"

/** testing */
/**
* Returns a TbotsProto::World proto given a World.
*
Expand All @@ -18,7 +19,7 @@
* @return The unique_ptr to a TbotsProto::World proto containing the field, friendly
* team, enemy team, ball, and the game state.
*/
std::unique_ptr<TbotsProto::World> createWorld(const World& world);
std::unique_ptr<TbotsProto::World> createWorldProto(const World& world);

/**
* Returns a TbotsProto::World proto with a sequence number given a World and a sequence
Expand All @@ -30,7 +31,7 @@ std::unique_ptr<TbotsProto::World> createWorld(const World& world);
* @return The unique_ptr to a TbotsProto::World proto containing the field, friendly
* team, enemy team, ball, game state, and the sequence number.
*/
std::unique_ptr<TbotsProto::World> createWorldWithSequenceNumber(
std::unique_ptr<TbotsProto::World> createWorldWithSequenceNumberProto(
const World& world, const uint64_t sequence_number);

/**
Expand All @@ -41,7 +42,7 @@ std::unique_ptr<TbotsProto::World> createWorldWithSequenceNumber(
* @return The unique_ptr to a TbotsProto::Team proto containing a list of robots and
* goalie ID
*/
std::unique_ptr<TbotsProto::Team> createTeam(const Team& team);
std::unique_ptr<TbotsProto::Team> createTeamProto(const Team& team);

/**
* Returns a TbotsProto::Robot proto given a Robot.
Expand All @@ -51,7 +52,7 @@ std::unique_ptr<TbotsProto::Team> createTeam(const Team& team);
* @return The unique_ptr to a TbotsProto::Robot proto containing the robot ID and robot
* state
*/
std::unique_ptr<TbotsProto::Robot> createRobot(const Robot& robot);
std::unique_ptr<TbotsProto::Robot> createRobotProto(const Robot& robot);

/**
* Returns a TbotsProto::Ball proto given a Ball.
Expand All @@ -61,7 +62,7 @@ std::unique_ptr<TbotsProto::Robot> createRobot(const Robot& robot);
* @return The unique_ptr to a TbotsProto::Ball proto containing the ball state and the
* ball acceleration
*/
std::unique_ptr<TbotsProto::Ball> createBall(const Ball& ball);
std::unique_ptr<TbotsProto::Ball> createBallProto(const Ball& ball);

/**
* Returns a TbotsProto::Field proto given a Field.
Expand All @@ -71,7 +72,7 @@ std::unique_ptr<TbotsProto::Ball> createBall(const Ball& ball);
* @return The unique_ptr to a TbotsProto::Field proto containing the Ball ID and Ball
* state
*/
std::unique_ptr<TbotsProto::Field> createField(const Field& field);
std::unique_ptr<TbotsProto::Field> createFieldProto(const Field& field);

/**
* Returns (Robot, Game, Ball) State given a (Robot, Game, Ball)
Expand All @@ -83,8 +84,8 @@ std::unique_ptr<TbotsProto::Field> createField(const Field& field);
std::unique_ptr<TbotsProto::RobotState> createRobotStateProto(const Robot& robot);
std::unique_ptr<TbotsProto::RobotState> createRobotStateProto(
const RobotState& robot_state);
std::unique_ptr<TbotsProto::GameState> createGameState(const GameState& game_state);
std::unique_ptr<TbotsProto::BallState> createBallState(const Ball& ball);
std::unique_ptr<TbotsProto::GameState> createGameStateProto(const GameState& game_state);
std::unique_ptr<TbotsProto::BallState> createBallStateProto(const Ball& ball);

/**
* Returns a TbotsProto::Timestamp proto given a timestamp.
Expand All @@ -94,7 +95,7 @@ std::unique_ptr<TbotsProto::BallState> createBallState(const Ball& ball);
* @return The unique_ptr to a TbotsProto::Timestamp proto containing the timestamp with
* the same time zone as the timestamp argument.
*/
std::unique_ptr<TbotsProto::Timestamp> createTimestamp(const Timestamp& timestamp);
std::unique_ptr<TbotsProto::Timestamp> createTimestampProto(const Timestamp& timestamp);

/**
* Returns a TbotsProto::NamedValue proto given a name and value.
Expand All @@ -105,15 +106,15 @@ std::unique_ptr<TbotsProto::Timestamp> createTimestamp(const Timestamp& timestam
* @return The unique_ptr to a TbotsProto::NamedValue proto containing data with
* specified name and value
*/
std::unique_ptr<TbotsProto::NamedValue> createNamedValue(const std::string name,
float value);
std::unique_ptr<TbotsProto::NamedValue> createNamedValueProto(const std::string name,
float value);

/**
* Returns a TbotsProto::PlotJugglerValue proto containing the name
* value pairs of the map.
*
* Could use LOG(PLOTJUGGLER) to plot the values. Example:
* LOG(PLOTJUGGLER) << *createPlotJugglerValue({
* LOG(PLOTJUGGLER) << *createPlotJugglerValueProto({
* {"vx", velocity.x()},
* {"vy", velocity.y()}
* });
Expand All @@ -123,7 +124,7 @@ std::unique_ptr<TbotsProto::NamedValue> createNamedValue(const std::string name,
* @return The unique_ptr to a TbotsProto::PlotJugglerValue proto containing data with
* specified names and values
*/
std::unique_ptr<TbotsProto::PlotJugglerValue> createPlotJugglerValue(
std::unique_ptr<TbotsProto::PlotJugglerValue> createPlotJugglerValueProto(
const std::map<std::string, double>& values);

/**
Expand All @@ -141,7 +142,7 @@ std::unique_ptr<TbotsProto::PlotJugglerValue> createPlotJugglerValue(
* @return The unique_ptr to a TbotsProto::DebugShapes::DebugShape proto
*/
template <class Shape>
std::unique_ptr<TbotsProto::DebugShapes::DebugShape> createDebugShape(
std::unique_ptr<TbotsProto::DebugShapes::DebugShape> createDebugShapeProto(
const Shape& shape, const std::string& unique_id, const std::string& debug_text = "")
{
auto debug_shape = std::make_unique<TbotsProto::DebugShapes::DebugShape>();
Expand All @@ -155,18 +156,18 @@ std::unique_ptr<TbotsProto::DebugShapes::DebugShape> createDebugShape(
* Returns a TbotsProto::DebugShapes proto containing the debug shapes
*
* Could use LOG(VISUALIZE) to plot these values. Example:
* LOG(VISUALIZE) << *createDebugShapes({
* *createDebugShape(circle, unique_id1, optional_text),
* *createDebugShape(polygon, unique_id2, optional_text),
* *createDebugShape(stadium, unique_id3, optional_text)
* LOG(VISUALIZE) << *createDebugShapesProto({
* *createDebugShapeProto(circle, unique_id1, optional_text),
* *createDebugShapeProto(polygon, unique_id2, optional_text),
* *createDebugShapeProto(stadium, unique_id3, optional_text)
* });
*
* @param debug_shapes A list of debug shapes proto to plot
*
* @return The unique_ptr to a TbotsProto::DebugShapes proto containing data with
* specified names and shapes
*/
std::unique_ptr<TbotsProto::DebugShapes> createDebugShapes(
std::unique_ptr<TbotsProto::DebugShapes> createDebugShapesProto(
const std::vector<TbotsProto::DebugShapes::DebugShape>& debug_shapes);

/**
Expand All @@ -185,7 +186,7 @@ std::unique_ptr<TbotsProto::Shape> createShapeProto(const Stadium& stadium);
*
* @return The unique_ptr to a TbotsProto::Timestamp with the current UTC time
*/
std::unique_ptr<TbotsProto::Timestamp> createCurrentTimestamp();
std::unique_ptr<TbotsProto::Timestamp> createCurrentTimestampProto();

/**
* Return RobotState given the TbotsProto::RobotState protobuf
Expand All @@ -210,7 +211,7 @@ BallState createBallState(const TbotsProto::BallState ball_state);
*
* @return The unique_ptr to a PassVisualization proto
*/
std::unique_ptr<TbotsProto::PassVisualization> createPassVisualization(
std::unique_ptr<TbotsProto::PassVisualization> createPassVisualizationProto(
const std::vector<PassWithRating>& passes_with_rating);

/**
Expand All @@ -220,7 +221,8 @@ std::unique_ptr<TbotsProto::PassVisualization> createPassVisualization(
* a boolean value for whether world state proto has been received
*
*/
std::unique_ptr<TbotsProto::WorldStateReceivedTrigger> createWorldStateReceivedTrigger();
std::unique_ptr<TbotsProto::WorldStateReceivedTrigger>
createWorldStateReceivedTriggerProto();

/**
* Returns a cost visualization given a vector of costs
Expand All @@ -231,7 +233,7 @@ std::unique_ptr<TbotsProto::WorldStateReceivedTrigger> createWorldStateReceivedT
*
* @return The unique_ptr to a CostVisualization proto
*/
std::unique_ptr<TbotsProto::CostVisualization> createCostVisualization(
std::unique_ptr<TbotsProto::CostVisualization> createCostVisualizationProto(
const std::vector<double>& costs, int num_rows, int num_cols);

/**
Expand Down
Loading
Loading