Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set seed value using CLI #1618

Merged
merged 5 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions src/cmd/cmdsim.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ COMMANDS = { 'sim' =>
" --log-compress When recording, compress final log files. \n"\
" Only valid if recording is enabled. \n"\
"\n"\
" --seed Pass a custom seed value to the random \n"\
adityapande-1995 marked this conversation as resolved.
Show resolved Hide resolved
" number generator. \n"\
"\n"\
" --playback [arg] Use logging system to play back states. \n"\
" Argument is path to recorded states. \n"\
"\n"\
Expand Down Expand Up @@ -221,7 +224,8 @@ class Cmd
'physics_engine' => '',
'render_engine_gui' => '',
'render_engine_server' => '',
'headless-rendering' => 0
'headless-rendering' => 0,
'seed' => 0
}

usage = COMMANDS[args[0]]
Expand Down Expand Up @@ -310,6 +314,9 @@ class Cmd
opts.on('--version') do
options['version'] = '1'
end
opts.on('--seed', Integer) do |i|
options['seed'] = i
end

end # opt_parser do

Expand Down Expand Up @@ -482,7 +489,7 @@ See https://github.com/gazebosim/gz-sim/issues/44 for more info."
options['playback'], options['physics_engine'],
options['render_engine_server'], options['render_engine_gui'],
options['file'], options['record-topics'].join(':'),
options['headless-rendering'])
options['headless-rendering'], options['seed'])
end

guiPid = Process.fork do
Expand Down Expand Up @@ -518,7 +525,7 @@ See https://github.com/gazebosim/gz-sim/issues/44 for more info."
options['playback'], options['physics_engine'],
options['render_engine_server'], options['render_engine_gui'],
options['file'], options['record-topics'].join(':'),
options['headless-rendering'])
options['headless-rendering'], options['seed'])
# Otherwise run the gui
else options['gui']
if plugin.end_with? ".dylib"
Expand Down
7 changes: 6 additions & 1 deletion src/gz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extern "C" int runServer(const char *_sdfString,
const char *_playback, const char *_physicsEngine,
const char *_renderEngineServer, const char *_renderEngineGui,
const char *_file, const char *_recordTopics,
int _headless)
int _headless, int _seed)
{
gz::sim::ServerConfig serverConfig;

Expand Down Expand Up @@ -347,6 +347,11 @@ extern "C" int runServer(const char *_sdfString,
serverConfig.SetRenderEngineGui(_renderEngineGui);
}

if (_seed != 0)
{
serverConfig.SetSeed(_seed);
}

// Create the Gazebo server
gz::sim::Server server(serverConfig);

Expand Down
3 changes: 2 additions & 1 deletion src/gz.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern "C" const char *worldInstallDir();
/// \param[in] _recordTopics Colon separated list of topics to record. Leave
/// null to record the default topics.
/// \param[in] _headless True if server rendering should run headless
/// \param[in] _seed --seed value to be used for random number generator.
/// \return 0 if successful, 1 if not.
extern "C" int runServer(const char *_sdfString,
int _iterations, int _run, float _hz, int _levels,
Expand All @@ -63,7 +64,7 @@ extern "C" int runServer(const char *_sdfString,
int _logCompress, const char *_playback,
const char *_physicsEngine, const char *_renderEngineServer,
const char *_renderEngineGui, const char *_file,
const char *_recordTopics, int _headless);
const char *_recordTopics, int _headless, int _seed);

/// \brief External hook to run simulation GUI.
/// \param[in] _guiConfig Path to Gazebo GUI configuration file.
Expand Down