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
16 changes: 16 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# ChangeLog

## [1.9.1] - 2024-12-31

### Added
-

### Fixed
-

### Changed
- gRPC client timeout deadline is variable and can be set from start.sh
- Versioning: Proto Major - Proto Minor - Code

### Developers
- [NaderZare](https://github.com/naderzare)

=======
## [1.1.3] - 2024-12-15

### Added
Expand Down
5 changes: 5 additions & 0 deletions src/coach/main_coach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ main( int argc, char **argv )
bool add_20_to_grpc_port_if_right_side = false;
std::string grpc_ip = "localhost";
std::string rpc_type = "thrift";
int rpc_timeout = 3;

for (int i = 0; i < argc; ++i) {
if (std::string(argv[i]) == "--rpc-port") {
Expand All @@ -100,12 +101,16 @@ main( int argc, char **argv )
if (std::string(argv[i]) == "--rpc-type") {
rpc_type = argv[i+1];
}
if (std::string(argv[i]) == "--rpc-timeout") {
rpc_timeout = std::stoi(argv[i+1]);
}
}

agent.SetFirstRpcPort(grpc_port);
agent.SetUseSameRpcPort(use_same_grpc_port);
agent.SetAdd20ToRpcPortIfRightSide(add_20_to_grpc_port_if_right_side);
agent.SetRpcIp(grpc_ip);
agent.SetRpcTimeout(rpc_timeout);

bool use_thrift = rpc_type=="thrift";
#ifndef USE_GRPC
Expand Down
6 changes: 4 additions & 2 deletions src/coach/sample_coach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ SampleCoach::actionImpl()
M_rpc_server_address,
M_first_rpc_port,
M_use_same_rpc_port,
M_add_20_to_rpc_port_if_right_side);
M_add_20_to_rpc_port_if_right_side,
M_rpc_timeout);
#endif
}
else
Expand All @@ -224,7 +225,8 @@ SampleCoach::actionImpl()
M_rpc_server_address,
M_first_rpc_port,
M_use_same_rpc_port,
M_add_20_to_rpc_port_if_right_side);
M_add_20_to_rpc_port_if_right_side,
M_rpc_timeout);
#endif
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/grpc-client/grpc_client_coach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ void GrpcClientCoach::init(rcsc::SoccerAgent *agent,
std::string target,
int port,
bool use_same_grpc_port,
bool add_20_to_grpc_port_if_right_side)
bool add_20_to_grpc_port_if_right_side,
int rpc_timeout)
{
M_agent = static_cast<rcsc::CoachAgent *>(agent);
M_rpc_timeout = rpc_timeout;
M_rpc_timeout = rpc_timeout;
M_unum = 12;
M_team_name = M_agent->world().ourTeamName();
if (add_20_to_grpc_port_if_right_side)
Expand All @@ -57,6 +60,9 @@ void GrpcClientCoach::getActions()
state.set_allocated_register_response(response);
protos::CoachActions actions;
ClientContext context;
// Set the deadline to M_rpc_timeout second from now
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(M_rpc_timeout);
context.set_deadline(deadline);
Status status = M_stub_->GetCoachActions(&context, state, &actions);
if (!status.ok())
{
Expand Down
3 changes: 2 additions & 1 deletion src/grpc-client/grpc_client_coach.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class GrpcClientCoach : public GrpcClient {
std::string target="localhost",
int port=50051,
bool use_same_grpc_port=true,
bool add_20_to_grpc_port_if_right_side=false) override;
bool add_20_to_grpc_port_if_right_side=false,
int rpc_timeout=3) override;

void getActions();
State generateState() const;
Expand Down
8 changes: 5 additions & 3 deletions src/grpc-client/grpc_client_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ void GrpcClientPlayer::init(rcsc::SoccerAgent *agent,
std::string target,
int port,
bool use_same_grpc_port,
bool add_20_to_grpc_port_if_right_side)
bool add_20_to_grpc_port_if_right_side,
int rpc_timeout)
{
M_agent = static_cast<rcsc::PlayerAgent *>(agent);
M_rpc_timeout = rpc_timeout;
M_unum = M_agent->world().self().unum();
M_team_name = M_agent->world().ourTeamName();
if (add_20_to_grpc_port_if_right_side)
Expand Down Expand Up @@ -179,8 +181,8 @@ void GrpcClientPlayer::getActions()
state.set_allocated_register_response(response);
protos::PlayerActions actions;
ClientContext context;
// Set the deadline to 1 second from now
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(3);
// Set the deadline to M_rpc_timeout second from now
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(M_rpc_timeout);
context.set_deadline(deadline);

Status status = M_stub_->GetPlayerActions(&context, state, &actions);
Expand Down
3 changes: 2 additions & 1 deletion src/grpc-client/grpc_client_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class GrpcClientPlayer : public GrpcClient, public RpcPlayerClient
std::string target = "localhost",
int port = 50051,
bool use_same_grpc_port = true,
bool add_20_to_grpc_port_if_right_side = false) override;
bool add_20_to_grpc_port_if_right_side = false,
int rpc_timeout=3) override;

