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()
Metadata
Release files for HaplyHAPI 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| HaplyHAPI-1.0.1.tar.gz | 6.9 kB | Without provenance | Details for HaplyHAPI-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| HaplyHAPI-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for HaplyHAPI-1.0.1-py3-none-any.whl |
Total release size: 14.0 kB
Release files / HaplyHAPI-1.0.1.tar.gz
| Download URL | HaplyHAPI-1.0.1.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
072712c891a0589a76f031739e9caef0d2dc4213ca10828a41f74d3604953b47
|
|
BLAKE2b-256 checksum How to use checksums |
26f42f7e5d7e2ef622623d1bc113ba076ca365eb06e0d94dff0e7b5ed6a3c74f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / HaplyHAPI-1.0.1-py3-none-any.whl
| Download URL | HaplyHAPI-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd621e0e9253ce843b5be8afd5b2f2291c18e96deb12aeb6792879d07936e386
|
|
BLAKE2b-256 checksum How to use checksums |
cbbd36a8e25765c1c1e26e5b9057185258918cf30aa0cd660e521173d7052f84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for HaplyHAPI 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.