Skip to content

Commit

Permalink
Verify works on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelmassot committed Jun 27, 2023
1 parent de48931 commit 5bf40ee
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

setup(
name="zeroros",
version="1.0.0",
version="1.0.1",
description="ZeroROS middleware",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
5 changes: 5 additions & 0 deletions src/zeroros/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
""" ZeroROS package. """
from .publisher import Publisher # noqa: F401
from .subscriber import Subscriber # noqa: F401
from .message_broker import MessageBroker # noqa: F401
from .datalogger import DataLogger # noqa: F401
7 changes: 5 additions & 2 deletions src/zeroros/message_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import zmq




class MessageBroker:
def __init__(self):
# gather list of topics from pub/subs
self.topics = {}
self.context = None
# run broker in seperate thread
self.broker_thread = threading.Thread(target=self.config_broker)
self.broker_thread.start()
Expand All @@ -16,9 +19,9 @@ def config_broker(self):
# https://zguide.zeromq.org/docs/chapter2/#The-Dynamic-Discovery-Problem
self.context = zmq.Context()
frontend = self.context.socket(zmq.XSUB)
frontend.bind("tcp://127.0.0.1:5559")
frontend.bind("tcp://127.0.0.1:5555")
backend = self.context.socket(zmq.XPUB)
backend.bind("tcp://127.0.0.1:5560")
backend.bind("tcp://127.0.0.1:5556")

# built-in pub/sub fowarder
zmq.proxy(frontend, backend)
Expand Down
20 changes: 19 additions & 1 deletion src/zeroros/messages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
"""This module contains all the messages that are used in ZeroROS."""


class Message:
pass
"""Empty base class for all messages."""


from .geometry_msgs import (
Vector3,
Vector3Stamped,
Twist,
Quaternion,
Pose,
PoseStamped,
PoseWithCovariance,
TwistWithCovariance,
) # noqa: F401
from .sensor_msgs import LaserScan # noqa: F401
from .nav_msgs import Odometry, Path # noqa: F401
from .std_msgs import Header, String, Int, Float, Bool # noqa: F401
19 changes: 19 additions & 0 deletions src/zeroros/messages/geometry_msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ def __str__(self):
self.x, self.y, self.z, self.w
)

def from_euler(self, roll: float, pitch: float, yaw: float):
cy = np.cos(yaw * 0.5)
sy = np.sin(yaw * 0.5)
cp = np.cos(pitch * 0.5)
sp = np.sin(pitch * 0.5)
cr = np.cos(roll * 0.5)
sr = np.sin(roll * 0.5)

self.w = cy * cp * cr + sy * sp * sr
self.x = cy * cp * sr - sy * sp * cr
self.y = sy * cp * sr + cy * sp * cr
self.z = sy * cp * cr - cy * sp * sr

def to_euler(self):
roll = np.arctan2(2.0 * (self.w * self.x + self.y * self.z), 1.0 - 2.0 * (self.x * self.x + self.y * self.y))
pitch = np.arcsin(2.0 * (self.w * self.y - self.z * self.x))
yaw = np.arctan2(2.0 * (self.w * self.z + self.x * self.y), 1.0 - 2.0 * (self.y * self.y + self.z * self.z))
return roll, pitch, yaw

def to_json(self):
return {"x": self.x, "y": self.y, "z": self.z, "w": self.w}

Expand Down
2 changes: 1 addition & 1 deletion src/zeroros/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(
topic: str,
message_class: type[Message],
ip: str = "127.0.0.1",
port: int = 5559,
port: int = 5555,
):
print("Creating publisher for topic: ", topic)
self.topic = validate_topic(topic)
Expand Down
2 changes: 1 addition & 1 deletion src/zeroros/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(
message_class: type[Message],
callback_handle: callable,
ip: str = "127.0.0.1",
port: int = 5560,
port: int = 5556,
):
self.ip = ip
self.port = port
Expand Down

0 comments on commit 5bf40ee

Please sign in to comment.