void updateChainByDefault(const rcsc::WorldModel &wm);
void updateChainByPlannerAction(const rcsc::WorldModel &wm, const protos::PlayerAction &action);
Expand Down
7 changes: 6 additions & 1 deletion src/grpc-client/grpc_client_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ void GrpcClientTrainer::init(rcsc::SoccerAgent *agent,
std::string target,
int port,
bool use_same_grpc_port,
bool add_20_to_grpc_port_if_right_side)
bool add_20_to_grpc_port_if_right_side,
int rpc_timeout)
{
M_agent = static_cast<rcsc::TrainerAgent *>(agent);
M_rpc_timeout = rpc_timeout;
M_unum = 13;
M_team_name = M_agent->world().ourTeamName();
if (add_20_to_grpc_port_if_right_side)
Expand All @@ -56,6 +58,9 @@ void GrpcClientTrainer::getActions()
state.set_allocated_register_response(response);
protos::TrainerActions actions;
ClientContext context;
// Set the deadline to M_rpc_timeout second from now
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(M_rpc_timeout);
context.set_deadline(deadline);
Status status = M_stub_->GetTrainerActions(&context, state, &actions);
if (!status.ok())
{
Expand Down
4 changes: 3 additions & 1 deletion src/grpc-client/grpc_client_trainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class GrpcClientTrainer : public GrpcClient {
rcsc::TrainerAgent * M_agent;
int M_rpc_timeout = 3;

public:
GrpcClientTrainer() ;
Expand All @@ -10,7 +11,8 @@ class GrpcClientTrainer : public GrpcClient {
std::string target="localhost",
int port=50051,
bool use_same_grpc_port=true,
bool add_20_to_grpc_port_if_right_side=false) override;
bool add_20_to_grpc_port_if_right_side=false,
int rpc_timeout=3) override;

void getActions();
State generateState() const;
Expand Down
5 changes: 5 additions & 0 deletions src/player/main_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ main( int argc, char **argv )
bool add_20_to_grpc_port_if_right_side = false;
std::string grpc_ip = "localhost";
std::string rpc_type = "thrift";
int rpc_timeout = 3;

for (int i = 0; i < argc; ++i) {
if (std::string(argv[i]) == "--rpc-port") {
Expand All @@ -99,12 +100,16 @@ main( int argc, char **argv )
if (std::string(argv[i]) == "--rpc-type") {
rpc_type = argv[i+1];
}
if (std::string(argv[i]) == "--rpc-timeout") {
rpc_timeout = std::stoi(argv[i+1]);
}
}

agent.SetFirstRpcPort(grpc_port);
agent.SetUseSameRpcPort(use_same_grpc_port);
agent.SetAdd20ToRpcPortIfRightSide(add_20_to_grpc_port_if_right_side);
agent.SetRpcIp(grpc_ip);
agent.SetRpcTimeout(rpc_timeout);

bool use_thrift = rpc_type=="thrift";

Expand Down
6 changes: 4 additions & 2 deletions src/player/sample_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ SamplePlayer::actionImpl()
M_rpc_server_address,
M_first_rpc_port,
M_use_same_rpc_port,
M_add_20_to_rpc_port_if_right_side);
M_add_20_to_rpc_port_if_right_side,
M_rpc_timeout);
#endif
}
else
Expand All @@ -251,7 +252,8 @@ SamplePlayer::actionImpl()
M_rpc_server_address,
M_first_rpc_port,
M_use_same_rpc_port,
M_add_20_to_rpc_port_if_right_side);
M_add_20_to_rpc_port_if_right_side,
M_rpc_timeout);
#endif
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/rpc-client/rpc-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class RpcAgent {
bool M_add_20_to_rpc_port_if_right_side;
std::string M_rpc_server_address;
bool M_use_thrift;
int M_rpc_timeout;

void SetFirstRpcPort(int port) { M_first_rpc_port = port; }
void SetUseSameRpcPort(bool use_same_grpc_port) { M_use_same_rpc_port = use_same_grpc_port; }
void SetAdd20ToRpcPortIfRightSide(bool add_20_to_grpc_port_if_right_side) { M_add_20_to_rpc_port_if_right_side = add_20_to_grpc_port_if_right_side; }
void SetRpcIp(std::string grpc_server_address) { M_rpc_server_address = grpc_server_address; }
void SetRpcTimeout(int timeout) { M_rpc_timeout = timeout; }
};
#endif //HELIOS_BASE_RPC_AGENT_H
4 changes: 3 additions & 1 deletion src/rpc-client/rpc-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class IRpcClient {
int M_unum;
std::string M_team_name;
bool M_param_sent = false;
int M_rpc_timeout = 3;


virtual bool connectToGrpcServer() = 0;
Expand All @@ -25,7 +26,8 @@ class IRpcClient {
std::string target="localhost",
int port=50051,
bool use_same_grpc_port=true,
bool add_20_to_grpc_port_if_right_side=false) = 0;
bool add_20_to_grpc_port_if_right_side=false,
int rpc_timeout=3) = 0;

