hbldh / pymetawear

Community developed SDK around the Python bindings for the C++ SDK
https://hbldh.github.io/pymetawear/
MIT License
43 stars 19 forks source link

Accelerometer and Gyroscope Log data and download #60

Open MoatazHammouda opened 5 years ago

MoatazHammouda commented 5 years ago

Description

I attempted to start logging data with specific parameters for the accelerometer and the gyroscope on my MMC board. The accelerometer settings are 25 Hz and 2.0 range and the gyroscope settings are 25 Hz and 2000.0 range.

After I stop the logging, I attempt to download the logged data and that is when I get the error shown in the traceback message.

My Code

from __future__ import division
from __future__ import print_function
from __future__ import absolute_import

import time

from pymetawear.client import MetaWearClient
from pymetawear.exceptions import PyMetaWearException, PyMetaWearDownloadTimeout
import pandas as pd

client = MetaWearClient('E6:36:15:BD:D1:44', debug=False)

print("Write accelerometer settings...")
client.accelerometer.set_settings(data_rate=25.0, data_range=2.0)
client.gyroscope.set_settings(data_rate=25.0, data_range=2000.0)

client.accelerometer.high_frequency_stream = False
client.gyroscope.high_frequency_stream = False

client.accelerometer.start_logging()
client.gyroscope.start_logging()

print("Logging accelerometer and gyroscope data...")

time.sleep(10.0)

client.accelerometer.stop_logging()
client.gyroscope.stop_logging()
print("Logging stopped.")

print("Downloading accelerometer data...")
download_done = False
n = 0
data = None
while (not download_done) and n < 3:
    try:
        data = client.accelerometer.download_log()
        download_done = True
    except PyMetaWearDownloadTimeout:
        print("Download of log interrupted. Trying to reconnect...")
        client.disconnect()
        client.connect()
        n += 1
if data is None:
    raise PyMetaWearException("Download of logging data failed.")

df=pd.DataFrame(data)
df.to_csv('Accelerometer_10.csv')

time.sleep(5.0)

print("Downloading gyroscope data...")
download_done = False
n = 0
dataG = None
while (not download_done) and n < 3:
    try:
        dataG = client.gyroscope.download_log()
        download_done = True
    except PyMetaWearDownloadTimeout:
        print("Download of log interrupted. Trying to reconnect...")
        client.disconnect()
        client.connect()
        n += 1
if data is None:
    raise PyMetaWearException("Download of logging data failed.")

df2=pd.DataFrame(dataG)
df2.to_csv('Gyroscope_10.csv')

print("Disconnecting...")
client.disconnect()

What I Did

From my understanding based on the traceback error message shown below is that in the pymetawear.modules.base.py the default callback only takes one argument and that is why only the accelerometer data is downloaded and the traceback error is given.

So it would be a logical assumption that if that issue is solved then it would work. But I wanted to ask if there is another way to log the data of different sensors on the MMC and download them without going through that hassle.

Thank you.

The traceback error message:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 315, in 'calling callback function'
TypeError: wrapper() takes exactly 1 argument (2 given)
krib-ula commented 4 years ago

I am having the same issue - any suggestions for this?