Exemplo n.º 1
0
from Alpes.Specification import *
from Alpes.Prosthesis import AlpesProsthesis
import time

h = AlpesProsthesis()
h.initialise()

# Start flexing fingers
h.write_positions([5000, 19000, 40000, 40000, 40000, 40000])
# Reading while fingers are moving
print('Flexsion: reading motor positions and velocities ...')
for i in range(25):
    print('Pos.: %s, Vel.: %s' % (h.read_positions(), h.read_velocities()))
    time.sleep(0.1)

# Start extending fingers
h.write_positions([0, 0, 0, 0, 0, 0])
# Reading while fingers are moving
print('Extension: reading motor positions and velocities ...')
for i in range(25):
    print('Pos.: %s, Vel.: %s' % (h.read_positions(), h.read_velocities()))
    time.sleep(0.1)

# Positions are measured in encoder ticks.
# Velocities are measured in rpm of the motor shaft after reduction.
Exemplo n.º 2
0
    # thresholds are approximately measure as percentage of total muscle contraction.
    # thresholds[0] corresponds to flexors, thresholds[1] correspons to extensors.
    thresholds=[10, 15],
    # cc_lock_duration filters out some unwanted control decisions after a co-contraction.
    # cc_lock_duration is measured in number of 'winlen's (see variable above).
    # Increase cc_lock_duration if unwanted motions appear after co-contraction or if
    # co-contraction gets detected twice instead of once in a short amount of time.
    cc_lock_duration=1)

grasps = [GRASPS().CYLINDRICAL, GRASPS().LATERAL, GRASPS().PINCH]
grasp = 0

# Connect the hand to the computer and switch it on. First run after connection
# will initialise the hand. Consecutive runs won't.
p = AlpesProsthesis()
p.initialise()
p.set_grasp(grasps[grasp])
mav2command = [0.02, 0.02
               ]  #mapping from mean absolute signal to the control variable.

with hub.run_in_background(listener):
    print('Streaming EMG ... Press ctrl-c or shift-c to stop.')
    while hub.running:
        time.sleep(winsec)
        # Pull recent EMG data from the buffer
        emg_data = listener.get_emg_data()
        # Transform it to numpy matrix
        emg_data = np.array([[x[1][flexors_chan], x[1][extensors_chan]]
                             for x in emg_data])
        # Interpret EMG, produce decision
        decision, mav = mc.decide(emg_data)