-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Wallar
committed
Sep 16, 2015
1 parent
68e6a8b
commit e73ad46
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
tags | ||
|
||
# C extensions | ||
*.so | ||
*.c | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Rope | ||
.ropeproject | ||
|
||
# Django stuff: | ||
*.log | ||
*.pot | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# Tex | ||
*.bak | ||
*.log | ||
*.aux | ||
|
||
# Ctags | ||
tags | ||
|
||
#Chutsu stuff | ||
run.sh | ||
|
||
scenes/*.out | ||
*.out | ||
scenes/ | ||
octave-workspace | ||
sandbox/ | ||
videos | ||
bags/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
__all__ = ["Heart"] | ||
|
||
from heart import Heart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
import socket | ||
import json | ||
import zlib | ||
import rospy | ||
import threading | ||
|
||
|
||
class Heart(object): | ||
|
||
def __init__(self, host, port, rate): | ||
self.host = host | ||
self.port = port | ||
self.rate = rate | ||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
self.data = {} | ||
self.running = False | ||
|
||
def set_data(self, data): | ||
self.data = data | ||
return self | ||
|
||
def beat(self): | ||
json_str = json.dumps(self.data) | ||
zip_str = zlib.compress(json_str) | ||
self.sock.sendto(zip_str, (self.host, self.port)) | ||
return self | ||
|
||
def kill(self): | ||
self.running = False | ||
return self | ||
|
||
def start(self): | ||
if self.running: | ||
raise RuntimeWarning("Heart already running") | ||
else: | ||
def __thread(): | ||
rate = rospy.Rate(self.rate) | ||
while self.running: | ||
self.beat() | ||
rate.sleep() | ||
self.running = True | ||
self.thread = threading.Thread(target=__thread) | ||
self.thread.daemon = True | ||
self.thread.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import os | ||
import sys | ||
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), "../src")) | ||
|
||
import jammi | ||
import socket | ||
import rospy | ||
import zlib | ||
|
||
|
||
def test_start(): | ||
rospy.init_node("jammi_test", anonymous=False) | ||
host, port = "localhost", 5005 | ||
rate = 20 | ||
heart = jammi.Heart(host, port, rate) | ||
heart.data["name"] = "test" | ||
heart.start() | ||
|
||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
sock.bind((host, port)) | ||
i = 0 | ||
while i < 20: | ||
i += 1 | ||
data_zip, addr = sock.recvfrom(1024) | ||
data = zlib.decompress(data_zip) | ||
print i, data, addr | ||
heart.kill() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_start() |