12#include "units/base.h"
37 std::optional<argos_lib::swerve::SwerveModulePositions>
Load()
override;
64 bool Save(
const T& homePosition)
override {
67 std::ofstream configFile(
GetFilePath(), std::ios::out);
68 if (configFile.good()) {
69 configFile << homePosition.template to<double>();
70 if (!configFile.good()) {
71 std::cout <<
"[ERROR] Could not write to config file\n";
75 std::cout <<
"[ERROR] Could not open config file\n";
82 std::cout <<
"[ERROR] Could not write to config file\n";
87 std::optional<T>
Load()
override {
90 std::ifstream configFile(
GetFilePath(), std::ios::in);
92 if (configFile.peek() == std::ifstream::traits_type::eof()) {
97 configFile >> homePosition;
101 return units::make_unit<T>(homePosition);
107 std::cout <<
"[ERROR] Could not read from config file\n";
114 static const fs::path homeDir{
"/home/lvuser"};
117 std::cout <<
"############# Path: " << configFile <<
'\n';
120 if (!fs::exists(configFile)) {
121 fs::create_directories(configFile.parent_path());
122 std::ofstream newFile(configFile);
Saves and loads home positions from filesystem.
Definition fs_homing.h:55
bool Save(const T &homePosition) override
Save home position to persistent storage.
Definition fs_homing.h:64
fs::path GetFilePath()
Definition fs_homing.h:113
FSHomingStorage(const fs::path &homeFilePath)
Construct a new FSHomingStorage object.
Definition fs_homing.h:62
const fs::path m_homesPath
Definition fs_homing.h:129
std::optional< T > Load() override
Load home position from persistent storage.
Definition fs_homing.h:87
Interface capable of saving and loading home positions from persistent storage.
Definition homing_interface.h:39
Definition fs_homing.h:17
bool Save(const argos_lib::swerve::SwerveModulePositions &homePosition) override
Save positions as new homes.
Definition fs_homing.cpp:17
fs::path GetFilePath()
Get the path of the file to load from and save to.
Definition fs_homing.cpp:49
const fs::path m_swerveHomesPath
Path of persistent storage file relative to home directory.
Definition fs_homing.h:46
std::optional< argos_lib::swerve::SwerveModulePositions > Load() override
Load absolute positions that represent 0 degree module orientations.
Definition fs_homing.cpp:31
Interface capable of saving and loading module home positions from persistent storage.
Definition homing_interface.h:13
Definition swap_controllers_command.h:12
Representation of the absolute encoder position of each module at home position.
Definition swerve_utils.h:38