Added getVolts() to iEMG interface and its sensors.

Signed-off-by: Serban Waltter <serban.waltter@rinftech.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Serban Waltter 2018-07-03 15:47:01 +03:00 committed by Mihai Tudor Panu
parent c642e02a18
commit 1f1510f38d
5 changed files with 59 additions and 0 deletions

View File

@ -45,5 +45,12 @@ namespace upm
* @return Muscle output as analog voltage
*/
virtual int value() = 0;
/**
* Read scaled/offset voltage from the sensor
*
* @return Measured volts
*/
virtual float getVolts() = 0;
};
}

View File

@ -67,3 +67,21 @@ int EMG::value()
int val = mraa_aio_read(m_aio);
return val;
}
float EMG::getVolts()
{
float val = mraa_aio_read_float(m_aio);
if (val < 0)
return val;
/* Apply raw scale */
val *= this->m_scale;
/* Scale to aRef */
val *= this->m_aRef;
/* Apply the offset in volts */
val += this->m_offset;
return val;
}

View File

@ -76,7 +76,15 @@ namespace upm {
*/
virtual int value();
virtual float getVolts();
private:
mraa_aio_context m_aio;
/* Analog voltage reference */
float m_aRef = 5.0;
/* Scale */
float m_scale = 1.0;
/* Offset in sensor units */
float m_offset = 0.0;
};
}

View File

@ -67,3 +67,21 @@ int GroveEMG::value()
int val = mraa_aio_read(m_aio);
return val;
}
float GroveEMG::getVolts()
{
float val = mraa_aio_read_float(m_aio);
if (val < 0)
return val;
/* Apply raw scale */
val *= this->m_scale;
/* Scale to aRef */
val *= this->m_aRef;
/* Apply the offset in volts */
val += this->m_offset;
return val;
}

View File

@ -77,7 +77,15 @@ namespace upm {
*/
virtual int value();
virtual float getVolts();
private:
mraa_aio_context m_aio;
/* Analog voltage reference */
float m_aRef = 5.0;
/* Scale */
float m_scale = 1.0;
/* Offset in sensor units */
float m_offset = 0.0;
};
}