bool isConnected() const{
return M_is_connected;
Expand Down
12 changes: 12 additions & 0 deletions src/start-agent.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rpc_port=50051
rpc_port_step="false"
rpc_add_20_to_port_for_right="false"
rpc_type="thrift"
rpc_timeout=3
coach_port=""
debug_server_host=""
debug_server_port=""
Expand Down Expand Up @@ -87,6 +88,7 @@ usage()
echo " --rpc-port-step specifies different rpc port for each player (default: false)"
echo " --rpc-add-20-to-port-for-right add 20 to RPC Port if team run on right side (default: false)"
echo " --rpc-type type of rpc framework (default: thrift) or grpc"
echo " --rpc-timeout specifies rpc timeout (default: 3)"
echo " --goalie specifies to run as a goalie"
echo " --player specifies to run as a player"
echo " --coach specifies to run as a coach"
Expand Down Expand Up @@ -131,6 +133,14 @@ do
rpc_type="${2}"
shift 1
;;
--rpc-timeout)
if [ $# -lt 2 ]; then
usage
exit 1
fi
rpc_timeout="${2}"
shift 1
;;
-h|--host)
if [ $# -lt 2 ]; then
usage
Expand Down Expand Up @@ -349,6 +359,7 @@ opt="${opt} ${debugopt}"
opt="${opt} --rpc-host ${rpc_host}"
opt="${opt} --rpc-port ${rpc_port}"
opt="${opt} --rpc-type ${rpc_type}"
opt="${opt} --rpc-timeout ${rpc_timeout}"
if [ "${rpc_port_step}" = "true" ]; then
opt="${opt} --rpc-port-step"
fi
Expand Down Expand Up @@ -379,6 +390,7 @@ if [ "${is_coach}" = "true" ]; then
coachopt="${coachopt} --rpc-host ${rpc_host}"
coachopt="${coachopt} --rpc-port ${rpc_port}"
coachopt="${coachopt} --rpc-type ${rpc_type}"
coachopt="${coachopt} --rpc-timeout ${rpc_timeout}"
if [ "${rpc_port_step}" = "true" ]; then
coachopt="${coachopt} --rpc-port-step"
fi
Expand Down
12 changes: 12 additions & 0 deletions src/start.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rpc_port=50051
rpc_port_step="false"
rpc_add_20_to_port_for_right="false"
rpc_type="thrift"
rpc_timeout=3
coach_port=""
debug_server_host=""
debug_server_port=""
Expand Down Expand Up @@ -89,6 +90,7 @@ usage()
echo " --rpc-port-step specifies different rpc port for each player (default: false)"
echo " --rpc-add-20-to-port-for-right add 20 to RPC Port if team run on right side (default: false)"
echo " --rpc-type type of rpc framework (default: thrift) or grpc"
echo " --rpc-timeout specifies rpc timeout (default: 3)"
echo " FULLSTATE_TYPE is one of [ignore|reference|override].") 1>&2
}

