VSS-SampleCpp 
Essa é a documentação do VSS-SampleCpp, que utiliza a biblioteca VSS-CoreCpp. Para voltar para a documentação do VSS-SDK, clique aqui.
#include <Communications/StateReceiver.h>
#include <Communications/CommandSender.h>
#include <Communications/DebugSender.h>
#include "cstdlib"
using namespace vss;
IStateReceiver *stateReceiver;
ICommandSender *commandSender;
IDebugSender *debugSender;
State state;
void send_commands();
void send_debug();
int main(int argc, char** argv){
srand(time(NULL));
stateReceiver = new StateReceiver();
commandSender = new CommandSender();
debugSender = new DebugSender();
stateReceiver->createSocket();
commandSender->createSocket(TeamType::Yellow);
debugSender->createSocket(TeamType::Yellow);
while(true){
state = stateReceiver->receiveState(FieldTransformationType::None);
send_commands();
send_debug();
}
return 0;
}
void send_commands(){
Command command;
for(int i = 0 ; i < 3 ; i++){
WheelsCommand wheelsCommand;
wheelsCommand.leftVel = 10;
wheelsCommand.rightVel = -10;
command.commands.push_back(wheelsCommand);
}
commandSender->sendCommand(command);
}
void send_debug(){
vss::Debug debug;
for(unsigned int i = 0 ; i < 3 ; i++){
vss::Point point;
point.x = state.teamYellow[i].x - 10 + rand()%20;
point.y = state.teamYellow[i].y - 10 + rand()%20;
debug.stepPoints.push_back(point);
}
for(unsigned int i = 0 ; i < 3 ; i++){
vss::Pose pose;
pose.x = state.teamYellow[i].x - 10 + rand()%20;
pose.y = state.teamYellow[i].y - 10 + rand()%20;
pose.angle = state.teamYellow[i].y - 10 + rand()%20;
debug.finalPoses.push_back(pose);
}
for(unsigned int i = 0 ; i < 3 ; i++){
vss::Path path;
vss::Point point_1;
vss::Point point_2;
point_1.x = state.teamYellow[i].x;
point_1.y = state.teamYellow[i].y;
point_2.x = state.ball.x - 10 + rand()%20;
point_2.y = state.ball.y - 10 + rand()%20;
path.points.push_back(point_1);
path.points.push_back(point_2);
}
debugSender->sendDebug(debug);
}
Utilização
Assumindo que você já tenha instalado o VSS-SDK, principalmente o VSS-CoreCpp. Para utilizar o exemplo basta executar os seguintes comandos.
Obs: O VSS-CoreCpp é exatamente o VSS-Core utilizado no VSS-SDK
VSS-SampleCpp
git clone https://github.com/VSS-SDK/VSS-SampleCpp
cd VSS-SampleCpp
sudo ./configure.sh
cd build
./vss-sample
VSS-CoreCpp 
O VSS-CoreCpp é exatamente o VSS-Core utilizado pelo VSS-SDK nos demais projetos. Inclusive é utilizado no VSS-SampleCpp. Também está em desenvolvimento um VSS-CoreRust e um VSS-CorePy.
Aqui são listados as constantes, modelos, interfaces de comunicação, helpers e builders que podem auxiliar na construção de estratégias.
Domínio
Dentro do domínio de futebol de robôs existem algumas constantes e estruturas de dados que são utilizadas em todos os projetos do SDK e podem ser utilizados em estratégias também.
Constantes
Constants.h
namespace vss {
// Space Constraints
const int MIN_COORDINATE_X = 0;
const int MAX_COORDINATE_X = 170;
const int MIN_COORDINATE_Y = 0;
const int MAX_COORDINATE_Y = 130;
const int MIN_ANGLE_VALUE = 0;
const int MAX_ANGLE_VALUE = 360;
// Randomization
const int MAX_RANDOM_VELOCITY = 5;
const int MAX_RANDOM_PATH_SIZE = 10;
const int MAX_RANDOM_TEAM_SIZE = 11;
const int MAX_RANDOM_WHEEL_COMMAND = 10;
const int MAX_RANDOM_IP_VALUE = 255;
const int MAX_RANDOM_PORT_VALUE = 20000;
// Communication
const int DEFAULT_STATE_PORT = 5555;
const int DEFAULT_CMD_YELLOW_PORT = 5556;
const int DEFAULT_CMD_BLUE_PORT = 5557;
const int DEFAULT_DEBUG_YELLOW_PORT = 5558;
const int DEFAULT_DEBUG_BLUE_PORT = 5559;
const int DEFAULT_CTRL_PORT = 5560;
const std::string DEFAULT_STATE_SEND_ADDR = "tcp://*";
const std::string DEFAULT_STATE_RECV_ADDR = "tcp://localhost";
const std::string DEFAULT_CMD_SEND_ADDR = "tcp://localhost";
const std::string DEFAULT_CMD_RECV_ADDR = "tcp://*";
const std::string DEFAULT_DEBUG_SEND_ADDR = "tcp://localhost";
const std::string DEFAULT_DEBUG_RECV_ADDR = "tcp://*";
const std::string DEFAULT_CTRL_SEND_ADDR = "tcp://*";
const std::string DEFAULT_CTRL_RECV_ADDR = "tcp://localhost";
// Enums
const TeamType DEFAULT_TEAM_TYPE = TeamType::Yellow;
const SideAttackType DEFAULT_SIDE_ATTACK_TYPE = SideAttackType::Left;
const TimeExecutionType DEFAULT_TIME_EXECUTION_TYPE = TimeExecutionType::Normal;
const EnvironmentType DEFAULT_ENVIRONMENT_TYPE = EnvironmentType::Simulation;
const DurationType DEFAULT_DURATION_TYPE = DurationType::TenMinutes;
const MatchFinishType DEFAULT_MATCH_FINISH_TYPE = MatchFinishType::TenGoalsDifference;
}
Enums
Domain/DurationType.h
namespace vss {
enum DurationType{
TenMinutes = 0,
UnlimitedMinutes = 1
};
std::string toDescription(DurationType);
DurationType toDurationType(std::string);
}
Domain/EnvironmentType.h
namespace vss {
enum EnvironmentType{
Simulation = 0,
Real = 1
};
std::string toDescription(EnvironmentType);
EnvironmentType toEnvironmentType(std::string);
}
Domain/FieldTransformationType.h
namespace vss {
enum FieldTransformationType{
None = 0,
Flip180Degrees = 1
};
std::string toDescription(FieldTransformationType);
FieldTransformationType toFieldTransformationType(std::string);
}
Domain/MatchFinishType.h
namespace vss {
enum MatchFinishType{
TenGoalsDifference = 0,
TimeUp = 1
};
std::string toDescription(MatchFinishType);
MatchFinishType toMatchFinishType(std::string);
}
Domain/SideAttackType.h
namespace vss {
enum SideAttackType{
Left = 0,
Right = 1
};
std::string toDescription(SideAttackType);
SideAttackType toSideAttackType(std::string);
}
Domain/TimeExecutionType.h
namespace vss {
enum TimeExecutionType {
Normal = 0,
Fast = 1
};
std::string toDescription(TimeExecutionType);
TimeExecutionType toTimeExecutionType(std::string);
}
Domain/TeamType.h
namespace vss {
enum TeamType{
Yellow = 0,
Blue = 1
};
std::string toDescription(TeamType);
TeamType toTeamType(std::string);
}
Modelos básicos
Domain/Point.h
namespace vss {
class Point {
public:
Point();
Point(float x, float y);
friend std::ostream& operator<<(std::ostream& os, const Point& point);
float x;
float y;
};
}
Domain/Pose.h
namespace vss {
class Pose : public Point {
public:
Pose();
Pose(float x, float y, float angle);
friend std::ostream& operator<<(std::ostream& os, const Pose& pose);
float angle;
};
}
Domain/Ball.h
namespace vss {
class Ball : public Point {
public:
Ball();
Ball(float x, float y, float speedX, float speedY);
friend std::ostream& operator<<(std::ostream& os, const Ball& ball);
float speedX;
float speedY;
};
}
Domain/Robot.h
amespace vss {
class Robot : public Pose {
public:
Robot();
Robot(float x, float y, float angle, float speedX, float speedY, float speedAngle);
friend std::ostream& operator<<(std::ostream& os, const Robot& robot);
float speedX;
float speedY;
float speedAngle;
};
}
Domain/Path.h
namespace vss {
class Path {
public:
Path();
Path(std::vector<Point> points);
friend std::ostream& operator<<(std::ostream& os, const Path& path);
std::vector<Point> points;
};
}
WheelsCommand.h
namespace vss {
class WheelsCommand {
public:
WheelsCommand();
WheelsCommand(int id, float leftVel, float rightVel);
friend std::ostream& operator<<(std::ostream& os, const WheelsCommand& wheelsCommand);
int id;
float leftVel;
float rightVel;
};
}
Modelos de configuração
Domain/ExecutionConfig.h
namespace vss {
class ExecutionConfig {
public:
ExecutionConfig();
friend std::ostream& operator<<(std::ostream& os, const ExecutionConfig& executionConfig);
// Communications
Address stateRecvAddr;
Address stateSendAddr;
Address cmdYellowRecvAddr;
Address cmdYellowSendAddr;
Address debugYellowRecvAddr;
Address debugYellowSendAddr;
Address cmdBlueRecvAddr;
Address cmdBlueSendAddr;
Address debugBlueRecvAddr;
Address debugBlueSendAddr;
Address ctrlRecvAddr;
Address ctrlSendAddr;
// Enums
TeamType teamType;
SideAttackType sideAttackType;
TimeExecutionType timeExecutionType;
EnvironmentType environmentType;
DurationType durationType;
MatchFinishType matchFinishType;
// Others
std::string teamInitialPositionPath;
bool isValidConfiguration;
};
}
Modelos de comunicação
Domain/Address.h
namespace vss {
class Address {
public:
Address();
Address(std::string ip, int port);
friend std::ostream& operator<<(std::ostream& os, const Address& address);
void setIp(std::string ip);
void setPort(int port);
std::string getIp();
int getPort();
std::string getFullAddress();
std::string ip;
int port;
};
}
Domain/State.h
namespace vss {
class State {
public:
State();
State(Ball ball, std::vector<Robot> teamBlue, std::vector<Robot> teamYellow);
friend std::ostream& operator<<(std::ostream& os, const State& state);
Ball ball;
std::vector<Robot> teamBlue;
std::vector<Robot> teamYellow;
};
}
Domain/Command.h
namespace vss {
class Command {
public:
Command();
Command(int id, std::vector<WheelsCommand> commands);
friend std::ostream& operator<<(std::ostream& os, const Command& command);
int id;
std::vector<WheelsCommand> commands;
};
}
Domain/Debug.h
namespace vss {
class Debug {
public:
Debug();
Debug(std::vector<Point> stepPoints, std::vector<Pose> finalPoses, std::vector<Path> paths);
friend std::ostream& operator<<(std::ostream& os, const Debug& debug);
std::vector<Point> stepPoints;
std::vector<Pose> finalPoses;
std::vector<Path> paths;
};
}
Domain/Control.h
namespace vss {
class Control {
public:
Control();
Control(bool paused, Ball ball, std::vector<Robot> teamYellow, std::vector<Robot> teamBlue);
friend std::ostream& operator<<(std::ostream& os, const Control& control);
bool paused;
Ball ball;
std::vector<Robot> teamYellow;
std::vector<Robot> teamBlue;
};
}
Interfaces de comunicação
Interfaces/IStateReceiver.h, Communications/StateReceiver.h
namespace vss{
class StateReceiver : public IStateReceiver {
public:
StateReceiver();
void createSocket(Address) override;
void createSocket() override;
State receiveState(FieldTransformationType) override;
};
}
Interfaces/IStateSender.h, Communications/StateSender.h
namespace vss{
class StateSender : public IStateSender {
public:
StateSender();
void createSocket(Address) override;
void createSocket() override;
void sendState(State) override;
};
}
Interfaces/ICommandSender.h, Communications/CommandSender.h
namespace vss {
class CommandSender : public ICommandSender {
public:
CommandSender();
void createSocket(Address) override;
void createSocket(TeamType) override;
void sendCommand(Command) override;
};
}
Interfaces/IDebugReceiver.h, Communications/DebugReceiver.h
namespace vss {
class DebugReceiver : public IDebugReceiver {
public:
DebugReceiver();
void createSocket(Address) override;
void createSocket(TeamType) override;
Debug receiveDebug() override;
};
}
Interfaces/IDebugSender.h, Communications/DebugSender.h
namespace vss {
class DebugSender : public IDebugSender {
public:
DebugSender();
void createSocket(Address) override;
void createSocket(TeamType) override;
void sendDebug(Debug) override;
};
}
Interfaces/IControlReceiver.h, Communications/ControlReceiver.h
namespace vss {
class ControlReceiver : public IControlReceiver {
public:
ControlReceiver();
void createSocket(Address) override;
void createSocket() override;
Control receiveControl() override;
};
}
Interfaces/IControlSender.h, Communications/ControlSender.h
namespace vss {
class ControlSender : public IControlSender {
public:
ControlSender();
void createSocket(Address) override;
void createSocket() override;
void sendControl(Control) override;
};
}
Enviando comandos
#include "Interfaces/ICommandSender.h"
#include "Communications/CommandSender.h"
#include "Domain/Command.h"
using namespace vss;
int main(int argc, char** argv){
ICommandSender commandSender = new CommandSender();
commandSender->createSocket(TeamType::Yellow);
while(true){
Command command;
commandSender->sendCommand(command);
}
return 0;
}
Obtendo estados
#include "Interfaces/IStateReceiver.h"
#include "Communications/StateReceiver.h"
#include "Domain/State.h"
using namespace vss;
int main(int argc, char** argv){
IStateReceiver *stateReceiver = new StateReceiver();
stateReceiver->createSocket();
while(true){
State state = stateReceiver->receiveState(FieldTransformationType::None);
}
return 0;
}
Interprete de configuração
Builders/StdinInterpreterBuilder.h
namespace vss {
class StdinInterpreterBuilder : public IStdinInterpreterBuilder {
public:
StdinInterpreterBuilder();
IStdinInterpreter* buildInterpreter() override;
IStdinInterpreterBuilder* onStateRecvAddr() override;
IStdinInterpreterBuilder* onStateSendAddr() override;
IStdinInterpreterBuilder* onYellowCmdRecvAddr() override;
IStdinInterpreterBuilder* onYellowCmdSendAddr() override;
IStdinInterpreterBuilder* onYellowDebugRecvAddr() override;
IStdinInterpreterBuilder* onYellowDebugSendAddr() override;
IStdinInterpreterBuilder* onBlueCmdRecvAddr() override;
IStdinInterpreterBuilder* onBlueCmdSendAddr() override;
IStdinInterpreterBuilder* onBlueDebugRecvAddr() override;
IStdinInterpreterBuilder* onBlueDebugSendAddr() override;
IStdinInterpreterBuilder* onCtrlRecvAddr() override;
IStdinInterpreterBuilder* onCtrlSendAddr() override;
IStdinInterpreterBuilder* onStatePort() override;
IStdinInterpreterBuilder* onYellowCmdPort() override;
IStdinInterpreterBuilder* onYellowDebugPort() override;
IStdinInterpreterBuilder* onBlueCmdPort() override;
IStdinInterpreterBuilder* onBlueDebugPort() override;
IStdinInterpreterBuilder* onCtrlPort() override;
IStdinInterpreterBuilder* onTeamType() override;
IStdinInterpreterBuilder* onSideAttackType() override;
IStdinInterpreterBuilder* onTimeExecutionType() override;
IStdinInterpreterBuilder* onEnvironmentType() override;
IStdinInterpreterBuilder* onDurationType() override;
IStdinInterpreterBuilder* onMatchFinishType() override;
IStdinInterpreterBuilder* onTeamInitialPositionPath() override;
protected:
IStdinInterpreter *stdinInterpreter;
};
}
Interpreters/StdinInterpreter.h
namespace vss {
class StdinInterpreter : public IStdinInterpreter {
public:
StdinInterpreter();
ExecutionConfig extractExecutionConfig(int argc, char **argv) override;
protected:
ExecutionConfig stdinConfiguration;
boost::program_options::options_description buildOptions();
void buildConfiguration(boost::program_options::variables_map);
};
}