Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the project not needing ScienceMode if Rehastim2 is used #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions Examples/motomed_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
import time
from pyScienceMode import Rehastim2
import logging
import logging.config

from pyScienceMode.devices.rehastim2 import Rehastim2


def setup_logger():
logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"output": {"format": "%(asctime)s - %(name)s.%(levelname)s:\t%(message)s"},
},
"datefmt": "%Y-%m-%d %H:%M:%S",
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "output", "stream": "ext://sys.stdout"}
},
"loggers": {
"pyScienceMode": {"handlers": ["console"], "level": logging.DEBUG},
},
}
logging.config.dictConfig(logging_config)


setup_logger()
logger = logging.getLogger("pyScienceMode")


port = "/dev/ttyUSB0" # Enter the port on which the stimulator is connected

motomed = Rehastim2(port, show_log=True, with_motomed=True).motomed
motomed.init_phase_training(arm_training=True)
print(motomed.get_motomed_mode())
logger.info(motomed.get_motomed_mode())
motomed.start_phase(speed=50, gear=5, active=False, go_forward=False, spasm_detection=True)
time.sleep(2)
motomed.set_gear(10)
time.sleep(200)
motomed.stop_training()
print(motomed.get_phase_result())
logger.info(motomed.get_phase_result())
41 changes: 32 additions & 9 deletions Examples/motomed_stim_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import logging
import logging.config
import time
from pyScienceMode import Rehastim2 as St
from pyScienceMode import Channel as Ch
from pyScienceMode import Modes, Device

from pyScienceMode import Channel as Ch, Modes, Device
from pyScienceMode.devices.rehastim2 import Rehastim2 as St


def setup_logger():
logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"output": {"format": "%(asctime)s - %(name)s.%(levelname)s:\t%(message)s"},
},
"datefmt": "%Y-%m-%d %H:%M:%S",
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "output", "stream": "ext://sys.stdout"}
},
"loggers": {
"pyScienceMode": {"handlers": ["console"], "level": logging.DEBUG},
},
}
logging.config.dictConfig(logging_config)


def init_rehastim():
Expand Down Expand Up @@ -39,6 +59,9 @@ def init_rehastim():


if __name__ == "__main__":
setup_logger()
logger = logging.getLogger("pyScienceMode")

stimulator, list_channels = init_rehastim()
motomed = stimulator.motomed

Expand All @@ -58,8 +81,8 @@ def init_rehastim():
if (10 <= angle_crank < 20 or 180 <= angle_crank < 220) and (tric_delt_stim or bic_delt_stim):
stimulator.pause_stimulation()
tric_delt_stim, bic_delt_stim = False, False
print("angle crank", angle_crank)
print("stimulation_state", (tric_delt_stim or bic_delt_stim))
logger.info(f"angle crank {angle_crank}")
logger.info(f"stimulation_state {tric_delt_stim or bic_delt_stim}")

if 20 <= angle_crank < 180 and not tric_delt_stim:
list_channels[0].set_amplitude(0)
Expand All @@ -69,8 +92,8 @@ def init_rehastim():
stimulator.start_stimulation(upd_list_channels=list_channels)
tric_delt_stim = True
bic_delt_stim = False
print("angle crank", angle_crank)
print("stimulation_state", tric_delt_stim)
logger.info(f"angle crank {angle_crank}")
logger.info(f"stimulation_state {tric_delt_stim}")

if (220 <= angle_crank < 360 or 0 <= angle_crank < 10) and not bic_delt_stim:
list_channels[0].set_amplitude(15)
Expand All @@ -80,7 +103,7 @@ def init_rehastim():
stimulator.start_stimulation(upd_list_channels=list_channels)
bic_delt_stim = True
tric_delt_stim = False
print("angle crank", angle_crank)
print("stimulation_state", bic_delt_stim)
logger.info(f"angle crank {angle_crank}")
logger.info(f"stimulation_state {bic_delt_stim}")

time.sleep(0.01)
2 changes: 1 addition & 1 deletion docs/rehastim2_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ After a disconnection, init_channel must be called.
"""
stimulator.init_channel(stimulation_interval=15, list_channels=list_channels)

stimulator.start_stimulation(2, list_channels)
stimulator.start_stimulation(stimulation_duration=2, upd_list_channels=list_channels)

stimulator.end_stimulation()

Expand Down
43 changes: 36 additions & 7 deletions examples/perf_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import logging
import logging.config

from biosiglive import ViconClient, DeviceType
from pyScienceMode import Channel, Point, Device, Modes
from pyScienceMode import RehastimP24 as St
from pyScienceMode import Rehastim2 as St2
from pyScienceMode.devices.rehastim2 import Rehastim2 as St2
from pyScienceMode.devices.rehastimP24 import RehastimP24 as St
import random
from time import sleep
from sciencemode import sciencemode
from biosiglive import ViconClient, DeviceType
from time import sleep
import numpy as np


"""
This file is used to test the performance of both devices (RehastimP24 and Rehastim2).
The tests are done with Vicon Nexus and the biosiglive library.
Expand All @@ -15,6 +19,24 @@
"""


def setup_logger():
logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"output": {"format": "%(asctime)s - %(name)s.%(levelname)s:\t%(message)s"},
},
"datefmt": "%Y-%m-%d %H:%M:%S",
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "output", "stream": "ext://sys.stdout"}
},
"loggers": {
"pyScienceMode": {"handlers": ["console"], "level": logging.DEBUG},
},
}
logging.config.dictConfig(logging_config)


def get_trigger():
"""
This function is used to get the trigger from Vicon.
Expand Down Expand Up @@ -395,9 +417,10 @@ def diff_frequency_ll_ml(frequency):
stimulatorp24.start_stimulation(upd_list_channels=list_channels, stimulation_duration=2, safety=True)
stimulatorp24.end_stimulation()

