Exemple #1
0
 def __init__(self, DIMENSIONS=(800, 450)):
     """DIMENSIONS is a tuple (WIDTH, HEIGHT) of the field."""
     # OBJECTS
     WIDTH = DIMENSIONS[0]
     self.players = [Player(0, WIDTH), Player(1, WIDTH)]
     self.ball = Ball()
     # DATA
     self.pressed_keys = set()  # set has no duplicates
     self.quit_key = pyglet.window.key.Q
     self.speed = 6  # in pixels per frame
     self.ball_speed = self.speed * 2.5
     self.WIDTH, self.HEIGHT = DIMENSIONS
     # STATE VARS
     self.paused = False
     self.i = 0  # "frame count" for debug
     self.ems_device = openEMSstim.openEMSstim(serial_port,19200)
     self.left_player_lost_stimulation = ems_command(1,100,2000)
     self.right_player_lost_stimulation = ems_command(2,100,2000)
Exemple #2
0
 def __init__(self, DIMENSIONS=(800, 450)):
     """DIMENSIONS is a tuple (WIDTH, HEIGHT) of the field."""
     # OBJECTS
     WIDTH = DIMENSIONS[0]
     self.players = [Player(0, WIDTH), Player(1, WIDTH)]
     self.ball = Ball()
     # DATA
     self.pressed_keys = set()  # set has no duplicates
     self.quit_key = pyglet.window.key.Q
     self.speed = 6  # in pixels per frame
     self.ball_speed = self.speed * 2.5
     self.WIDTH, self.HEIGHT = DIMENSIONS
     # STATE VARS
     self.paused = False
     self.i = 0  # "frame count" for debug
     self.ems_device = openEMSstim.openEMSstim(serial_port,19200)
     self.left_player_lost_stimulation = ems_command(1,100,2000)
     self.right_player_lost_stimulation = ems_command(2,100,2000)
# This program enables to send commands via USB to the openEMSstim board
# NOTE: To use it you will need to adjust the COM_port to whatever your operating system reported for the arduino connection (Windows will be something like COM3, check on Device Manager, while unix will be /dev/tty.usbsomething)

from time import sleep
from pyEMS import openEMSstim
from pyEMS.EMSCommand import ems_command

my_ems_board = openEMSstim.openEMSstim("/dev/tty.usbserial-A98VFLTL",19200)
while 1:
    choice = int(raw_input("1 or 2? EMS with full intensity on that channel for 2 seconds"))
    my_ems_board.send(ems_command(choice,100,9000))


#native imports
import sys
from time import sleep 

#import openEMSstim modules
sys.path.append("../")
from pyEMS import openEMSstim
from pyEMS.EMSCommand import ems_command


#create a ems_device
ems_device = openEMSstim.openEMSstim("/dev/tty.wchusbserial1410",19200)
if ems_device: #check if was created properly
    print("Device Found")
    print("Will send: Channel 1, Intensity=1 (out of 100), Duration=1000 (1 second)")
    command_1 = ems_command(1,1,1000)
    ems_device.send(command_1)
    sleep(1)
    print("Will send: Channel 2, Intensity=1 (out of 100), Duration=1000 (1 second)")
    command_2 = ems_command(2,1,1000)
    ems_device.send(command_2)
    sleep(1)
    print("Will send: Channel 1 + 2 (two commands) with Intensity=40 (out of 100), Duration=2000 (2 seconds)")
    command_1 = ems_command(1,40,2000)
    command_2 = ems_command(2,40,2000)
    ems_device.send(command_1)
    ems_device.send(command_2)
    sleep(2)
    print("Done testing. Closing")
    ems_device.shutdown()
#
        else:
            return False


