@@ -8,7 +8,7 @@ namespace aimrt_mujoco_sim::mujoco_sim_module::common {
88std::optional<int32_t > GetJointSensorIdByJointName (const mjModel* m, std::string_view joint_name, mjtSensor sensor_type) {
99 int32_t jointId = mj_name2id (m, mjOBJ_JOINT, joint_name.data ());
1010 if (jointId < 0 ) {
11- AIMRT_ERROR_THROW (" Invalid joint name: {}." , joint_name);
11+ AIMRT_ERROR_THROW (" Invalid joint name: {}, cannot find a joint sensor ." , joint_name);
1212 return std::nullopt ;
1313 }
1414
@@ -34,7 +34,7 @@ std::optional<int32_t> GetJointactfrcIdByJointName(const mjModel* m, std::string
3434
3535std::optional<std::string> GetJointSensorNameByJointName (const mjModel* m, std::string_view joint_name, mjtSensor sensor_type) {
3636 if (auto sensor_id = GetJointSensorIdByJointName (m, joint_name, sensor_type)) {
37- return mj_id2name (m, mjOBJ_SENSOR, * sensor_id);
37+ return mj_id2name (m, mjOBJ_SENSOR, sensor_id. value_or (- 1 ) );
3838 }
3939 return std::nullopt ;
4040}
@@ -54,7 +54,7 @@ std::optional<std::string> GetJointactfrcNameByJointName(const mjModel* m, std::
5454std::optional<int32_t > GetJointActIdByJointName (const mjModel* m, std::string_view joint_name) {
5555 int32_t joint_id = mj_name2id (m, mjOBJ_JOINT, joint_name.data ());
5656 if (joint_id < 0 ) {
57- AIMRT_ERROR_THROW (" Invalid joint name: {}." , joint_name);
57+ AIMRT_ERROR_THROW (" Invalid joint name: {}, cannot find a joint actuator ." , joint_name);
5858 return std::nullopt ;
5959 }
6060
@@ -67,10 +67,10 @@ std::optional<int32_t> GetJointActIdByJointName(const mjModel* m, std::string_vi
6767}
6868
6969std::optional<std::string> GetJointActNameByJointName (const mjModel* m, std::string_view joint_name) {
70- int32_t actuatorId = GetJointActIdByJointName (m, joint_name.data ()). value_or (- 1 );
71- if (actuatorId < 0 ) return std:: nullopt ;
72-
73- return mj_id2name (m, mjOBJ_ACTUATOR, actuatorId) ;
70+ if ( auto actuator_id = GetJointActIdByJointName (m, joint_name.data ())) {
71+ return mj_id2name (m, mjOBJ_ACTUATOR, actuator_id. value_or (- 1 )) ;
72+ }
73+ return std:: nullopt ;
7474}
7575
7676std::optional<std::string> GetJointActTypeByJointName (const mjModel* m, std::string_view joint_name) {
@@ -115,6 +115,8 @@ std::optional<std::string> GetJointActTypeByJointName(const mjModel* m, std::str
115115}
116116
117117std::optional<int32_t > GetSensorIdBySensorName (const mjModel* m, std::string_view sensor_name) {
118+ if (sensor_name.empty ()) return std::nullopt ;
119+
118120 int32_t sensor_id = mj_name2id (m, mjOBJ_SENSOR, sensor_name.data ());
119121 if (sensor_id < 0 ) {
120122 AIMRT_ERROR_THROW (" Invalid sensor name: {}." , sensor_name);
0 commit comments