Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
UDP Accelerometer data transmission
import socket
from pyvmu import vmu931, messages
class VMUTransmit(object):
def __init__(self, ip, port, device="/dev/tty.usbmodem1411", euler=True, accelerometer=True, quaternion=True):
self.__device = device
self.__euler = euler
self.__accelerometer = accelerometer
self.__quaternion = quaternion
self.__ip = ip
self.__port = port
def start(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
with vmu931.VMU931Parser(device=self.__device, quaternion=self.__quaternion, euler=self.__euler, accelerometer=self.__accelerometer) as vp:
while True:
p = vp.parse()
if isinstance(p, messages.Euler):
ts, x, y, z = p
sock.sendto("e:{},{},{},{}".format(ts, x, y, z).encode(), (self.__ip, self.__port))
elif isinstance(p, messages.Accelerometer):
ts, x, y, z = p
sock.sendto("a:{},{},{},{}".format(ts, x, y, z).encode(), (self.__ip, self.__port))
elif isinstance(p, messages.Quaternion):
t, w, x, y, z = p
sock.sendto("q:{},{},{},{},{}".format(ts, w, x, y, z).encode(), (self.__ip, self.__port))
if __name__ == "__main__":
vmut = VMUTransmit(ip="", port=1234)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.