while (not_ended):
    cli_clear()
    if len(command_history) >= 1:
        print("Last command: " + str(command_history[-1]))
    if print_channel_config_next_time:
        print_configuration(print_channel_config_next_time)
    command = raw_input(command_list)
    command_tokens = command.split(" ")

    # direct command mode
    if len(command_tokens) == 3:
        command = ems_command(command_tokens[0], command_tokens[1],
                              command_tokens[2])
        stimulate(my_ems_board, command, command_history, True,
                  command_tokens[0], command_tokens[1], command_tokens[2])

    # save preset mode
    elif len(command_tokens) == 2:
        if command_tokens[0] == "p":
            #p = Preset(command_history[-1])
            print("save preset mode is not implemented yet")

    # stimulate with channel + preset
        elif command_tokens[0].isdigit():
            if contains(presets, command_tokens[1]) == True:
                command = ems_command(command_tokens[0], command_tokens[1],
                                      preset_stimulation_duration)
                stimulate(my_ems_board, command, command_history, True,
Exemple #6
0
    else:
        print("Error: command invalid, hence not sent")


while (not_ended):
    cli_clear()
    if len(command_history) >= 1:
        print("Last command: " + str(command_history[-1]))
    if print_channel_config_next_time:
        print_configuration(print_channel_config_next_time)
    command = raw_input(command_list)
    command_tokens = command.split(" ")

    # direct command mode
    if len(command_tokens) == 3:
        command = ems_command(command_tokens[0], command_tokens[1],
                              command_tokens[2])
        stimulate(my_ems_board, command, command_history, True,
                  command_tokens[0], command_tokens[1], command_tokens[2])

    # repeat command mode or all single "string" commands
    elif len(command_tokens) == 1:

        # repeat last command mode
        if command_tokens[0] == "r":
            if len(command_history) >= 1:
                stimulate(my_ems_board, command, command_history, False)
            else:
                print(
                    "Warning: there is no last command to repeat (history empty)"
                )
        else:
            return False


while (not_ended):
    cli_clear()
    if len(command_history) >= 1:
        print("Last command: " + str(command_history[-1]))
    if print_channel_config_next_time:
        print_configuration(print_channel_config_next_time)
    command = raw_input(command_list)
    command_tokens = command.split(" ")
    
    # direct command mode
    if len(command_tokens) == 3: 
        command = ems_command(command_tokens[0],command_tokens[1],command_tokens[2])
        stimulate(my_ems_board, command, command_history, True, command_tokens[0], command_tokens[1], command_tokens[2]) 
    
    # save preset mode
    elif len(command_tokens) == 2: 
        if command_tokens[0] == "p":
            #p = Preset(command_history[-1])
            print("save preset mode is not implemented yet")

    # stimulate with channel + preset
        elif command_tokens[0].isdigit():
            if contains(presets,command_tokens[1]) == True:
                command = ems_command(command_tokens[0], command_tokens[1], preset_stimulation_duration)
                stimulate(my_ems_board, command, command_history, True, command_tokens[0], command_tokens[1]) 
            else:
                print("Warning: preset " + str(command_tokens[1]) + " not found")
Exemple #8
0
import sys
from time import sleep

#import openEMSstim modules
sys.path.append("../")
from pyEMS import openEMSstim
from pyEMS.EMSCommand import ems_command

#create a ems_device
ems_device = openEMSstim.openEMSstim("/dev/tty.wchusbserial1410", 19200)
if ems_device:  #check if was created properly
    print("Device Found")
    print(
        "Will send: Channel 1, Intensity=1 (out of 100), Duration=1000 (1 second)"
    )
    command_1 = ems_command(1, 1, 1000)
    ems_device.send(command_1)
    sleep(1)
    print(
        "Will send: Channel 2, Intensity=1 (out of 100), Duration=1000 (1 second)"
    )
    command_2 = ems_command(2, 1, 1000)
    ems_device.send(command_2)
    sleep(1)
    print(
        "Will send: Channel 1 + 2 (two commands) with Intensity=40 (out of 100), Duration=2000 (2 seconds)"
    )
    command_1 = ems_command(1, 40, 2000)
    command_2 = ems_command(2, 40, 2000)
    ems_device.send(command_1)
    ems_device.send(command_2)