Skip to content

Add/implement energy metrics#75

Merged
SaltyJoss merged 14 commits intoDevfrom
add/implement_energy_metrics
Feb 23, 2026
Merged

Add/implement energy metrics#75
SaltyJoss merged 14 commits intoDevfrom
add/implement_energy_metrics

Conversation

@SaltyJoss
Copy link
Owner

This pull request introduces batch mode support to the simulation engine, enabling command-line execution of multiple simulation runs with configurable parameters. The changes add new batch-related entry points, argument parsing, and integrate batch functionality into the build system. Additionally, the build configuration is updated to include new headers and source files, and some unused scene-related files are removed.

Batch mode functionality:

  • Added new batch entry point (BatchMain.cpp) and supporting headers (BatchEntry.h, BatchArgs.h) to enable running simulations in batch mode via command-line arguments. ([[1]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-2a016f49e99426052a1f0c9a1ae48081be701c3b8767dd10f8be669431be476eR1-R19), [[2]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-4c538a6d8d5ec795af8306b70d3069005463b0a2b2dbd488ca809a17d00ba94bR1-R3), [[3]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-058af05fc29e9955a6897926d40c0f4a17344c0247ccb04eb1ec34d580bef942R1-R132))
  • Modified Main.cpp to parse batch-specific arguments, validate them, and delegate execution to the batch entry point when the --batch flag is present. ([Sim_Engine/Engine/src/Main.cppR2-R166](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-02056878299abb44028bd3b057128c802d19bb9238ecdf55f1c3da933c0a4250R2-R166))

Build system updates:

  • Updated Engine.vcxproj and Engine.vcxproj.filters to include new batch source and header files, and set up appropriate include directories for batch mode dependencies (including Eigen). ([[1]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-62beac1f3052cae8cf7e65e6c31278785269ca76154a39b50c4a157929d66503L60-R60), [[2]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-62beac1f3052cae8cf7e65e6c31278785269ca76154a39b50c4a157929d66503L90-R90), [[3]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-62beac1f3052cae8cf7e65e6c31278785269ca76154a39b50c4a157929d66503R114), [[4]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-62beac1f3052cae8cf7e65e6c31278785269ca76154a39b50c4a157929d66503R142-R145), [[5]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-c8c42c5ee651e9760de79e8a8b570d11c05a619f44194d20533497f23ad93477R10-R12), [[6]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-c8c42c5ee651e9760de79e8a8b570d11c05a619f44194d20533497f23ad93477R21-R23), [[7]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-c8c42c5ee651e9760de79e8a8b570d11c05a619f44194d20533497f23ad93477R93-R100))