logger = logging.getLogger("pyScienceMode")
for point in channel_1.list_point:
list_points.append(point)
print(point.pulse_width, point.amplitude)
logger.info(point.pulse_width, point.amplitude)
sleep(2)
stimulatorp24.start_stim_one_channel_stimulation(
no_channel=1, points=list_points, stim_sequence=100, pulse_interval=1000 / frequency
Expand Down Expand Up @@ -429,12 +452,14 @@ def communication_speed_P24():
ll_config.points[0].current = list_points[0].amplitude
ll_config.points[1].time = list_points[1].pulse_width
ll_config.points[1].current = list_points[1].amplitude

logger = logging.getLogger("pyScienceMode")
while True:
ll_config.packet_number = sciencemode.lib.smpt_packet_number_generator_next(stimulatorp24.device)
sciencemode.lib.smpt_send_ll_channel_config(stimulatorp24.device, ll_config)
sleep(waiting_time)
waiting_time *= 0.9
print(waiting_time)
logger.info(waiting_time)


def limit_parameters(device: Device):
Expand Down Expand Up @@ -475,13 +500,15 @@ def communication_speed_r2():
stimulator2.init_channel(stimulation_interval=8, list_channels=list_channels)
amplitude = 10
waiting_time = 1

logger = logging.getLogger("pyScienceMode")
while True:
stimulator2.start_stimulation(stimulation_duration=0.35)
amplitude *= 1.01
channel_1.set_amplitude(amplitude)
sleep(waiting_time)
waiting_time *= 0.9
print(waiting_time)
logger.info(waiting_time)


def decalage(freq1, freq2, freq3, device: Device):
Expand Down Expand Up @@ -554,6 +581,8 @@ def exe():
"""
Test to see if the python program do the same thing as the .exe program.
"""
setup_logger()

stimulatorp24 = St(port="COM4", show_log=True)
channel_1 = Channel(no_channel=1, amplitude=20, pulse_width=350, frequency=50, device_type=Device.Rehastimp24)
list_channels.append(channel_1)
Expand Down
11 changes: 4 additions & 7 deletions examples/rehastim2_example.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Import Stimulator class
from pyScienceMode import Rehastim2 as St
from pyScienceMode import Modes, Device

# Import Channel class
from pyScienceMode import Channel as Ch
from time import sleep

from pyScienceMode import Modes, Device, Channel as Ch
from pyScienceMode.devices.rehastim2 import Rehastim2 as St

# Create a list of channels
list_channels = []

Expand Down Expand Up @@ -103,7 +100,7 @@
"""
stimulator.init_channel(stimulation_interval=15, list_channels=list_channels)

stimulator.start_stimulation(2, list_channels)
stimulator.start_stimulation(stimulation_duration=2, upd_list_channels=list_channels)

stimulator.end_stimulation()

Expand Down
30 changes: 28 additions & 2 deletions examples/rehastimp24_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import logging
import logging.config

from pyScienceMode import Channel, Point, Device, Modes
from pyScienceMode import RehastimP24 as St
from pyScienceMode.devices.rehastimP24 import RehastimP24 as St


"""
This example shows how to use the RehastimP24 device.
Expand All @@ -8,6 +12,28 @@
to be able to use commands from another one.
"""


def setup_logger():
logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"output": {"format": "%(asctime)s - %(name)s.%(levelname)s:\t%(message)s"},
},
"datefmt": "%Y-%m-%d %H:%M:%S",
"handlers": {
"console": {"class": "logging.StreamHandler", "formatter": "output", "stream": "ext://sys.stdout"}
},
"loggers": {
"pyScienceMode": {"handlers": ["console"], "level": logging.DEBUG},
},
}
logging.config.dictConfig(logging_config)


setup_logger()
logger = logging.getLogger("pyScienceMode")

# list which contains the channels you want to use
list_channels = []

Expand Down Expand Up @@ -61,7 +87,7 @@
"""

# stimulator.get_battery_status()
print(stimulator.get_stim_status())
logger.info(stimulator.get_stim_status())
# stimulator.get_main_status()
# stimulator.get_all()
# stimulator.reset()
Expand Down
4 changes: 1 addition & 3 deletions pyScienceMode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from .motomed_interface import _Motomed
from .sciencemode import RehastimGeneric
from .devices.rehastim_generic import RehastimGeneric
from . import utils
from .rehastim2_interface import Rehastim2
from .rehastimP24_interface import RehastimP24
from . import acks
from .channel import Channel, Point
from .enums import Rehastim2Commands, RehastimP24Commands, Modes, Device
Loading