Skip to content

Commit

Permalink
Add Training State to APP Reinforcement Learning
Browse files Browse the repository at this point in the history
  • Loading branch information
Akram authored and Akram committed Aug 5, 2024
1 parent d47c8cf commit c11acae
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 0 deletions.
91 changes: 91 additions & 0 deletions lib/APPReinforcementLearning/src/TrainingState.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* MIT License
*
* Copyright (c) 2023 - 2024 Andreas Merkle <[email protected]>
*
* 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 <StateMachine.h>
#include <DifferentialDrive.h>

/******************************************************************************
* 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
*****************************************************************************/
137 changes: 137 additions & 0 deletions lib/APPReinforcementLearning/src/TrainingState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* MIT License
*
* Copyright (c) 2023 - 2024 Andreas Merkle <[email protected]>
*
* 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 <stdint.h>
#include <IState.h>
#include <SimpleTimer.h>

/******************************************************************************
* 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
*****************************************************************************/

0 comments on commit c11acae

Please sign in to comment.