예제 #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.
예제 #2
0
from Alpes.Specification import *
from Alpes.Prosthesis import AlpesProsthesis, GESTURES
import time

h = AlpesProsthesis()
h.initialise()

# Go through all gestures
gestures = [
    g for g in dir(GESTURES())
    if not g.startswith('__') and not callable(getattr(GESTURES(), g))
]
for g in gestures:
    print('Performing %s gesture' % g)
    h.set_gesture(getattr(GESTURES(), g))
    time.sleep(2.5)

print('Back to initial position')
h.set_gesture(GESTURES.OPEN)
time.sleep(5)
from Alpes.Specification import *
from Alpes.Prosthesis import AlpesProsthesis
import time

h = AlpesProsthesis()
h.initialise()

# Access any register you need. Register names are defined in Alpes.Specifications
pid = [
    h.read_register(VOIES.INDEX, REGISTRES.COEF_P),
    h.read_register(VOIES.INDEX, REGISTRES.COEF_I),
    h.read_register(VOIES.INDEX, REGISTRES.COEF_D)
]

print('PID coefficients of index finger motor: ', pid)

# Access the same register in all motors:
mode = h.read_registers_across(REGISTRES.MODE_CMD_MOTEUR)
print('Motor command modes: ', mode)

# Read the entire hand's memory:
h.read_memory()
print('Contents of all registers of thumb motor:')
print(h.memory[VOIES.POUCE])
예제 #4
0
from Alpes.Specification import *
from Alpes.Prosthesis import AlpesProsthesis

# Create an instance of AlpesProsthesis() object. It will try to connect to the hand by itself.
h = AlpesProsthesis()
# Start initialisation procedure.
h.initialise()
예제 #5
0
from Alpes.Specification import *
from Alpes.Prosthesis import AlpesProsthesis
import time

h = AlpesProsthesis()
h.initialise()

# Can write to motors separately:
for motor in [2, 3, 4, 5]:
    h.write_positions([40000], [motor])
    time.sleep(3)

# Can write to all of them at once.
h.write_positions([0, 0, 0, 0, 0, 0])
time.sleep(3)
예제 #6
0
from Alpes.Specification import *
from Alpes.Prosthesis import AlpesProsthesis
import time

h = AlpesProsthesis()
h.initialise()

# Set current limit to zero: this will forbid the motor from drawing any current:
h.set_current_limits([0], [VOIES.AURICULAIRE])

# Now try to move this finger with the current limited to 0:
h.write_positions([MAXIMAL_MOTOR_POSITIONS[VOIES.AURICULAIRE]],
                  [VOIES.AURICULAIRE])
print(
    'Position command is sent but current is limited to zero. No rotation ...')
time.sleep(5)

# Setup default current limit:
h.set_current_limits([CONTROLE_COURANT.LIMITE_COURANT_DEFAUT],
                     [VOIES.AURICULAIRE])
print('Setting up default current limit. Rotation is possible.')
time.sleep(5)

# Go back to initial position:
print('Getting back ...')
h.write_positions([0], [VOIES.AURICULAIRE])
time.sleep(5)
from Alpes.Specification import *
from Alpes.Prosthesis import AlpesProsthesis
import time

h = AlpesProsthesis()
h.initialise()

# Apply increasing tension to the motors:
print('Positive tension to the motor ...')
N = 10
for i in range(1, N + 1):
    h.write_tensions([i / N * MOTORSPEC.MAXIMAL_ABSOLUTE_TENSION / 2],
                     [VOIES.AURICULAIRE])
    time.sleep(4 / N)
    print('Tension: %2.2f V' %
          (i / N * MOTORSPEC.MAXIMAL_ABSOLUTE_TENSION / 2))

# Apply decreasing negative tension to the motors:
print('Negative tension to the motor ...')
for i in range(N + 1):
    h.write_tensions([-i / N * MOTORSPEC.MAXIMAL_ABSOLUTE_TENSION / 2],
                     [VOIES.AURICULAIRE])
    time.sleep(2 / N)
    print('Tension: %2.2f V' %
          (-i / N * MOTORSPEC.MAXIMAL_ABSOLUTE_TENSION / 2))

print('Stopeed applying tension.')
time.sleep(2.5)

print('Getting back to initial position ...')
h.write_positions([0] * 6)
예제 #8
0
    # Absolute values of EMG are spanned between 0 and 127.
    # 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