Skip to content

Commit

Permalink
Copied LineFollower App; renamed it SensorFusion
Browse files Browse the repository at this point in the history
  • Loading branch information
jkerpe committed Oct 27, 2023
1 parent a232640 commit abee565
Show file tree
Hide file tree
Showing 19 changed files with 2,922 additions and 0 deletions.
113 changes: 113 additions & 0 deletions lib/SensorFusion/App.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* MIT License
*
* Copyright (c) 2023 Andreas Merkle <web@blue-andi.de>
*
* 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 LineFollower application
* @author Andreas Merkle <web@blue-andi.de>
*/

/******************************************************************************
* Includes
*****************************************************************************/
#include "App.h"
#include "StartupState.h"
#include <Board.h>
#include <Speedometer.h>
#include <DifferentialDrive.h>
#include <Odometry.h>
#include <Util.h>

/******************************************************************************
* Compiler Switches
*****************************************************************************/

/******************************************************************************
* Macros
*****************************************************************************/

/******************************************************************************
* Types and classes
*****************************************************************************/

/******************************************************************************
* Prototypes
*****************************************************************************/

/******************************************************************************
* Local Variables
*****************************************************************************/

/******************************************************************************
* Public Methods
*****************************************************************************/

void App::setup()
{
Serial.begin(SERIAL_BAUDRATE);
Board::getInstance().init();
m_systemStateMachine.setState(&StartupState::getInstance());
m_controlInterval.start(DIFFERENTIAL_DRIVE_CONTROL_PERIOD);
}

void App::loop()
{
Speedometer::getInstance().process();

if (true == m_controlInterval.isTimeout())
{
/* The differential drive control needs the measured speed of the
* left and right wheel. Therefore it shall be processed after
* the speedometer.
*/
DifferentialDrive::getInstance().process(DIFFERENTIAL_DRIVE_CONTROL_PERIOD);

/* The odometry unit needs to detect motor speed changes to be able to
* calculate correct values. Therefore it shall be processed right after
* the differential drive control.
*/
Odometry::getInstance().process();

m_controlInterval.restart();
}

m_systemStateMachine.process();
}

/******************************************************************************
* Protected Methods
*****************************************************************************/

/******************************************************************************
* Private Methods
*****************************************************************************/

/******************************************************************************
* External Functions
*****************************************************************************/

/******************************************************************************
* Local Functions
*****************************************************************************/
108 changes: 108 additions & 0 deletions lib/SensorFusion/App.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* MIT License
*
* Copyright (c) 2023 Andreas Merkle <web@blue-andi.de>
*
* 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 LineFollower application
* @author Andreas Merkle <web@blue-andi.de>
*
* @addtogroup Application
*
* @{
*/

#ifndef APP_H
#define APP_H

/******************************************************************************
* Compile Switches
*****************************************************************************/

/******************************************************************************
* Includes
*****************************************************************************/
#include <StateMachine.h>
#include <SimpleTimer.h>
#include <Arduino.h>

/******************************************************************************
* Macros
*****************************************************************************/

/******************************************************************************
* Types and Classes
*****************************************************************************/

/** The line follower application. */
class App
{
public:
/**
* Construct the line follower application.
*/
App() : m_systemStateMachine(), m_controlInterval()
{
}

/**
* Destroy the line follower application.
*/
~App()
{
}

/**
* Setup the application.
*/
void setup();

/**
* Process the application periodically.
*/
void loop();

private:
/** Differential drive control period in ms. */
static const uint32_t DIFFERENTIAL_DRIVE_CONTROL_PERIOD = 5U;

/** Baudrate for Serial Communication */
static const uint32_t SERIAL_BAUDRATE = 115200U;

/** The system state machine. */
StateMachine m_systemStateMachine;

/** Timer used for differential drive control processing. */
SimpleTimer m_controlInterval;

App(const App& app);
App& operator=(const App& app);
};

/******************************************************************************
* Functions
*****************************************************************************/

#endif /* APP_H */
/** @} */
Loading

0 comments on commit abee565

Please sign in to comment.