emg: Added emg sensor C source

Added the C source for the emg sensor with necessary changes to cmake,
examples, docs.

    * Renamed all files with groveemg to emg
    * Replaced all instances of groveemg with emg
    * Added C source for emg sensor
    * Updated all cmake files
    * Added C example for emg sensor

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-09-08 12:35:41 -07:00
parent fe06de86b4
commit a19678948b
20 changed files with 525 additions and 56 deletions

View File

@ -169,7 +169,7 @@ add_example (nunchuck)
add_example (otp538u)
add_example (grovecollision)
add_example (groveelectromagnet)
add_example (groveemg)
add_example (emg)
add_example (o2)
add_example (grovegsr)
add_example (ina132)

View File

@ -24,7 +24,7 @@
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "groveemg.hpp"
#include "emg.hpp"
using namespace std;
@ -41,9 +41,9 @@ int main(int argc, char **argv)
signal(SIGINT, sig_handler);
//! [Interesting]
// The was tested with the GroveEMG Muscle Signal Reader Sensor Module
// Instantiate a GroveEMG on analog pin A0
upm::GroveEMG *emg = new upm::GroveEMG(0);
// The was tested with the EMG Muscle Signal Reader Sensor Module
// Instantiate a EMG on analog pin A0
upm::EMG *emg = new upm::EMG(0);
cout << "Calibrating...." << endl;
emg->calibrate();

View File

@ -97,6 +97,7 @@ add_example (dfrorp)
add_example (vdiv)
add_example (mqx)
add_example (o2)
add_example (emg)
# Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)

86
examples/c/emg.c Normal file
View File

@ -0,0 +1,86 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* 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 <unistd.h>
#include <signal.h>
#include "emg.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a emg sensor on analog pin A0
emg_context sensor = emg_init(0);
if (!sensor)
{
printf("emg_init() failed.\n");
return -1;
}
// Set the aref, scale, and offset
emg_set_aref(sensor, 5.0);
emg_set_scale(sensor, 1.0);
emg_set_offset(sensor, -.1);
printf("aRef: %0.03f scale: %0.03f offset: %0.03f\n\n",
emg_get_aref(sensor),
emg_get_scale(sensor),
emg_get_offset(sensor));
// Every half a second, sample the sensor output
while (shouldRun)
{
float normalized = 0.0;
float raw_volts = 0.0;
float volts = 0.0;
emg_get_normalized(sensor, &normalized);
emg_get_raw_volts(sensor, &raw_volts);
emg_get_volts(sensor, &volts);
printf("Normalized output: %0.03f, raw emg sensor output: %0.03f v "
"adjusted output: %0.03f v\n", normalized, raw_volts, volts);
usleep(500000);
}
//! [Interesting]
printf("Exiting\n");
emg_close(sensor);
return 0;
}

View File

@ -34,7 +34,7 @@ add_example(GroveButtonSample grove)
add_example(GroveButton_intrSample grove)
add_example(GroveCollision grovecollision)
add_example(GroveEHRSample groveehr)
add_example(GroveEmg groveemg)
add_example(Emg emg)
add_example(GroveGsr grovegsr)
add_example(GroveLed_multiSample grove)
add_example(GroveLEDSample grove)

View File

@ -21,15 +21,15 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_groveemg.GroveEMG;
import upm_emg.EMG;
public class GroveEmg {
public class Emg {
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// Instantiating the Grove EMG sensor on Analog pin 0
GroveEMG emg = new GroveEMG(0);
EMG emg = new EMG(0);
System.out.println("Calibrating ... ");
emg.calibrate();

View File

@ -21,26 +21,26 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var groveemg_lib = require("jsupm_groveemg");
var emg_lib = require("jsupm_emg");
// The was tested with the GroveEMG Muscle Signal Reader Sensor Module
// Instantiate a GroveEMG on analog pin A0
var groveemg_obj = new groveemg_lib.GroveEMG(0);
// The was tested with the EMG Muscle Signal Reader Sensor Module
// Instantiate a EMG on analog pin A0
var emg_obj = new emg_lib.EMG(0);
console.log("Calibrating....");
groveemg_obj.calibrate();
emg_obj.calibrate();
var myInterval = setInterval(function()
{
console.log(groveemg_obj.value());
console.log(emg_obj.value());
}, 100);
// When exiting: clear interval, and print message
process.on('SIGINT', function()
{
clearInterval(myInterval);
groveemg_obj = null;
groveemg_lib.cleanUp();
groveemg_lib = null;
emg_obj = null;
emg_lib.cleanUp();
emg_lib = null;
console.log("Exiting...");
process.exit(0);
});

View File

@ -22,11 +22,11 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_groveemg as upmGroveemg
import pyupm_emg as upmEmg
# Tested with the GroveEMG Muscle Signal Reader Sensor Module
# Instantiate a GroveEMG on analog pin A0
myEMG = upmGroveemg.GroveEMG(0)
# Tested with the EMG Muscle Signal Reader Sensor Module
# Instantiate a EMG on analog pin A0
myEMG = upmEmg.EMG(0)
## Exit handlers ##