From 05cd96d2b221b09ddf62e9ff3ddbaac5e280b8d3 Mon Sep 17 00:00:00 2001 From: RobertPatzke <robert.patzke@mfp-portal.de> Date: Mon, 7 Nov 2022 08:01:35 +0100 Subject: [PATCH] Update 20221107-1 --- libraries/ProcMeas/ProcMeas.cpp | 97 +++++++++++++++++++++++++++++ libraries/ProcMeas/ProcMeas.h | 106 ++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 libraries/ProcMeas/ProcMeas.cpp create mode 100644 libraries/ProcMeas/ProcMeas.h diff --git a/libraries/ProcMeas/ProcMeas.cpp b/libraries/ProcMeas/ProcMeas.cpp new file mode 100644 index 0000000..bd0fd7e --- /dev/null +++ b/libraries/ProcMeas/ProcMeas.cpp @@ -0,0 +1,97 @@ +//----------------------------------------------------------------------------- +// Thema: Social Manufacturing Network / Process Measurements +// Datei: ProcMeas.cpp +// Editor: Robert Patzke +// URI/URL: www.mfp-portal.de +//----------------------------------------------------------------------------- +// Lizenz: CC-BY-SA (siehe Wikipedia: Creative Commons) +// + +#include "ProcMeas.h" + +// --------------------------------------------------------------------------- +// Konstruktoren und Initialisierungen +// --------------------------------------------------------------------------- +// +ProcMeas::ProcMeas(IntrfMeas *measPtr) +{ + pMeas = measPtr; + gravAnglesAvail = false; + pmState = pmInit; + gravSigns = 0; +#ifdef ProcMeasDebug + memset(&statistics,0,sizeof(Statistics)); +#endif +}; + +// --------------------------------------------------------------------------- +// Anwenderfunktionen +// --------------------------------------------------------------------------- +// + +void ProcMeas::run() +{ + if(pMeas == NULL) return; + + switch(pmState) + { + case pmInit: +#ifdef ProcMeasDebug + statistics.pmInitCnt++; +#endif + pmState = pmWait; + break; + + case pmWait: +#ifdef ProcMeasDebug + statistics.pmWaitCnt++; +#endif + if(pMeas->available(1, 1)) + { + pMeas->getValues(1, 1, &gravAngles); + gravSigns = pMeas->getSigns(1, 1); + pmState = pmCalc; + } + break; + + case pmCalc: +#ifdef ProcMeasDebug + statistics.pmCalcCnt++; +#endif + posture.pitch = euler.getPitchFromGravity(gravAngles.x, gravAngles.y, gravAngles.z) * RAD_TO_DEG; + posture.roll = euler.getRollFromGravity(gravAngles.y, gravAngles.z) * RAD_TO_DEG; + posture.yaw = 0.0; + pMeas->sync(1, 1); + gravAnglesAvail = true; + pmState = pmWait; + break; + } +} + +bool ProcMeas::availAngles(bool reset) +{ + if(!gravAnglesAvail) return(false); + if(reset) gravAnglesAvail = false; + return(true); +} + +float ProcMeas::getRollValue() +{ + return(posture.roll); +} + +float ProcMeas::getPitchValue() +{ + return(posture.pitch); +} + +float ProcMeas::getYawValue() +{ + return(posture.yaw); +} + +byte ProcMeas::getGravSigns() +{ + return(gravSigns); +} + diff --git a/libraries/ProcMeas/ProcMeas.h b/libraries/ProcMeas/ProcMeas.h new file mode 100644 index 0000000..e0b14eb --- /dev/null +++ b/libraries/ProcMeas/ProcMeas.h @@ -0,0 +1,106 @@ +//----------------------------------------------------------------------------- +// Thema: Social Manufacturing Network / Process Measurements +// Datei: ProcMeas.h +// Editor: Robert Patzke +// URI/URL: www.mfp-portal.de +//----------------------------------------------------------------------------- +// Lizenz: CC-BY-SA (siehe Wikipedia: Creative Commons) +// +#ifndef _ProcMeas_h +#define _ProcMeas_h +//----------------------------------------------------------------------------- + +#include <stddef.h> +#include <string.h> +#include "arduinoDefs.h" +#include "IntrfMeas.h" +#include "EulerAngles.h" + +//#define ProcMeasDebug + +typedef enum _PmState +{ + pmInit, + pmWait, + pmCalc +} PmState; + +typedef struct _Posture +{ + float roll; + float pitch; + float yaw; +}Posture, *PosturePtr; + +// --------------------------------------------------------------------------- +// class ProcMeas +// --------------------------------------------------------------------------- +// +class ProcMeas +{ + // ------------------------------------------------------------------------- + // Klassenspezifische Datentypen + // ------------------------------------------------------------------------- + // +#ifdef ProcMeasDebug + typedef struct _Statistics + { + dword pmInitCnt; + dword pmWaitCnt; + dword pmCalcCnt; + } Statistics, *StatisticsPtr; +#endif + +private: + // ------------------------------------------------------------------------- + // Lokale Variablen + // ------------------------------------------------------------------------- + // + bool gravAnglesAvail; + IntrfMeas *pMeas; + TriFloat gravAngles; + byte gravSigns; + PmState pmState; + EulerAngles euler; + Posture posture; + +private: + // ------------------------------------------------------------------------- + // Lokale Funktionen + // ------------------------------------------------------------------------- + // + +public: + // ------------------------------------------------------------------------- + // Konstruktoren und Initialisierungen + // ------------------------------------------------------------------------- + // + ProcMeas(IntrfMeas *measPtr); + + // ------------------------------------------------------------------------- + // Anwenderfunktionen + // ------------------------------------------------------------------------- + // + void run(); + bool availAngles(bool reset); + float getRollValue(); + float getPitchValue(); + float getYawValue(); + byte getGravSigns(); + + // ------------------------------------------------------------------------- + // Debug-Funtionen + // ------------------------------------------------------------------------- + // +#ifdef ProcMeasDebug + Statistics statistics; + +#endif + + + +}; + +//----------------------------------------------------------------------------- +#endif // _ProcMeas_h + -- GitLab