-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsbConnection.py
More file actions
36 lines (25 loc) · 803 Bytes
/
UsbConnection.py
File metadata and controls
36 lines (25 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import serial
import time
import numpy as np
class UsbConnection:
def __init__(self, port, name, is_verbose = False):
self.port = port
self.name = name
self.is_verbose = is_verbose
if is_verbose:
print("\nConnecting to arduino...")
self.arduino_usb = serial.Serial(port = port, baudrate = 9600)
if is_verbose:
print(" Connection successful!")
def WriteData(self, x):
x += "\0"
byte_data = bytes(x, 'utf-8')
self.arduino_usb.write(byte_data)
time.sleep(0.05)
def SendAngles(self, vector3):
if self.is_verbose:
print("\nSending angles", vector3, "...")
position_string = str(int(vector3[0])) + "," + str(int(vector3[1])) + "," + str(int(vector3[2])) + ","
self.WriteData(position_string)
if self.is_verbose:
print(" Angles sent successfully!")