Skip to content
Snippets Groups Projects
Commit 85982a08 authored by Matteo Pignataro's avatar Matteo Pignataro
Browse files

[PayloadTest] First structure commit

parent c61402b1
Branches
Tags
No related merge requests found
/* Copyright (c) 2022 Skyward Experimental Rocketry
* Author: Matteo Pignataro
*
* 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.
*/
/**
* This class specifies the sensors constants that the sensor manager
* needs to know about every device. For example the sample time is
* essential to understand how much time a sensor should wait before
* another sample.
*/
#pragma once
#include <sensors/LIS3DSH/LIS3DSH.h>
namespace ParafoilTest
{
static constexpr unsigned int SAMPLE_PERIOD_ACCEL_LIS3DSH = 2; //2 millis
static constexpr LIS3DSH::OutputDataRate ACCEL_LIS3DSH_ODR = LIS3DSH::ODR_800_HZ;
static constexpr LIS3DSH::BlockDataUpdate ACCEL_LIS3DSH_BDU = LIS3DSH::UPDATE_AFTER_READ_MODE;
static constexpr LIS3DSH::FullScale ACCEL_LIS3DSH_FULL_SCALE = LIS3DSH::FULL_SCALE_2G;
}
\ No newline at end of file
/* Copyright (c) 2022 Skyward Experimental Rocketry
* Author: Matteo Pignataro
*
* 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.
*/
#include <Configs/SensorsConfig.h>
#include "Sensors.h"
using std::bind;
//using std::function;
using namespace Boardcore;
namespace ParafoilTest
{
/**
* PRIVATE METHODS
*/
void Sensors::initLIS3DSH()
{
//CS PIN which we use to enable the dialgue with the sensor
GpioPin cs(GPIOE_BASE, 3);
cs.mode(miosix::Mode::OUTPUT);
accel_sensor = new LIS3DSH(spiInterface,
cs,
ACCEL_LIS3DSH_ORD,
ACCEL_LIS3DSH_BDU,
ACCEL_LIS3DSH_FULL_SCALE);
accel_sensor -> init();
//Create the sensor description binding it to the sample period,
//its callback function and if it is DMA access and enabled.
SensorInfo info("LIS3DSH", SAMPLE_PERIOD_ACCEL_LIS3DSH,
bind(&Sensors::LIS3DSHCallback, this), false, true);
//Adding the sensor to the sensors map
sensors_map.emplace(std::make_pair(accel_sensor, info));
}
void Sensors::LIS3DSHCallback()
{
LoggerService::getInstance() -> log(accel_sensor -> getLastSample());
}
/**
* PUBLIC METHODS
*/
Sensors::Sensors(SPIBusInterface& spi, TaskScheduler* scheduler)
: spiInterface(spi)
{
//Sensor init
initLIS3DSH();
//Sensor manager instance
//At this point sensors_map contains all the initialized sensors
manager = new SensorManager(scheduler, sensors_map);
}
Sensors::~Sensors()
{
//Delete the sensors
delete accel_sensor;
//Sensor manager stop and delete
manager -> stop();
delete manager;
}
bool Sensors::start()
{
return manager -> start();
}
void Sensors::calibrate()
{
}
}
\ No newline at end of file
/* Copyright (c) 2022 Skyward Experimental Rocketry
* Author: Matteo Pignataro
*
* 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.
*/
#pragma once
#include <sensors/SensorManager.h>
#include <sensors/LIS3DSH/LIS3DSH.h>
using namespace Boardcore;
/**
* This class memorizes all the sensors instances.
* Every instance is initialized by the constructor. Also every
* sensor has its own status
*/
namespace ParafoilTest
{
class Sensors
{
private:
/**
* @brief Sensor manager object
*/
SensorManager* manager;
/**
* @brief Sensor map that contains every sensor istance
* that needs to be sampled by the sensor manager
*/
SensorManager::SensorMap_t sensors_map;
/**
* @brief SPI interface passed via constructor
*/
SPIBusInterface& spiInterface;
/**
* @brief initializes the LIS3DSH method
*/
void initLIS3DSH();
void LIS3DSHcallback();
public:
LIS3DSH* accel_sensor;
/**
* @brief Constructor
* @param The spi interface used for the sensors
* @param The task scheduler
*/
Sensors(SPIBusInterface& spi, TaskScheduler* scheduler);
/**
* @brief Deconstructor
*/
~Sensors();
/**
* @brief Starts the sensor manager to sample data
* @return boolean that indicates operation's result
*/
bool start();
/**
* @brief Calibrates the sensors that need to
*/
void calibrate();
}
}
\ No newline at end of file
/* Copyright (c) 2022 Skyward Experimental Rocketry
* Author: Matteo Pignataro
*
* 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.
*/
#pragma once
#include <Common.h>
#include <Main/Sensors.h>
using namespace Boardcore;
/**
* This class is the main singleton that keeps all the project objects.
* It has all the instances and initializes all of them.
*/
namespace ParafoilTest
{
class PayloadTest : public Singleton<PayloadTest>
{
private:
/**
* @brief Constructor
*/
PayloadTest()
{
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment