Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export IMU data to ZMQ PUB #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions mtdevice.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env python
import serial
import struct
import sys
import getopt
import time
import glob
import re
import json
import pprint
import re
import struct
import sys
import time

import serial
import zmq

from mtdef import MID, OutputMode, OutputSettings, MTException, Baudrates, \
XDIGroup, getMIDName, DeviceState, DeprecatedMID, MTErrorMessage, \
MTTimeoutException
from mtdef import (MID, Baudrates, DeprecatedMID, DeviceState, MTErrorMessage,
MTException, MTTimeoutException, OutputMode, OutputSettings,
XDIGroup, getMIDName)


################################################################
Expand All @@ -19,7 +22,7 @@
class MTDevice(object):
"""XSens MT device communication object."""

def __init__(self, port, baudrate=115200, timeout=0.002, autoconf=True,
def __init__(self, port, baudrate=115200, timeout=0.02, autoconf=True,
config_mode=False, verbose=False):
"""Open device."""
self.verbose = verbose
Expand Down Expand Up @@ -1475,8 +1478,15 @@ def main():
# mode, settings, length = mt.auto_config()
# print mode, settings, length
try:
port = "5556"
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:%s" % port)
topic = "imu"
while True:
print mt.read_measurement(mode, settings)
output = mt.read_measurement(mode, settings)
socket.send(json.dumps(output))
print(output)
except KeyboardInterrupt:
pass
except MTErrorMessage as e:
Expand Down