Beispiel #1
0
def main():
    marvin_clips = GetSoundClips("clips")

    accel = Accelerometer(reactor, "/dev/ttyACM0")
    accelPlayer = AccelPlayer(Player(), marvin_clips)
    accel.setCallback(accelPlayer.getData)
    reactor.run()
Beispiel #2
0
def main():
    marvin_clips = GetSoundClips("clips")

    accel = Accelerometer(reactor, "/dev/ttyACM0")
    accelPlayer = AccelPlayer(Player(), marvin_clips)
    accel.setCallback(accelPlayer.getData)
    reactor.run()
Beispiel #3
0
    def create_wrist_obj(self):
        """Creates wrist accelerometer data object.
           Scales accelerometer cutpoints from Powell et al. (2017) to selected epoch length.

        :returns
        -wrist object
        -cutpoints: dictionary
        """

        print("\n--------------------------------------------- Wrist file --------------------------------------------")
        if self.wrist_filepath is not None:
            wrist = Accelerometer(raw_filepath=self.wrist_filepath,
                                  load_raw=self.load_raw,
                                  start_offset=self.wrist_offset)
            fs = wrist.sample_rate

        if self.wrist_filepath is None:
            wrist = None
            fs = 1

        # Scales Powell et al. 2017 cutpoints to correct epoch length and sample rate (SVMs)
        if self.cutpoints.capitalize() == "Powell":
            print("\nSetting cutpoints to cutpoints from Powell et al. 2017.")
            cutpoint_dict = {"Light": 47 * fs / 30 * self.epoch_len / 15,
                             "Moderate": 64 * fs / 30 * self.epoch_len / 15,
                             "Vigorous": 157 * fs / 30 * self.epoch_len / 15}

        # Cutpoints use AVM and are independent of sample rates and  epoch lengths
        if self.cutpoints.capitalize() == "Fraysse":
            print("\nSetting cutpoints to cutpoints from Fraysse et al. 2021.")
            cutpoint_dict = {"Light": 42.5, "Moderate": 62.5, "Vigorous": 10000}

        return wrist, cutpoint_dict
Beispiel #4
0
def init():
    rest = None
    if (USE_REST):
        print('Start REST server')
        rest = RESTThread()
        rest.start()

    bin = None
    if (USE_BINLOG):
        bin = BinaryFileController(2)
        bin.start()

    acc = Accelerometer(0.250, bin)
    acc.start()

    log = None
    if (USE_TEXTLOG):
        log = FileController(20)
        log.start()

    dsp = Display(acc, log, rest)
    dsp.start()

    print('at sleep')
    time.sleep(60 * 30)

    acc.stopit()
    acc.join()
    print("Accelorometer stopped")

    dsp.stopit()
    dsp.join()
    print("Display stopped")

    if (USE_BINLOG):
        bin.stopit()
        bin.join()
        print("BinLogger stopped")

    if (USE_TEXTLOG):
        log.stopit()
        log.join()
        print("FileController stopped")

    if (USE_REST):
        rest.stopit()
        rest.join()
        print("REST server stopped")

    time.sleep(2)
    print("End")
Beispiel #5
0
class Orientation():

    def __init__(self):
        self.accel = Accelerometer()
        self.mag = Magnetometer()

    def magTiltCompensation(self, acceleration, magnetic):
        accel_X = acceleration.x
        accel_Y = acceleration.y
        accel_Z = acceleration.z
        mag_X = magnetic.x
        mag_Y = magnetic.y
        mag_Z = magnetic.z

        t_roll = accel_X * accel_X + accel_Z * accel_Z
        rollRadians = math.atan2(accel_Y, math.sqrt(t_roll))

        t_pitch = accel_Y * accel_Y + accel_Z * accel_Z
        pitchRadians = math.atan2(accel_X, math.sqrt(t_pitch))

        cosRoll = math.cos(rollRadians)
        sinRoll = math.sin(rollRadians)
        cosPitch = math.cos(-1*pitchRadians)
        sinPitch = math.sin(-1*pitchRadians)

        mag_X = (mag_X * cosPitch) + (mag_Z * sinPitch)
        mag_Y = (mag_X * sinRoll * sinPitch) + (mag_Y * cosRoll) - (mag_Z * sinRoll * cosPitch)

        return Vector([mag_X, mag_Y, mag_Z])

    def getOrientation(self):
        acceleration = Vector(self.accel.read())
        magnetic = Vector(self.mag.read())
        roll = 0
        pitch = 0
        heading = 0

        PI_F = 3.14159265

        roll = math.atan2(acceleration.x, acceleration.z)

        if acceleration.x * math.sin(roll) + acceleration.z * math.cos(roll) == 0:
            pitch = (PI_F / 2) if acceleration.y > 0 else (-PI_F / 2)
        else:
            pitch = math.atan(-acceleration.y / (acceleration.x * math.sin(roll) + acceleration.z * math.cos(roll)))

        magCompensated = self.magTiltCompensation(acceleration, magnetic)
        heading = math.atan2(magCompensated.x, magCompensated.z)

        return [math.degrees(roll),
                math.degrees(pitch),
                math.degrees(heading)]
