Skip to main content

Python interface to the Dudman lab Mouse Joystick Rig.

Project description

About

- Python Package Name: mouse_joystick_interface
- Description: Python interface to the Dudman lab Mouse Joystick Rig.
- Version: 5.0.1
- Python Version: 3.10
- Release Date: 2023-12-05
- Creation Date: 2023-10-17
- License: BSD-3-Clause
- URL: https://github.com/janelia-pypi/mouse_joystick_interface_python
- Author: Peter Polidoro
- Email: peter@polidoro.io
- Copyright: 2023 Howard Hughes Medical Institute
- References:
  - https://github.com/janelia-kicad/mouse_joystick_controller
- Dependencies:
  - modular_client
  - flatten_json

Example Usage

Python

from mouse_joystick_interface import MouseJoystickInterface
dev = MouseJoystickInterface() # Might automatically find devices if available
# if devices not found automatically, specify ports directly
dev = MouseJoystickInterface(use_ports=['/dev/ttyACM0','/dev/ttyACM0']) # Linux specific ports
dev = MouseJoystickInterface(use_ports=['/dev/tty.usbmodem262471','/dev/tty.usbmodem262472']) # Mac OS X specific ports
dev = MouseJoystickInterface(use_ports=['COM3','COM4']) # Windows specific ports
# abort_assay prematurely stops a running assay and leaves the rig ready to start a new assay
dev.abort_assay()
# start_assay is the main method that starts the assay, collects assay data, and saves data files
dev.start_assay(set_path='~/set_example.csv')

# optional mouse_joystick_controller methods
dev.mouse_joystick_controller.set_properties_to_defaults(['ALL'])
dev.mouse_joystick_controller.get_property_values(['ALL'])
dev.mouse_joystick_controller.repeat_aborted_trial('setValue',False)
dev.mouse_joystick_controller.get_assay_status()
dev.mouse_joystick_controller.move_joystick_to_base_position()
dev.mouse_joystick_controller.move_joystick_to_reach_position()
duration = 10
count = 1
dev.mouse_joystick_controller.activate_lickport(duration,count)
dev.mouse_joystick_controller.get_trial_timing_data()
dev.mouse_joystick_controller.abort_trial()

Command Line

Example Set CSV Input File

repeat\_trial\_count,pull\_torque,lickport\_reward\_duration,zero\_torque\_reward\_delay,reach\_position.0,reach\_position.1
2,50,100,0,20,200
3,75,120,0,30,300
2,0,100,3,5,200

Example Trials CSV Ouput File

finished\_trial\_count,successful\_trial\_count,trial\_aborted,assay\_aborted,pull\_threshold,set\_in\_assay,repeat\_set\_count,block\_in\_set,block\_count,trial\_in\_block,block.repeat\_trial\_count,block.pull\_torque,block.lickport\_reward\_duration,block.zero\_torque\_reward\_delay,block.reach\_position.0,block.reach\_position.1,trial\_start,mouse\_ready,joystick\_ready,pull,push,timeout,trial\_abort

Installation

https://github.com/janelia-pypi/python_setup

GNU/Linux

  1. Drivers

    GNU/Linux computers usually have all of the necessary drivers already installed, but users need the appropriate permissions to open the device and communicate with it.

    Udev is the GNU/Linux subsystem that detects when things are plugged into your computer.

    Udev may be used to detect when a device is plugged into the computer and automatically give permission to open that device.

    If you plug a sensor into your computer and attempt to open it and get an error such as: "FATAL: cannot open /dev/ttyACM0: Permission denied", then you need to install udev rules to give permission to open that device.

    Udev rules may be downloaded as a file and placed in the appropriate directory using these instructions:

    99-platformio-udev.rules

  2. Download rules into the correct directory

    curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
    
  3. Restart udev management tool

    sudo service udev restart
    
  4. Ubuntu/Debian users may need to add own “username” to the “dialout” group

    sudo usermod -a -G dialout $USER
    sudo usermod -a -G plugdev $USER
    
  5. After setting up rules and groups

    You will need to log out and log back in again (or reboot) for the user group changes to take effect.

    After this file is installed, physically unplug and reconnect your board.

Python Code

The Python code in this library may be installed in any number of ways, chose one.

  1. pip

    python3 -m venv ~/venvs/mouse_joystick_interface
    source ~/venvs/mouse_joystick_interface/bin/activate
    pip install mouse_joystick_interface
    
  2. guix

    Setup guix-janelia channel:

    https://github.com/guix-janelia/guix-janelia

    guix install python-mouse-joystick-interface
    

Windows

Python Code

The Python code in this library may be installed in any number of ways, chose one.

  1. pip

    python3 -m venv C:\venvs\mouse_joystick_interface
    C:\venvs\mouse_joystick_interface\Scripts\activate
    pip install mouse_joystick_interface
    

Development

Clone Repository

git clone git@github.com:janelia-pypi/mouse_joystick_interface_python.git
cd mouse_joystick_interface_python

Guix

Install Guix

Install Guix

Edit metadata.org

make -f .metadata/Makefile metadata-edits

Tangle metadata.org

make -f .metadata/Makefile metadata

Develop Python package

make -f .metadata/Makefile guix-dev-container
exit

Test Python package using ipython shell

make -f .metadata/Makefile guix-dev-container-ipython
import mouse_joystick_interface
exit

Test Python package installation

make -f .metadata/Makefile guix-container
exit

Upload Python package to pypi

make -f .metadata/Makefile upload

Test direct device interaction using serial terminal

make -f .metadata/Makefile guix-dev-container-port-serial # PORT=/dev/ttyACM0
# make -f .metadata/Makefile PORT=/dev/ttyACM1 guix-dev-container-port-serial
? # help
[C-a][C-x] # to exit

Docker

Install Docker Engine

https://docs.docker.com/engine/

Develop Python package

make -f .metadata/Makefile docker-dev-container
exit

Test Python package using ipython shell

make -f .metadata/Makefile docker-dev-container-ipython
import mouse_joystick_interface
exit

Test Python package installation

make -f .metadata/Makefile docker-container
exit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mouse_joystick_interface-5.0.1.tar.gz (10.1 kB view hashes)

Uploaded Source

Built Distribution

mouse_joystick_interface-5.0.1-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page