Cleanup and refactoring:

  • Removed unused scene-related files (MeshLoader.h, VertexHolder.h, MeshLoader.cpp) from the build configuration and filters, and moved relevant headers to assets and platform directories. ([[1]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-749d9a81240905e28ef4b6934f1d6f00e807035614bc0b2c1d683cb400865c79R182-R183), [[2]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-749d9a81240905e28ef4b6934f1d6f00e807035614bc0b2c1d683cb400865c79R215-R226), [[3]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-749d9a81240905e28ef4b6934f1d6f00e807035614bc0b2c1d683cb400865c79L245-L251), [[4]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-749d9a81240905e28ef4b6934f1d6f00e807035614bc0b2c1d683cb400865c79L387), [[5]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-8b55ccce9346a3dcd5555c53c11f7707c81b7f56e3630dd79b2266bafbc7b4a9L234-L236), [[6]](https://github.com/SaltyJoss/RoboticArm_MathModelling/pull/75/files#diff-8b55ccce9346a3dcd5555c53c11f7707c81b7f56e3630dd79b2266bafbc7b4a9L303-L305))

Disclaimer:
In the interst of time, I generated this summary with GitHub Copilot, then checked it!

NOTES:
- The idea is to introduce a thread-safe, double-buffered internal logging system for joint metrics, I am so fed up of the current logger.
- Added JointLogEntry struct, push_entry, and validate methods to MetricLogger.
- Implemented claimExportLogBuffer, useInternalLogBuffer, and reserveInternalLogBuffers to manage buffer swapping and allocation. (assisted by forums and AI to correct minor mistakes)
- Updated simulation loop to use internal buffers by default, with support for external buffers if needed.
NOTES:
- IntroduceD Interactive/Synchronous run modes to SimulationCore WITH dynamical sizing log and reference buffers based on mode to prevent OOM (new acronym learnt) errors.
- Moved joint log buffer management into the robot system, with export and clearing handled via new interfaces.
- Refactored exportLogsToHDF5 for validation, timing, and robust logging.
- Added buffer size validation to exportRefsToHDF5.

TODO:
- Now implementing batch parallelisation
    * I WANT TO VERY CLEAR -> this does not affect my current dissertation, but I really cannot be bothered waiting for all my tests to finish because my thread util is 100%.
NOTES:
- Major refactor to decouple simulation core from GUI by introducing ISimulationCore, a headless API for scripting and batch operation.
    * This has taken ~7hours, learnt a lot though!!
- Added StudyRunner for parallel/batch simulation runs and BatchMain for CLI batch mode.
- Interpreter contexts now use ISimulationCore*, enabling headless scripting!
- Moveded MeshLoader and VertexHolder to Assets namespace -> updated all mesh/vertex code accordingly.
- Addeded integration method enum header.

TODO:
- Go through and MAKE SURE it is working (it loads, but cannot verify right now, commit is to save progress)
NOTES:
- Major refactor for thread-safe parallel simulation and integrator comparison
- Batch mode now uses hardware concurrency, times runs, and sorts results.
- StudyRunner and GUI now launch async simulation tasks, poll results, and handle exceptions robustly.
- Integrator comparison runs each method in parallel, results are sorted and displayed when ready.
- Added thread-safe result handling in SimManager and ControlPanel.
- SSAO kernel generation uses C++ RNG for reproducibility.
- Script integrator replacement uses regex for reliability.
- Improved OpenGL resource cleanup and modularity.
- UI is more responsive; background runs do not block main thread.

TODO:
- Make parallelisation Universal
NOTES:
- Added StudyRunner to SimManager for batch/background studies.
- Introduced thread-safe result handling and integration method querying in ISimulationCore.
- Refactored CommandScriptEditor to use StudyRunner for background runs.
- Tweaked telemetry and comparison results collection in ControlPanel (I want to spend some time fixing the entire class honestly, but after).
- "Standardised" simulation core factory usage and cleaned up declarations (I think there is a lot of work to be done here though).

TODO:
- Get parallelisation working with runs on gui.
NOTES:
- Refactored SimulationCore to manage RobotSystem, PhysicsSystem, TrajectoryManager, and object container with std::unique_ptr for improved memory safety and automatic cleanup.
- Updated factory and setter/getter methods accordingly (just to allow for batch runs using these systems).
- Added ENGINE_API to paths functions for DLL compatibility.
- BatchMain.cpp now initialises paths and includes expanded batch script and debug logging.

TODO:
- Fixed HDF5 to be thread-safe, it currently is not.
- Run tests, and finish report, I HAVE LOTS OF NOTES

DISCLAIMER:
- Some changes in this commit were assisted using AI, as I am finding this interesting but also difficult, NOTES HAVE BEEN MADE SO I CAN LEARN :)
NOTES:
- Add DataManager destructor/finalise() for explicit cleanup of HDF5 writers
- Include thread ID and ms timestamp in HDF5 filenames to avoid collisions
- Add debug helpers and print statements for shutdown tracing
- Protect HDF5 file creation with a mutex for thread safety
- In batch mode, force single worker thread for determinism
- Ensure simulation stops and data is flushed on script completion
- Minor code/comment cleanups and improved timestamp formatting
NOTES:
- Introduced BatchArgs struct for batch mode argument handling.
- Refactored BatchMain.cpp/Main.cpp for improved parsing and validation.
- Batch mode now actually supports flexible sweeps of timesteps and integrators, with output tags generated from run parameters.
- HDF5 file naming updated to use run tags (HONESTLY WORTH IT).
- Project files updated to include BatchArgs.h.
- BatchEntry.h now accepts BatchArgs.
- Batch mode is now user-friendly.
NOTES:
- Refactored SimulationCore to allow construction with either internally owned subsystems or externally provided references.
- Added separate unique_ptr and raw pointer members to enable flexible integration as a standalone core or within a larger system that manages subsystems externally.

TODO:
- Find cause of "invalid delete" error upon close, MSVC debug heap detects then invalid delte and triggers a debug break, but its midnight and im tired, and it still works soooo.
@SaltyJoss SaltyJoss self-assigned this Feb 22, 2026
@SaltyJoss SaltyJoss added documentation Improvements or additions to documentation enhancement New feature or request fixes fixing existing issues labels Feb 22, 2026
NOTES:
- Refactored SimulationCore to allow construction with either internally owned subsystems or externally provided references.
- Added separate unique_ptr and raw pointer members to enable flexible integration as a standalone core or within a larger system that manages subsystems externally.

TODO:
- Find cause of "invalid delete" error upon close, MSVC debug heap detects then invalid delte and triggers a debug break, but its midnight and im tired, and it still works soooo.

ALTERNATIVELY:
- Believe I found a fix, amending previous commit
@SaltyJoss SaltyJoss merged commit dd3b25a into Dev Feb 23, 2026
2 checks passed
@SaltyJoss SaltyJoss deleted the add/implement_energy_metrics branch February 23, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request fixes fixing existing issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant