Giter VIP home page Giter VIP logo

pyopenhaptics's Introduction

pyOpenHaptics

Python wrapper for the OpenHaptics HD library to use the haptic device directly from Python. Used to control the 3dSystems devices (Touch/Touch X) directly from Python.

Prerequisites

This library requires from the pre-installation of the OpenHaptics libraries and Touch X drivers. For this please follow their official installation tutorial for Linux or Windows.

OpenHaptics in Linux requires from additional libraries. You can use the following command to install them.

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install libncurses5-dev freeglut3 build-essential

Installation

Use the latest version from the PyPi project.

python3 -m pip install pyOpenHaptics

How to use it

The library contains multiple functionalities to get and set different variables. Most of the functionalities are gathered into 3 different files hd.py, hd_callback.py and hd_device.py. The first file contains a Python mimic of most of the OpenHaptics HD library main functions. The second file contains the schedulers and a python wrapper to wrap your python callback function into a C callback function to interact with the already compiled shared library. Lastly, this defines the Python class to initialize your Haptic hardware and interface.

Haptic device template

Here is a small template on how to setup your callback loop and your haptic device to gather the desired information from the device.

import pyOpenHaptics.hd as hd
from pyOpenHaptics.hd_callback import hd_callback
from pyOpenHaptics.hd_device import HapticDevice
from dataclasses import dataclass

# Data class to keep track of the device state and use it in other parts of the code
@dataclass
class DeviceState:
    # Define the variables you want to safe here

# Callback to gather the device state
@hd_callback
def device_callback():
    # Make the device_state global to be accesed in other parts of the code
    global device_state
    # your callback function, gather the different variables on the device
    # YOUR CODE HERE

if __name__ == "__main__":
    # Initialize the data class
    device_state = DeviceState()

    # Initialize the haptic device and the callback loop
    device = HapticDevice(callback = device_callback, scheduler_type="async")
    
    # YOUR CODE HERE
    
    # Close the device to avoid segmentation faults
    device.close()

You can find more complex examples here

pyopenhaptics's People

Contributors

mikelitu avatar acercyc avatar

Stargazers

Haonan Chen avatar  avatar Megumi Miyashita avatar mhubii avatar Bava Kesavan avatar

Watchers

 avatar

Forkers

acercyc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.