Beispiel #6
0
    def create_ankle_obj(self):
        """Creates ankle accelerometer data object.

        :returns
        -ankle object
        """

        print("\n--------------------------------------------- Ankle file --------------------------------------------")

        ankle = Accelerometer(raw_filepath=self.ankle_filepath,
                              load_raw=self.load_raw,
                              start_offset=self.ankle_offset)

        return ankle
Beispiel #7
0
    def calibrateAcc(self):

        [biasX, biasY, biasZ, OffX, OffY, OffZ] = Acc.calibrate(self)

        self.cb_Acc.setEnabled(True)
        self.cb_Acc.setChecked(True)

        self.tv_AccScaleX.setText(str(round(biasX, 4)))
        self.tv_AccScaleY.setText(str(round(biasY, 4)))
        self.tv_AccScaleZ.setText(str(round(biasZ, 4)))

        self.tv_AccOffX.setText(str(round(OffX, 4)))
        self.tv_AccOffY.setText(str(round(OffY, 4)))
        self.tv_AccOffZ.setText(str(round(OffZ, 4)))
Beispiel #8
0
def init():
    rest = None
    if (USE_REST):
        print('Start REST server')
        rest = RESTThread()
        rest.start()
    
    bin = None
    if (USE_BINLOG):
        bin = BinaryFileController(2)
        bin.start()

    acc = Accelerometer(0.250, bin)
    acc.start()

    log = None
    if (USE_TEXTLOG):
        log = FileController(20)
        log.start()

    dsp = Display(acc, log, rest)
    dsp.start()
    
    print('at sleep')
    time.sleep(60*30)
    
    acc.stopit()
    acc.join()
    print("Accelorometer stopped")
        
    dsp.stopit()
    dsp.join()
    print("Display stopped")

    if (USE_BINLOG):
        bin.stopit()
        bin.join()
        print("BinLogger stopped")

    if (USE_TEXTLOG):
        log.stopit()
        log.join()
        print("FileController stopped")

    if (USE_REST):
        rest.stopit()
        rest.join()
        print("REST server stopped")

    time.sleep(2)
    print("End")
Beispiel #9
0
 def __init__(self):
     self.accel = Accelerometer()
     self.mag = Magnetometer()
Beispiel #10
0
class Orientation():
    def __init__(self):
        self.accel = Accelerometer()
        self.mag = Magnetometer()

    def magTiltCompensation(self, acceleration, magnetic):
        accel_X = acceleration.x
        accel_Y = acceleration.y
        accel_Z = acceleration.z
        mag_X = magnetic.x
        mag_Y = magnetic.y
        mag_Z = magnetic.z

        t_roll = accel_X * accel_X + accel_Z * accel_Z
        rollRadians = math.atan2(accel_Y, math.sqrt(t_roll))

        t_pitch = accel_Y * accel_Y + accel_Z * accel_Z
        pitchRadians = math.atan2(accel_X, math.sqrt(t_pitch))

        cosRoll = math.cos(rollRadians)
        sinRoll = math.sin(rollRadians)
        cosPitch = math.cos(-1 * pitchRadians)
        sinPitch = math.sin(-1 * pitchRadians)

        mag_X = (mag_X * cosPitch) + (mag_Z * sinPitch)
        mag_Y = (mag_X * sinRoll * sinPitch) + (mag_Y * cosRoll) - (mag_Z * sinRoll * cosPitch)

        return Vector([mag_X, mag_Y, mag_Z])

    def getOrientationOld(self):
        acceleration = Vector(self.accel.read())
        magnetic = Vector(self.mag.read())
        roll = 0
        pitch = 0
        heading = 0

        PI_F = 3.14159265

        roll = math.atan2(acceleration.y, acceleration.z)

        if acceleration.y * math.sin(roll) + acceleration.z * math.cos(roll) == 0:
            pitch = (PI_F / 2) if acceleration.x > 0 else (-PI_F / 2)
        else:
            pitch = math.atan(-acceleration.x / (acceleration.y * math.sin(roll) + acceleration.z * math.cos(roll)))

        magCompensated = self.magTiltCompensation(acceleration, magnetic)
        heading = math.atan2(magnetic.z, magnetic.x)

        return [math.degrees(roll),
                math.degrees(pitch),
                math.degrees(heading)]

    def getOrientation(self):
        acceleration = Vector(self.accel.read())
        roll = 0
        pitch = 0
        heading = self.mag.readMagneticHeading()

        PI_F = 3.14159265

        roll = math.atan2(acceleration.y, acceleration.z)

        if acceleration.y * math.sin(roll) + acceleration.z * math.cos(roll) == 0:
            pitch = (PI_F / 2) if acceleration.x > 0 else (-PI_F / 2)
        else:
            pitch = math.atan(-acceleration.x / (acceleration.y * math.sin(roll) + acceleration.z * math.cos(roll)))

        # m_max_x = 384
        # m_max_y = 253
        # m_max_z = 372
        # m_min_x = -282
        # m_min_y = -431
        # m_min_z = -276
        # x_error = (m_max_x + m_min_x) / 2
        # y_error = (m_max_y + m_min_y) / 2
        #
        # real_x = magnetic.x - x_error
        # real_y = magnetic.y - y_error

        # heading = math.atan2(real_y, real_x)

        return [math.degrees(roll),
                math.degrees(pitch),
                heading]