Python implementation of the haply hAPI
Project description
Python Implementation of the hAPI
This is a python port of the java implementation of the hAPI .
Installation
pip install HaplyHAPI
Usage
Here’s an example of using the hAPI to control a 2diy Haply device. The example is also available in the examples folder.
In this example we will read position of the device and send a constant force.
from HaplyHAPI import Board, Device, Mechanisms, Pantograph
import time
import serial.tools.list_ports
CW = 0
CCW = 1
hardware_version = 3 # 2 for the metallic plate device, 3 for the newer plastic device
haplyBoard = Board
device = Device
SimpleActuatorMech = Mechanisms
pantograph = Mechanisms
com_ports = list(serial.tools.list_ports.comports())
# if only one port is available, use that one, otherwise ask the user to select the correct one
if len(com_ports) == 1:
port = com_ports[0].device
else:
print("Select the COM port for the Haply board:")
for i, port in enumerate(com_ports):
print(str(i) + ": " + port.device)
port = com_ports[int(input())].device
def main():
print("Starting the application!")
haplyBoard = Board("test", port, 0)
device = Device(5, haplyBoard)
pantograph = Pantograph(hardware_version)
device.set_mechanism(pantograph)
#device.add_encoder(1, CCW, 240, 10978, 2)
#device.add_encoder(2, CCW, -60, 10978, 1)
if hardware_version == 3:
device.add_actuator(1, CCW, 2)
device.add_actuator(2, CCW, 1)
device.add_encoder(1, CCW, 168, 4880, 2)
device.add_encoder(2, CCW, 12, 4880, 1)
else:
device.add_actuator(1, CCW, 2)
device.add_actuator(2, CW, 1)
device.add_encoder(1, CCW, 241, 10752, 2)
device.add_encoder(2, CW, -61, 10752, 1)
device.device_set_parameters()
i=0
while(True):
if(haplyBoard.data_available()):
device.device_read_data()
motorAngle = device.get_device_angles()
device_position = device.get_device_position(motorAngle)
print("Device position: " + str(device_position))
i+=1
forces = [0, 10]
device.set_device_torques(forces)
device.device_write_torques()
time.sleep(0.001)
if __name__ == "__main__":
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
HaplyHAPI-1.0.1.tar.gz
(6.9 kB
view details)
Built Distribution
File details
Details for the file HaplyHAPI-1.0.1.tar.gz
.
File metadata
- Download URL: HaplyHAPI-1.0.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 072712c891a0589a76f031739e9caef0d2dc4213ca10828a41f74d3604953b47 |
|
MD5 | c3c348fdd94052f323ca8602b4c36b43 |
|
BLAKE2b-256 | 26f42f7e5d7e2ef622623d1bc113ba076ca365eb06e0d94dff0e7b5ed6a3c74f |
File details
Details for the file HaplyHAPI-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: HaplyHAPI-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd621e0e9253ce843b5be8afd5b2f2291c18e96deb12aeb6792879d07936e386 |
|
MD5 | 3fcf7cb874d59e482c048b08866568a7 |
|
BLAKE2b-256 | cbbd36a8e25765c1c1e26e5b9057185258918cf30aa0cd660e521173d7052f84 |