Fixes to touch_grid config parsing.
PiperOrigin-RevId: 530561729 Change-Id: I67f6dfd137aa54ce2141e5d5c30b5b888665c4a2
This commit is contained in:
committed by
Copybara-Service
parent
4c487e07ed
commit
b36c611745
+22
-22
@@ -177,52 +177,52 @@ TouchGrid* TouchGrid::Create(const mjModel* m, mjData* d,
|
|||||||
int nchannel = strtod(mj_getPluginConfig(m, instance, "nchannel"), nullptr);
|
int nchannel = strtod(mj_getPluginConfig(m, instance, "nchannel"), nullptr);
|
||||||
if (!nchannel) nchannel = 1;
|
if (!nchannel) nchannel = 1;
|
||||||
if (nchannel < 1 || nchannel > 6) {
|
if (nchannel < 1 || nchannel > 6) {
|
||||||
mju_warning("nchannel must be between 1 and 6");
|
mju_error("nchannel must be between 1 and 6");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// size
|
// size
|
||||||
std::vector<int> size;
|
std::vector<int> size;
|
||||||
std::vector<mjtNum> fov;
|
std::string size_str = std::string(mj_getPluginConfig(m, instance, "size"));
|
||||||
ReadVector(
|
ReadVector(size, size_str.c_str());
|
||||||
size, std::string(mj_getPluginConfig(m, instance, "size")).c_str());
|
if (size.size()!= 2) {
|
||||||
ReadVector(
|
mju_error("Both horizontal and vertical resolutions must be specified");
|
||||||
fov, std::string(mj_getPluginConfig(m, instance, "fov")).c_str());
|
|
||||||
if (size[0] < 0 || size[1] < 0) {
|
|
||||||
mju_warning("Horizontal and vertical resolutions must be positive");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (size.size()!= 2) {
|
if (size[0] <= 0 || size[1] <= 0) {
|
||||||
mju_warning("Both horizontal and vertical resolutions must be specified");
|
mju_error("Horizontal and vertical resolutions must be positive");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// field of view
|
// field of view
|
||||||
|
std::vector<mjtNum> fov;
|
||||||
|
std::string fov_str = std::string(mj_getPluginConfig(m, instance, "fov"));
|
||||||
|
ReadVector(fov, fov_str.c_str());
|
||||||
|
if (fov.size()!= 2) {
|
||||||
|
mju_error(
|
||||||
|
"Both horizontal and vertical fields of view must be specified");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
if (fov[0] <= 0 || fov[0] > 180) {
|
if (fov[0] <= 0 || fov[0] > 180) {
|
||||||
mju_warning("`fov[0]` must be a float between (0, 180] degrees");
|
mju_error("`fov[0]` must be a float between (0, 180] degrees");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (fov[1] <= 0 || fov[1] > 90) {
|
if (fov[1] <= 0 || fov[1] > 90) {
|
||||||
mju_warning("`fov[1]` must be a float between (0, 90] degrees");
|
mju_error("`fov[1]` must be a float between (0, 90] degrees");
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
if (fov.size()!= 2) {
|
|
||||||
mju_warning(
|
|
||||||
"Both horizontal and vertical fields of view must be specified");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// gamma
|
// gamma
|
||||||
mjtNum gamma = strtod(mj_getPluginConfig(m, instance, "gamma"), nullptr);
|
mjtNum gamma = strtod(mj_getPluginConfig(m, instance, "gamma"), nullptr);
|
||||||
if (gamma < 0 || gamma > 1) {
|
if (gamma < 0 || gamma > 1) {
|
||||||
mju_warning("`gamma` must be a nonnegative float between [0, 1]");
|
mju_error("`gamma` must be a nonnegative float between [0, 1]");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TouchGrid(m, d, instance, nchannel, size.data(), fov.data(),
|
return new TouchGrid(m, d, instance, nchannel, size.data(), fov.data(),
|
||||||
gamma);
|
gamma);
|
||||||
} else {
|
} else {
|
||||||
mju_warning("Invalid or missing parameters in touch_grid sensor plugin");
|
mju_error("Invalid or missing parameters in touch_grid sensor plugin");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,7 +489,7 @@ void TouchGrid::RegisterPlugin() {
|
|||||||
plugin.name = "mujoco.sensor.touch_grid";
|
plugin.name = "mujoco.sensor.touch_grid";
|
||||||
plugin.capabilityflags |= mjPLUGIN_SENSOR;
|
plugin.capabilityflags |= mjPLUGIN_SENSOR;
|
||||||
|
|
||||||
// Parameterized by 5 attributes.
|
// Parameterized by 4 attributes.
|
||||||
const char* attributes[] = {"nchannel", "size", "fov", "gamma"};
|
const char* attributes[] = {"nchannel", "size", "fov", "gamma"};
|
||||||
plugin.nattribute = sizeof(attributes) / sizeof(attributes[0]);
|
plugin.nattribute = sizeof(attributes) / sizeof(attributes[0]);
|
||||||
plugin.attributes = attributes;
|
plugin.attributes = attributes;
|
||||||
@@ -502,8 +502,8 @@ void TouchGrid::RegisterPlugin() {
|
|||||||
int nchannel = strtod(mj_getPluginConfig(m, instance, "nchannel"), nullptr);
|
int nchannel = strtod(mj_getPluginConfig(m, instance, "nchannel"), nullptr);
|
||||||
if (!nchannel) nchannel = 1;
|
if (!nchannel) nchannel = 1;
|
||||||
std::vector<int> size;
|
std::vector<int> size;
|
||||||
ReadVector(
|
std::string size_str = std::string(mj_getPluginConfig(m, instance, "size"));
|
||||||
size, std::string(mj_getPluginConfig(m, instance, "size")).c_str());
|
ReadVector(size, size_str.c_str());
|
||||||
return nchannel * size[0] * size[1];
|
return nchannel * size[0] * size[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user