Expand Down Expand Up @@ -130,6 +132,14 @@ do
rpc_type="${2}"
shift 1
;;
--rpc-timeout)
if [ $# -lt 2 ]; then
usage
exit 1
fi
rpc_timeout="${2}"
shift 1
;;
-h|--host)
if [ $# -lt 2 ]; then
usage
Expand Down Expand Up @@ -354,6 +364,7 @@ opt="${opt} ${debugopt}"
opt="${opt} --rpc-host ${rpc_host}"
opt="${opt} --rpc-port ${rpc_port}"
opt="${opt} --rpc-type ${rpc_type}"
opt="${opt} --rpc-timeout ${rpc_timeout}"
if [ "${rpc_port_step}" = "true" ]; then
opt="${opt} --rpc-port-step"
fi
Expand Down Expand Up @@ -411,6 +422,7 @@ if [ "${usecoach}" = "true" ]; then
coachopt="${coachopt} --rpc-host ${rpc_host}"
coachopt="${coachopt} --rpc-port ${rpc_port}"
coachopt="${coachopt} --rpc-type ${rpc_type}"
coachopt="${coachopt} --rpc-timeout ${rpc_timeout}"
if [ "${rpc_port_step}" = "true" ]; then
coachopt="${coachopt} --rpc-port-step"
fi
Expand Down
4 changes: 3 additions & 1 deletion src/thrift-client/thrift_client_coach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ void ThriftClientCoach::init(rcsc::SoccerAgent *agent,
std::string target,
int port,
bool use_same_grpc_port,
bool add_20_to_grpc_port_if_right_side)
bool add_20_to_grpc_port_if_right_side,
int rpc_timeout)
{
M_agent = static_cast<rcsc::CoachAgent *>(agent);
M_rpc_timeout = rpc_timeout;
M_unum = 12;
M_team_name = M_agent->world().ourTeamName();
if (add_20_to_grpc_port_if_right_side)
Expand Down
3 changes: 2 additions & 1 deletion src/thrift-client/thrift_client_coach.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class ThriftClientCoach : public ThriftAgent {
std::string target="localhost",
int port=50051,
bool use_same_grpc_port=true,
bool add_20_to_grpc_port_if_right_side=false) override;
bool add_20_to_grpc_port_if_right_side=false,
int rpc_timeout=3) override;

void getActions();
soccer::State generateState() const;
Expand Down
4 changes: 3 additions & 1 deletion src/thrift-client/thrift_client_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ void ThriftClientPlayer::init(rcsc::SoccerAgent *agent,
std::string target,
int port,
bool use_same_grpc_port,
bool add_20_to_grpc_port_if_right_side)
bool add_20_to_grpc_port_if_right_side,
int rpc_timeout)
{
M_agent = static_cast<rcsc::PlayerAgent *>(agent);
M_rpc_timeout = rpc_timeout;
M_unum = M_agent->world().self().unum();
M_team_name = M_agent->world().ourTeamName();
if (add_20_to_grpc_port_if_right_side)
Expand Down
3 changes: 2 additions & 1 deletion src/thrift-client/thrift_client_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ThriftClientPlayer : public ThriftAgent, public RpcPlayerClient {
std::string target="localhost",
int port=50051,
bool use_same_grpc_port=true,
bool add_20_to_grpc_port_if_right_side=false) override;
bool add_20_to_grpc_port_if_right_side=false,
int rpc_timeout=3) override;

void updateChainByDefault(const rcsc::WorldModel &wm);
void updateChainByPlannerAction(const rcsc::WorldModel &wm, const soccer::PlayerAction &action);
Expand Down
Loading