-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Python node to relay from /mavros/set_point/global to /ap/cmd_gps_pose. Signed-off-by: Rhys Mainwaring <[email protected]>
- Loading branch information
1 parent
f270841
commit 9ac5fd8
Showing
1 changed file
with
64 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,64 @@ | ||
""" | ||
ROS 2 node to convert from mavros_msgs/GlobalPositionTarget Message | ||
to ardupilot_msgs/GlobalPosition | ||
""" | ||
|
||
import sys | ||
|
||
import rclpy | ||
from rclpy.executors import ExternalShutdownException | ||
from rclpy.node import Node | ||
|
||
from mavros_msgs.msg import GlobalPositionTarget | ||
from ardupilot_msgs.msg import GlobalPosition | ||
|
||
|
||
class GlobalPositionRelay(Node): | ||
def __init__(self): | ||
super().__init__("global_position_relay") | ||
|
||
self.pub = self.create_publisher( | ||
GlobalPosition, | ||
"/ap/cmd_gps_pose", | ||
10, | ||
) | ||
|
||
self.sub = self.create_subscription( | ||
GlobalPositionTarget, | ||
"/mavros/setpoint_raw/global", | ||
self.global_position_cb, | ||
10, | ||
) | ||
|
||
def global_position_cb(self, msg): | ||
|
||
pos_msg = GlobalPosition() | ||
pos_msg.header = msg.header | ||
pos_msg.header.frame_id = "map" | ||
pos_msg.latitude = msg.latitude | ||
pos_msg.longitude = msg.longitude | ||
pos_msg.altitude = msg.altitude | ||
|
||
self.pub.publish(pos_msg) | ||
|
||
self.get_logger().info("recv: {}\n".format(msg)) | ||
self.get_logger().info("send: {}\n".format(pos_msg)) | ||
|
||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
|
||
node = GlobalPositionRelay() | ||
try: | ||
rclpy.spin(node) | ||
except KeyboardInterrupt: | ||
pass | ||
except ExternalShutdownException: | ||
sys.exit(1) | ||
finally: | ||
node.destroy_node() | ||
rclpy.try_shutdown() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |