Created
April 21, 2021 08:34
-
-
Save dayjaby/cbe9f027a7d48638c776ca8512058b29 to your computer and use it in GitHub Desktop.
ROS mavlink subscriptions and publications
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
import rospy | |
from mavros import mavlink | |
from mavros_msgs.msg import Mavlink | |
from pymavlink.dialects.v20 import common | |
class MavlinkPublicationTest: | |
def __init__(self): | |
self.mav = common.MAVLink(None) | |
self.mav_pub = rospy.Publisher("/mavlink/to", Mavlink, queue_size=10) | |
msg = common.MAVLink_command_long_message( | |
target_system=0, | |
target_component=0, | |
command=205, | |
confirmation=0, | |
param1=90, # pitch | |
param2=0, # roll | |
param3=0, # yaw | |
param4=0, | |
param5=0, | |
param6=0, | |
param7=2 | |
) | |
msg.pack(self.mav) # you can add ,force_mavlink1=True here if you need mavlink version 1 | |
self.mav_pub.publish(mavlink.convert_to_rosmsg(msg)) |
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
import rospy | |
from mavros import mavlink | |
from mavros_msgs.msg import Mavlink | |
from pymavlink.dialects.v20 import common | |
class MavlinkSubscriptionTest: | |
def __init__(self): | |
self.mav = common.MAVLink(None) | |
rospy.Subscriber("/mavlink/from", Mavlink, self.on_mavlink) | |
def on_mavlink(self, msg): | |
if msg.msgid == 24: | |
gps_raw_int = self.mav.decode(mavlink.convert_to_bytes(msg)) | |
self.gps_fix_type = gps_raw_int.fix_type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment