Skip to content
Snippets Groups Projects
Commit 05cd96d2 authored by RobertPatzke's avatar RobertPatzke
Browse files

Update 20221107-1

parent 800a1868
No related branches found
No related tags found
No related merge requests found
//-----------------------------------------------------------------------------
// 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);
}
//-----------------------------------------------------------------------------
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment