Skip to content

Commit

Permalink
Added a twist converter that strips the stamp from a twist stamped
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-palmer committed Apr 1, 2024
1 parent ef97915 commit 788fe06
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions mobile_to_maritime/launch/demo.launch.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
launch:
- node:
pkg: mobile_to_maritime
exec: mobile_to_maritime_twist
exec: mobile_twist_to_maritime_twist
name: convert_twist_demo
param:
- name: in_topic
Expand All @@ -18,7 +18,7 @@ launch:

- node:
pkg: mobile_to_maritime
exec: mobile_to_maritime_twist_stamped
exec: mobile_twist_stamped_to_maritime_twist_stamped
name: convert_twist_stamped_demo
param:
- name: in_topic
Expand Down
49 changes: 38 additions & 11 deletions mobile_to_maritime/mobile_to_maritime/mobile_to_maritime.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ def _get_qos_profile_from_params(self) -> QoSProfile:
)

@abstractmethod
def in_callback(self, msg: Any) -> None:
...
def in_callback(self, msg: Any) -> None: ...


class MaritimeToMobileStamped(MobileToMaritime):
class MaritimeStampedToMobileStamped(MobileToMaritime):
def __init__(self, message_type: Any, node_name: str) -> None:
super().__init__(message_type, node_name)

Expand All @@ -96,9 +95,9 @@ def __init__(self, message_type: Any, node_name: str) -> None:
)


class MobileToMaritimeTwist(MobileToMaritime):
class MobileTwistToMaritimeTwist(MobileToMaritime):
def __init__(self) -> None:
super().__init__(Twist, "mobile_to_maritime_twist")
super().__init__(Twist, "mobile_twist_to_maritime_twist")

def in_callback(self, msg: Twist) -> None:
maritime_twist = Twist()
Expand All @@ -114,9 +113,9 @@ def in_callback(self, msg: Twist) -> None:
self.out_pub.publish(maritime_twist)


class MobileToMaritimeTwistStamped(MaritimeToMobileStamped):
class MobileTwistStampedToMaritimeTwistStamped(MaritimeStampedToMobileStamped):
def __init__(self) -> None:
super().__init__(TwistStamped, "mobile_to_maritime_twist_stamped")
super().__init__(TwistStamped, "mobile_twist_stamped_to_maritime_twist_stamped")

def in_callback(self, msg: TwistStamped) -> None:
maritime_twist = TwistStamped()
Expand All @@ -135,20 +134,48 @@ def in_callback(self, msg: TwistStamped) -> None:
self.out_pub.publish(maritime_twist)


def main_mobile_to_maritime_twist(args: list[str] | None = None):
class MobileTwistStampedToMaritimeTwist(MobileToMaritime):
def __init__(self) -> None:
super().__init__(TwistStamped, "mobile_twist_stamped_to_maritime_twist")

def in_callback(self, msg: TwistStamped) -> None:
maritime_twist = Twist()

maritime_twist.linear.x = msg.twist.linear.x
maritime_twist.linear.y = -msg.twist.linear.y
maritime_twist.linear.z = -msg.twist.linear.z

maritime_twist.angular.x = msg.twist.angular.x
maritime_twist.angular.y = -msg.twist.angular.y
maritime_twist.angular.z = -msg.twist.angular.z

self.out_pub.publish(maritime_twist)


def main_mobile_twist_to_maritime_twist(args: list[str] | None = None):
rclpy.init(args=args)

node = MobileTwistToMaritimeTwist()
rclpy.spin(node)

node.destroy_node()
rclpy.shutdown()


def main_mobile_twist_stamped_to_maritime_twist_stamped(args: list[str] | None = None):
rclpy.init(args=args)

node = MobileToMaritimeTwist()
node = MobileTwistStampedToMaritimeTwistStamped()
rclpy.spin(node)

node.destroy_node()
rclpy.shutdown()


def main_mobile_to_maritime_twist_stamped(args: list[str] | None = None):
def main_mobile_twist_stamped_to_maritime_twist(args: list[str] | None = None):
rclpy.init(args=args)

node = MobileToMaritimeTwistStamped()
node = MobileTwistStampedToMaritimeTwist()
rclpy.spin(node)

node.destroy_node()
Expand Down
5 changes: 3 additions & 2 deletions mobile_to_maritime/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
tests_require=["pytest"],
entry_points={
"console_scripts": [
"mobile_to_maritime_twist = mobile_to_maritime.mobile_to_maritime:main_mobile_to_maritime_twist", # noqa
"mobile_to_maritime_twist_stamped = mobile_to_maritime.mobile_to_maritime:main_mobile_to_maritime_twist_stamped", # noqa
"mobile_twist_to_maritime_twist = mobile_to_maritime.mobile_to_maritime:main_mobile_twist_to_maritime_twist", # noqa
"mobile_twist_stamped_to_maritime_twist_stamped = mobile_to_maritime.mobile_to_maritime:main_mobile_twist_stamped_to_maritime_twist_stamped", # noqa
"mobile_twist_stamped_to_maritime_twist = mobile_to_maritime.mobile_to_maritime:main_mobile_twist_stamped_to_maritime_twist", # noqa
],
},
)

0 comments on commit 788fe06

Please sign in to comment.