diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 52c5df88..c87e5375 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -86,6 +86,8 @@ jobs: cd "$RUNNER_TEMP/grSim-download" unset QT_PLUGIN_PATH QT_QPA_PLATFORM_PLUGIN_PATH QML2_IMPORT_PATH DYLD_LIBRARY_PATH DYLD_FRAMEWORK_PATH ./grSim.app/Contents/MacOS/grSim --smoke-test + ./grSim.app/Contents/MacOS/grSim --smoke-test \ + --settings "$PWD/grSim.app/Contents/Resources/config/Utama-Field-20261028.xml" # Windows build does not work currently, see https://github.com/RoboCup-SSL/grSim/issues/183 # build-windows: diff --git a/CMakeLists.txt b/CMakeLists.txt index 35515373..bc9c1206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,7 +281,7 @@ foreach(dependency vartypes_external protobuf_external ode_external) endforeach() target_sources(${app} PRIVATE src/main.cpp) if(APPLE AND GRSIM_MACOSX_BUNDLE) - file(GLOB CONFIG_FILES "config/*.ini") + file(GLOB CONFIG_FILES "config/*.ini" "config/*.xml") set_source_files_properties(${CONFIG_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/config") set(app_icon "${PROJECT_SOURCE_DIR}/resources/icons/grsim.icns") set_source_files_properties("${app_icon}" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") @@ -324,9 +324,13 @@ if(BUILD_TESTING) target_sources(${app} PRIVATE tests/application_smoke.cpp) target_compile_definitions(${app} PRIVATE GRSIM_BUILD_SMOKE_TEST) add_test(NAME application_smoke COMMAND $ --smoke-test) + add_test(NAME application_smoke_field_profile COMMAND $ + --smoke-test --settings "${PROJECT_SOURCE_DIR}/config/Utama-Field-20261028.xml") + set_tests_properties(application_smoke_field_profile PROPERTIES + TIMEOUT 20 LABELS "opengl") set_tests_properties(application_smoke PROPERTIES TIMEOUT 20 LABELS "opengl") if(UNIX AND NOT APPLE) - set_tests_properties(application_smoke PROPERTIES + set_tests_properties(application_smoke application_smoke_field_profile PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=xcb;LIBGL_ALWAYS_SOFTWARE=1") endif() add_executable(grSim_timing_test tests/timing_regression.cpp) diff --git a/README.md b/README.md index 45701c42..aa37f23f 100644 --- a/README.md +++ b/README.md @@ -189,3 +189,32 @@ ER-Force 2016 fitted coefficients. These describe that team's field and ball, not a calibration of another setup. `--require-agreement` makes a reference mismatch return failure. Raw measurements and generated recordings should stay outside Git. + +### Utama physical-field calibration + +`config/Utama-Field-20261028.xml` selects the two measured robot models (yellow: +radio 0, blue: radio 1), six robots per side, and 0.20 m/s² ball rolling +deceleration. Start with `grSim --settings config/Utama-Field-20261028.xml`. +The file applies to this run; saved personal settings are unchanged. In a Mac +bundle it is under `grSim.app/Contents/Resources/config/`. + +The profiles use physical logs from 27–28 October in +[Utama-Core v2.5.0](https://github.com/First-Order-RoboCup-SSL/Utama-Core/releases/tag/v2.5.0). +SIM logs, the simulated tournament, uncertain 21 October logs, setup-only +segments and invalid starting states were excluded from fitting. Robot gains +were checked on held-out command steps, and ball rolling on held-out source logs. +Geometry and masses remain assumptions from Parsian; these logs do not measure +them. Response is validated for the observed drives (up to 1 m/s) and turns +(1–4 rad/s), not all possible commands. + +Local/global body-velocity commands use separate forward/left gains and angular +gain `AngularVelocityScale + AngularVelocityScaleSlope * abs(requested_turn)`. +Teleport velocity targets and raw wheel-speed commands keep their existing meaning. +General models retain unit +gains and zero slope. Camera/radio delay, vision noise, kicker charge and dribbler +loss are separate effects; this profile does not fit those into ODE or duplicate +an external hardware-noise layer. Use one actuator-response model in the stack. + +For physics comparisons, `grSim_replay --replay FILE --checkpoint-every 1` saves +every simulation tick. The default interval remains 30 ticks; diagnostics do not +change the fixed timestep or five ODE substeps. diff --git a/config/Utama-Field-20261028.xml b/config/Utama-Field-20261028.xml new file mode 100644 index 00000000..a9d759b3 --- /dev/null +++ b/config/Utama-Field-20261028.xml @@ -0,0 +1,18 @@ + + + + + + 6 + + Utama-Radio-0 + Utama-Radio-1 + + + + 0.20 + + + diff --git a/config/Utama-Radio-0.ini b/config/Utama-Radio-0.ini new file mode 100644 index 00000000..6a18d639 --- /dev/null +++ b/config/Utama-Radio-0.ini @@ -0,0 +1,43 @@ +; Utama physical robot on radio 0, 27-28 October2026 field logs. +; Geometry/mass are inherited Parsian assumptions; only body-response gains were fitted. +[Geometery] +CenterFromKicker= 0.073 +Radius = 0.09 +Height = 0.147 +RobotBottomZValue = 0.02 +KickerZValue = 0.005 +KickerThickness = 0.005 +KickerWidth = 0.08 +KickerHeight = 0.04 +WheelRadius = 0.027 +WheelThickness = 0.005 +Wheel1Angle = 60 +Wheel2Angle = 135 +Wheel3Angle = 225 +Wheel4Angle = 300 +[Physics] +Bodymass = 2 +Wheelmass = 0.2 +Kickermass =0.02 +KickerDampFactor = 0.2 +RollerTorqueFactor = 0.06 +RollerPerpendicularTorqueFactor = 0.005 +KickerFriction = 0.8 +WheelTangentFriction = 0.8 +WheelPerpendicularFriction = 0.05 +WheelMotorMaximumApplyingTorque= 0.2 + +MaxLinearKickSpeed=10 +MaxChipKickSpeed=10 +AccSpeedupAbsoluteMax=4 +AccSpeedupAngularMax=50 +AccBrakeAbsoluteMax=4 +AccBrakeAngularMax=50 +VelAbsoluteMax=5 +VelAngularMax=20 + +[Actuation] +ForwardVelocityScale=0.974 +LeftVelocityScale=0.958 +AngularVelocityScale=1.002 +AngularVelocityScaleSlope=0.021 diff --git a/config/Utama-Radio-1.ini b/config/Utama-Radio-1.ini new file mode 100644 index 00000000..9e7413e3 --- /dev/null +++ b/config/Utama-Radio-1.ini @@ -0,0 +1,43 @@ +; Utama physical robot on radio 1, 27-28 October2026 field logs. +; Geometry/mass are inherited Parsian assumptions; only body-response gains were fitted. +[Geometery] +CenterFromKicker= 0.073 +Radius = 0.09 +Height = 0.147 +RobotBottomZValue = 0.02 +KickerZValue = 0.005 +KickerThickness = 0.005 +KickerWidth = 0.08 +KickerHeight = 0.04 +WheelRadius = 0.027 +WheelThickness = 0.005 +Wheel1Angle = 60 +Wheel2Angle = 135 +Wheel3Angle = 225 +Wheel4Angle = 300 +[Physics] +Bodymass = 2 +Wheelmass = 0.2 +Kickermass =0.02 +KickerDampFactor = 0.2 +RollerTorqueFactor = 0.06 +RollerPerpendicularTorqueFactor = 0.005 +KickerFriction = 0.8 +WheelTangentFriction = 0.8 +WheelPerpendicularFriction = 0.05 +WheelMotorMaximumApplyingTorque= 0.2 + +MaxLinearKickSpeed=10 +MaxChipKickSpeed=10 +AccSpeedupAbsoluteMax=4 +AccSpeedupAngularMax=50 +AccBrakeAbsoluteMax=4 +AccBrakeAngularMax=50 +VelAbsoluteMax=5 +VelAngularMax=20 + +[Actuation] +ForwardVelocityScale=0.962 +LeftVelocityScale=0.924 +AngularVelocityScale=0.958 +AngularVelocityScaleSlope=0.023 diff --git a/include/robot.h b/include/robot.h index c55fbaef..2103127c 100644 --- a/include/robot.h +++ b/include/robot.h @@ -102,7 +102,7 @@ class Robot { ~Robot(); void step(); void setSpeed(int i,dReal s); //i = 0,1,2,3 - void setSpeed(dReal vx, dReal vy, dReal vw); + void setSpeed(dReal vx, dReal vy, dReal vw, bool applyResponse = true); dReal getSpeed(int i); void incSpeed(int i,dReal v); void resetSpeeds(); diff --git a/include/simulationsettings.h b/include/simulationsettings.h index 30e64506..1b95fee3 100644 --- a/include/simulationsettings.h +++ b/include/simulationsettings.h @@ -41,6 +41,11 @@ class RobotSettings { double AccBrakeAngularMax; double VelAbsoluteMax; double VelAngularMax; + // Measured body-velocity response to local/global velocity commands. + double ForwardVelocityScale = 1; + double LeftVelocityScale = 1; + double AngularVelocityScale = 1; + double AngularVelocityScaleSlope = 0; // gain per absolute commanded rad/s bool operator==(const RobotSettings& other) const { for (auto member : members()) if (this->*member != other.*member) return false; @@ -53,8 +58,8 @@ class RobotSettings { } private: - static const std::array& members() { - static const std::array values{{ + static const std::array& members() { + static const std::array values{{ &RobotSettings::RobotCenterFromKicker, &RobotSettings::RobotRadius, &RobotSettings::RobotHeight, &RobotSettings::BottomHeight, &RobotSettings::KickerZ, &RobotSettings::KickerThickness, @@ -70,7 +75,9 @@ class RobotSettings { &RobotSettings::MaxChipKickSpeed, &RobotSettings::AccSpeedupAbsoluteMax, &RobotSettings::AccSpeedupAngularMax, &RobotSettings::AccBrakeAbsoluteMax, &RobotSettings::AccBrakeAngularMax, &RobotSettings::VelAbsoluteMax, - &RobotSettings::VelAngularMax + &RobotSettings::VelAngularMax, &RobotSettings::ForwardVelocityScale, + &RobotSettings::LeftVelocityScale, &RobotSettings::AngularVelocityScale, + &RobotSettings::AngularVelocityScaleSlope }}; return values; } diff --git a/src/configwidget.cpp b/src/configwidget.cpp index 81e00bd6..ea48b697 100644 --- a/src/configwidget.cpp +++ b/src/configwidget.cpp @@ -20,6 +20,11 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim) #include #include +#include +#include +#include +#include +#include #define ADD_ENUM(type,name,Defaultvalue,namestring) \ v_##name = std::shared_ptr(new VarTypes::Var##type(namestring,Defaultvalue)); \ @@ -49,9 +54,26 @@ static QString robotConfigDirectory() return executable.absoluteFilePath("../config"); } +// Explicit settings are configuration input, not a request to silently use +// defaults. The implicit personal settings path keeps its historical fallback. +static void validateSettingsFile(const QString& path) +{ + QFile input(path); + if (!QFileInfo(path).isFile() || !input.open(QIODevice::ReadOnly)) + throw std::runtime_error("Requested settings must be an existing readable regular file"); + QXmlStreamReader xml(&input); + if (!xml.readNextStartElement() || xml.qualifiedName() != QLatin1String("VarXML") || + !xml.namespaceUri().isEmpty()) + throw std::runtime_error("Requested settings must have a VarXML root"); + while (!xml.atEnd()) xml.readNext(); + if (xml.hasError()) + throw std::runtime_error("Requested settings contain invalid XML"); +} + ConfigWidget::ConfigWidget(bool persist, const QString& settingsPath) : persistSettings(persist), settingsFile(settingsPath.isEmpty() ? QDir::homePath() + QString("/.grsim.xml") : settingsPath) { + if (!settingsPath.isEmpty()) validateSettingsFile(settingsPath); tmodel=new VarTreeModel(); this->setModel(tmodel); geo_vars = std::make_shared("Geometry"); @@ -332,6 +354,17 @@ void ConfigWidget::loadRobotSettings(QString team) robotSettings.AccBrakeAngularMax = robot_settings->value("Physics/AccBrakeAngularMax", 50).toDouble(); robotSettings.VelAbsoluteMax = robot_settings->value("Physics/VelAbsoluteMax", 5).toDouble(); robotSettings.VelAngularMax = robot_settings->value("Physics/VelAngularMax", 20).toDouble(); + auto velocityScale = [&](const char* name) { + const double value = robot_settings->value(QString("Actuation/") + name, 1.0).toDouble(); + if (std::isfinite(value) && value > 0) return value; + qWarning("Invalid %s in robot model; using unit response", name); + return 1.0; + }; + robotSettings.ForwardVelocityScale = velocityScale("ForwardVelocityScale"); + robotSettings.LeftVelocityScale = velocityScale("LeftVelocityScale"); + robotSettings.AngularVelocityScale = velocityScale("AngularVelocityScale"); + const double slope = robot_settings->value("Actuation/AngularVelocityScaleSlope", 0.0).toDouble(); + robotSettings.AngularVelocityScaleSlope = std::isfinite(slope) && slope >= 0 ? slope : 0; } SimulationSettings ConfigWidget::simulationSettings() diff --git a/src/main.cpp b/src/main.cpp index ebbf9d2b..10090556 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,9 +17,11 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim) */ #include #include "mainwindow.h" +#include +#include #ifdef GRSIM_BUILD_SMOKE_TEST -int runApplicationSmokeTest(QApplication& app); +int runApplicationSmokeTest(QApplication& app, const QString& settingsPath); #endif int main(int argc, char *argv[]) @@ -37,16 +39,28 @@ int main(int argc, char *argv[]) QCommandLineOption headlessOption(QStringList() << "H" << "headless", QCoreApplication::translate("main", "Run without a UI")); parser.addOption(headlessOption); + QCommandLineOption settingsOption("settings", + "Read an XML configuration for this run without changing saved settings.", "file"); + parser.addOption(settingsOption); #ifdef GRSIM_BUILD_SMOKE_TEST QCommandLineOption smokeOption("smoke-test", "Check application resources, rendering and UDP, then exit."); parser.addOption(smokeOption); #endif parser.process(a); + ConfigWidget* config = nullptr; + try { + if (parser.isSet(settingsOption) && parser.value(settingsOption).isEmpty()) + throw std::runtime_error("Expected a nonempty settings filename"); #ifdef GRSIM_BUILD_SMOKE_TEST - if (parser.isSet(smokeOption)) return runApplicationSmokeTest(a); + if (parser.isSet(smokeOption)) return runApplicationSmokeTest(a, parser.value(settingsOption)); #endif + if (parser.isSet(settingsOption)) config = new ConfigWidget(false, parser.value(settingsOption)); + } catch (const std::exception& error) { + std::fprintf(stderr, "%s\n", error.what()); + return 2; + } - MainWindow w; + MainWindow w(nullptr, config); if (parser.isSet(headlessOption)) { // enable headless mode w.hide(); diff --git a/src/robot.cpp b/src/robot.cpp index ad49539b..5b56ab47 100644 --- a/src/robot.cpp +++ b/src/robot.cpp @@ -415,8 +415,16 @@ void Robot::setSpeed(int i,dReal s) wheels[i]->speed = s; } -void Robot::setSpeed(dReal vx, dReal vy, dReal vw) +void Robot::setSpeed(dReal vx, dReal vy, dReal vw, bool applyResponse) { + if (applyResponse) { + vx *= settings.ForwardVelocityScale; + vy *= settings.LeftVelocityScale; + const double angularScale = settings.AngularVelocityScaleSlope == 0 + ? settings.AngularVelocityScale + : settings.AngularVelocityScale + settings.AngularVelocityScaleSlope * std::abs(vw); + vw *= angularScale; + } dReal _DEG2RAD = M_PI / 180.0; dReal v = sqrt(vx * vx + vy * vy); diff --git a/src/sslworld.cpp b/src/sslworld.cpp index d469cf53..98d500fd 100644 --- a/src/sslworld.cpp +++ b/src/sslworld.cpp @@ -773,7 +773,8 @@ void SSLWorld::processTeleportRobot(const TeleportRobot &teleBot, Robot *robot) dReal vxLocal = (vx * cos(-orientation)) - (vy * sin(-orientation)); dReal vyLocal = (vy * cos(-orientation)) + (vx * sin(-orientation)); - robot->setSpeed(vxLocal, vyLocal, vAngular); + // Teleport velocities are state targets, not hardware actuation commands. + robot->setSpeed(vxLocal, vyLocal, vAngular, false); if (teleBot.has_present()) { robot->on = teleBot.present(); diff --git a/tests/application_smoke.cpp b/tests/application_smoke.cpp index df9d7837..b3ef102c 100644 --- a/tests/application_smoke.cpp +++ b/tests/application_smoke.cpp @@ -17,7 +17,7 @@ // Run through the real executable and its installed resources; never read or // write personal settings. CTest and the relocated macOS artifact use this path. -int runApplicationSmokeTest(QApplication& app) +int runApplicationSmokeTest(QApplication& app, const QString& settingsPath) { QUdpSocket vision, feedback, reserve; if (!vision.bind(QHostAddress(QHostAddress::LocalHost), 0) || @@ -25,10 +25,13 @@ int runApplicationSmokeTest(QApplication& app) !reserve.bind(QHostAddress(QHostAddress::LocalHost), 0)) return 2; const quint16 controlPort = reserve.localPort(); reserve.close(); - auto* config = new ConfigWidget(false); - config->v_BlueTeam->setString("Parsian"); - config->v_YellowTeam->setString("Parsian"); - config->loadRobotsSettings(); + auto* config = new ConfigWidget(false, settingsPath); + if (settingsPath.isEmpty()) { + config->v_BlueTeam->setString("Parsian"); + config->v_YellowTeam->setString("Parsian"); + config->loadRobotsSettings(); + } + std::printf("Settings: rolling_deceleration=%.2f\n", config->BallRollingDeceleration()); const auto model = config->simulationSettings().blueSettings; const bool resources = std::abs(model.RobotHeight - 0.147) < 1e-9 && std::abs(model.WheelRadius - 0.027) < 1e-9; diff --git a/tests/check_physics_replay.py b/tests/check_physics_replay.py index df6b662d..7782d1fb 100644 --- a/tests/check_physics_replay.py +++ b/tests/check_physics_replay.py @@ -31,6 +31,11 @@ def run(args, accepted=True, step_seconds=1 / 60): assert result.returncode != 0, "invalid recording was accepted" +def message(field, payload): + assert len(payload) < 128 + return bytes([(field << 3) | 2, len(payload)]) + payload + + def difference(left, right): assert len(left["checkpoints"]) == len(right["checkpoints"]) maximum = 0 @@ -97,6 +102,33 @@ def difference(left, right): assert commanded["checkpoints"][0]["bodies"][0]["position"][0] == 2 assert commanded["checkpoints"][0]["simulation_time"] == document["initial"]["simulation_time"] print("PASS short and zero-tick capture timelines replay exactly, including terminal commands", flush=True) + # Explicit teleport velocities keep their historical unscaled semantics. + identity = b"\x08\x00\x10\x02" # robot 0, BLUE + velocity_fields = (b"\x2d" + struct.pack(" 1e-4, "changing accepted command ticks had no detectable effect" print("PASS negative control detects shifted command ticks", flush=True) + legacy = copy.deepcopy(document) + for model in ["robotSettings", "blueSettings", "yellowSettings"]: + for key in ["ForwardVelocityScale", "LeftVelocityScale", "AngularVelocityScale", "AngularVelocityScaleSlope"]: + del legacy["settings"][model][key] + changed.write_text(json.dumps(legacy)) + assert difference(serial, run(["--replay", str(changed)])) <= 1e-12 + print("PASS legacy v1 recordings retain exact unit-response physics", flush=True) variants = [] + for key, value in [("ForwardVelocityScale", 0), ("LeftVelocityScale", -1), + ("AngularVelocityScale", "not numeric"), ("AngularVelocityScaleSlope", -1)]: + invalid_gain = copy.deepcopy(document) + invalid_gain["settings"]["blueSettings"][key] = value + variants.append(invalid_gain) wrong_format = copy.deepcopy(document); wrong_format["format"] = "unknown" variants.append(wrong_format) missing = copy.deepcopy(document); del missing["settings"]["BallMass"] @@ -166,9 +224,6 @@ def difference(left, right): simulator_port = int(re.search(r"simulator=(\d+)", ready).group(1)) # Reject the whole batch before applying its ball or robot teleports, # including explicitly present false-valued unsupported flags. - def message(field, payload): - assert len(payload) < 128 - return bytes([(field << 3) | 2, len(payload)]) + payload identity = b"\x08\x00\x10\x02" # robot 0, BLUE teleport_robot = message(1, identity) + b"\x15" + struct.pack(" #include -#include #include -#include #include #include #include @@ -65,6 +63,11 @@ X(AccBrakeAngularMax) \ X(VelAbsoluteMax) \ X(VelAngularMax) +#define ROBOT_RESPONSE_FIELDS(X) \ + X(ForwardVelocityScale) \ + X(LeftVelocityScale) \ + X(AngularVelocityScale) \ + X(AngularVelocityScaleSlope) #define SIM_INT_FIELDS(X) \ X(Robots_Count) \ X(sendGeometryEvery) \ @@ -153,7 +156,7 @@ QJsonObject saveRobot(const RobotSettings& settings) { QJsonObject result; #define SAVE(name) result[#name] = settings.name; - ROBOT_FIELDS(SAVE) + ROBOT_FIELDS(SAVE) ROBOT_RESPONSE_FIELDS(SAVE) #undef SAVE return result; } @@ -163,11 +166,21 @@ RobotSettings loadRobot(const QJsonObject& object) #define LOAD(name) result.name = number(object, #name); ROBOT_FIELDS(LOAD) #undef LOAD + // Older v1 recordings have unit response, before these optional fields + // existed. Preserve their exact command/physics behaviour. +#define LOAD(name) if (object.contains(#name)) result.name = number(object, #name); + ROBOT_RESPONSE_FIELDS(LOAD) +#undef LOAD + if (result.ForwardVelocityScale <= 0 || result.LeftVelocityScale <= 0 || + result.AngularVelocityScale <= 0 || result.AngularVelocityScaleSlope < 0) + throw std::runtime_error("Invalid robot velocity response"); if (result.BodyMass <= 0 || result.WheelMass <= 0 || result.KickerMass <= 0 || result.RobotRadius <= 0 || result.RobotHeight <= 0 || result.WheelRadius <= 0 || result.WheelThickness <= 0) throw std::runtime_error("Invalid robot dimensions or mass"); - if (saveRobot(result).size() != object.size()) throw std::runtime_error("Unknown robot setting"); + const auto known = saveRobot(result); + for (auto field = object.begin(); field != object.end(); ++field) + if (!known.contains(field.key())) throw std::runtime_error("Unknown robot setting"); return result; } QJsonObject saveSettings(const SimulationSettings& settings) @@ -383,7 +396,7 @@ int main(int argc, char** argv) if (qEnvironmentVariableIsEmpty("QT_QPA_PLATFORM")) qputenv("QT_QPA_PLATFORM", "offscreen"); QApplication app(argc, argv); QString recordFile, replayFile, settingsFile, fixture; - unsigned helpers = 0, seed = 166, ticks = 180, durationMs = 0; + unsigned helpers = 0, seed = 166, ticks = 180, durationMs = 0, checkpointEvery = 30; unsigned ports[3] = {0, 0, 0}; try { for (int i = 1; i < argc; ++i) { @@ -402,6 +415,7 @@ int main(int argc, char** argv) else if (option == "--seed") seed = number; else if (option == "--ticks" && number > 0 && number <= 1000000) ticks = number; else if (option == "--duration-ms" && number >= 50 && number <= 120000) durationMs = number; + else if (option == "--checkpoint-every" && number > 0 && number <= 1000000) checkpointEvery = number; else if (option == "--blue-port" && number <= 65535) ports[0] = number; else if (option == "--yellow-port" && number <= 65535) ports[1] = number; else if (option == "--sim-port" && number <= 65535) ports[2] = number; @@ -428,20 +442,6 @@ int main(int argc, char** argv) throw std::runtime_error("Missing replay timeline"); settings = loadSettings(recording["settings"].toObject()); } else { - if (!settingsFile.isEmpty()) { - QFile input(settingsFile); - if (!QFileInfo(settingsFile).isFile() || !input.open(QIODevice::ReadOnly)) - throw std::runtime_error("Requested settings must be an existing readable regular file"); - // VarXML silently keeps defaults when parsing fails. Validate - // explicit input first so a recording cannot use another setup. - QXmlStreamReader xml(&input); - if (!xml.readNextStartElement() || xml.qualifiedName() != QLatin1String("VarXML") || - !xml.namespaceUri().isEmpty()) - throw std::runtime_error("Requested settings must have a VarXML root"); - while (!xml.atEnd()) xml.readNext(); - if (xml.hasError()) - throw std::runtime_error("Requested settings contain invalid XML"); - } ConfigWidget config(false, settingsFile); if (settingsFile.isEmpty()) { config.v_BlueTeam->setString("Parsian"); config.v_YellowTeam->setString("Parsian"); @@ -491,7 +491,7 @@ int main(int argc, char** argv) auto step = [&]() { world.stepPhysics(settings.DeltaTime(), PhysicsStepOptions(), &statistics); ++tick; - if (tick % 30 == 0) checkpoints.append(state(world, tick)); + if (tick % checkpointEvery == 0) checkpoints.append(state(world, tick)); }; auto accept = [&](const QJsonObject& event) { const auto response = apply(world, event); @@ -514,6 +514,8 @@ int main(int argc, char** argv) } accept(commandEvent(tick, "simulator_control", placement)); while (tick < ticks) { + // Fixture inputs have their own fixed schedule. Changing + // observation density must never alter the accepted commands. if (tick % 30 == 0) { for (int team = 0; team < 2; ++team) { RobotControl command; @@ -601,7 +603,7 @@ int main(int argc, char** argv) while (index < unsigned(events.size())) apply(world, events[int(index++)].toObject()); } - if (tick % 30 == 0) checkpoints.removeLast(); + if (tick % checkpointEvery == 0) checkpoints.removeLast(); checkpoints.append(state(world, tick)); recording["ticks"] = int(tick); recording["events"] = events;