Skip to content

Commit

Permalink
fix: moves hash check before sim_time check
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPL1 committed Dec 5, 2024
1 parent 25ef3ea commit d59d1c6
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions mujoco_ros/src/mujoco_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ MujocoEnv *MujocoEnv::instance = nullptr;

MujocoEnv::MujocoEnv(const std::string &admin_hash /* = std::string()*/)
{
if (!admin_hash.empty()) {
mju::strcpy_arr(settings_.admin_hash, admin_hash.c_str());
}

nh_->param<bool>("eval_mode", settings_.eval_mode, false);
if (settings_.eval_mode) {
ROS_INFO("Running in evaluation mode. Parsing admin hash...");
if (!settings_.admin_hash[0]) {
ROS_ERROR_NAMED("mujoco", "Evaluation mode requires a hash to verify critical operations are allowed. No "
"hash was provided, aborting launch.");
settings_.exit_request = 1;
throw std::runtime_error(
"Evaluation mode requires a hash to verify critical operations are allowed. No hash was "
"provided, aborting launch.");
}
}

if (!ros::param::get("/use_sim_time", settings_.use_sim_time)) {
ROS_FATAL_NAMED("mujoco", "/use_sim_time ROS param is unset. This node requires you to explicitly set it to true "
"or false. Also Make sure it is set before starting any node, "
Expand Down Expand Up @@ -115,25 +132,6 @@ MujocoEnv::MujocoEnv(const std::string &admin_hash /* = std::string()*/)
}
ROS_INFO_STREAM("Compiled with render backend: " << render_backend);

if (!admin_hash.empty()) {
mju::strcpy_arr(settings_.admin_hash, admin_hash.c_str());
}

nh_->param<bool>("eval_mode", settings_.eval_mode, false);
if (settings_.eval_mode) {
ROS_INFO("Running in evaluation mode. Parsing admin hash...");
if (!settings_.admin_hash[0]) {
ROS_ERROR_NAMED("mujoco", "Evaluation mode requires a hash to verify critical operations are allowed. No "
"hash was provided, aborting launch.");
settings_.exit_request = 1;
throw std::runtime_error(
"Evaluation mode requires a hash to verify critical operations are allowed. No hash was "
"provided, aborting launch.");
}
} else {
ROS_INFO("Running in normal training mode.");
}

nh_->param<bool>("render_offscreen", settings_.render_offscreen, true);
if (settings_.render_offscreen) {
mjv_makeScene(nullptr, &offscreen_.scn, Viewer::kMaxGeom);
Expand Down

0 comments on commit d59d1c6

Please sign in to comment.