diff --git a/lib/APPReinforcementLearning/src/TrainingState.cpp b/lib/APPReinforcementLearning/src/TrainingState.cpp new file mode 100644 index 00000000..91e91597 --- /dev/null +++ b/lib/APPReinforcementLearning/src/TrainingState.cpp @@ -0,0 +1,91 @@ +/* MIT License + * + * Copyright (c) 2023 - 2024 Andreas Merkle + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/******************************************************************************* + DESCRIPTION +*******************************************************************************/ +/** + * @brief Training state + * @author Akram Bziouech + */ + +/****************************************************************************** + * Includes + *****************************************************************************/ +#include "TrainingState.h" +#include +#include + +/****************************************************************************** + * Compiler Switches + *****************************************************************************/ + +/****************************************************************************** + * Macros + *****************************************************************************/ + +/****************************************************************************** + * Types and classes + *****************************************************************************/ + +/****************************************************************************** + * Prototypes + *****************************************************************************/ + +/****************************************************************************** + * Local Variables + *****************************************************************************/ + +/****************************************************************************** + * Public Methods + *****************************************************************************/ + +void TrainingState::entry() +{ + DifferentialDrive& diffDrive = DifferentialDrive::getInstance(); + diffDrive.setLinearSpeed(0, 0); + diffDrive.disable(); +} + +void TrainingState::process(StateMachine& sm) +{ + /* Nothing to do. */ + (void)sm; +} + +void TrainingState::exit() +{ + DifferentialDrive::getInstance().enable(); +} + +/****************************************************************************** + * Protected Methods + *****************************************************************************/ + +/****************************************************************************** + * Private Methods + *****************************************************************************/ + +/****************************************************************************** + * External Functions + *****************************************************************************/ diff --git a/lib/APPReinforcementLearning/src/TrainingState.h b/lib/APPReinforcementLearning/src/TrainingState.h new file mode 100644 index 00000000..737d7a89 --- /dev/null +++ b/lib/APPReinforcementLearning/src/TrainingState.h @@ -0,0 +1,137 @@ +/* MIT License + * + * Copyright (c) 2023 - 2024 Andreas Merkle + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/******************************************************************************* + DESCRIPTION +*******************************************************************************/ +/** + * @brief Training state + * @author Akram Bziouech + * + * @addtogroup Application + * + * @{ + */ + +#ifndef TRAINING_STATE_H +#define TRAINING_STATE_H + +/****************************************************************************** + * Compile Switches + *****************************************************************************/ + +/****************************************************************************** + * Includes + *****************************************************************************/ +#include +#include +#include + +/****************************************************************************** + * Macros + *****************************************************************************/ + +/****************************************************************************** + * Types and Classes + *****************************************************************************/ + +/** The system Training state. */ +class TrainingState : public IState +{ +public: + /** + * Get state instance. + * + * @return State instance. + */ + static TrainingState& getInstance() + { + static TrainingState instance; + + /* Singleton idiom to force initialization during first usage. */ + + return instance; + } + + /** + * If the state is entered, this method will called once. + */ + void entry() final; + + /** + * Processing the state. + * + * @param[in] sm State machine, which is calling this state. + */ + void process(StateMachine& sm) final; + + /** + * If the state is left, this method will be called once. + */ + void exit() final; + +protected: +private: + /** + * Default constructor. + */ + TrainingState() + { + } + + /** + * Default destructor. + */ + ~TrainingState() + { + } + + /** + * Copy construction of an instance. + * Not allowed. + * + * @param[in] state Source instance. + */ + TrainingState(const TrainingState& state); + + /** + * Assignment of an instance. + * Not allowed. + * + * @param[in] state Source instance. + * + * @returns Reference to Training instance. + */ + TrainingState& operator=(const TrainingState& state); +}; + +/****************************************************************************** + * Functions + *****************************************************************************/ + +#endif /* TRAINING_STATE_H */ +/** @} */ + +/****************************************************************************** + * Local Functions + *****************************************************************************/