Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <ros/ros.h>
00025 #include <ros/console.h>
00026
00027 #include <mavros/utils.h>
00028 #include <mavconn/interface.h>
00029
00030 #include <mavros/Mavlink.h>
00031
00032 using namespace mavros;
00033 using namespace mavconn;
00034
00035 ros::Publisher mavlink_pub;
00036 ros::Subscriber mavlink_sub;
00037 MAVConnInterface::Ptr gcs_link;
00038
00039 void mavlink_pub_cb(const mavlink_message_t *mmsg, uint8_t sysid, uint8_t compid) {
00040 MavlinkPtr rmsg = boost::make_shared<Mavlink>();
00041
00042 rmsg->header.stamp = ros::Time::now();
00043 mavutils::copy_mavlink_to_ros(mmsg, rmsg);
00044 mavlink_pub.publish(rmsg);
00045 };
00046
00047 void mavlink_sub_cb(const Mavlink::ConstPtr &rmsg) {
00048 mavlink_message_t mmsg;
00049
00050 if (mavutils::copy_ros_to_mavlink(rmsg, mmsg))
00051 gcs_link->send_message(&mmsg, rmsg->sysid, rmsg->compid);
00052 else
00053 ROS_ERROR("Packet drop: illegal payload64 size");
00054 };
00055
00056 int main(int argc, char *argv[])
00057 {
00058 ros::init(argc, argv, "gcs_bridge");
00059 ros::NodeHandle priv_nh("~");
00060 ros::NodeHandle mavlink_nh("/mavlink");
00061
00062 std::string gcs_url;
00063 priv_nh.param<std::string>("gcs_url", gcs_url, "udp://@");
00064
00065 try {
00066 gcs_link = MAVConnInterface::open_url(gcs_url);
00067 }
00068 catch (mavconn::DeviceError &ex) {
00069 ROS_FATAL("GCS: %s", ex.what());
00070 return 1;
00071 }
00072
00073 mavlink_pub = mavlink_nh.advertise<Mavlink>("to", 10);
00074 gcs_link->message_received.connect(mavlink_pub_cb);
00075
00076 mavlink_sub = mavlink_nh.subscribe("from", 10, mavlink_sub_cb,
00077 ros::TransportHints()
00078 .unreliable()
00079 .maxDatagramSize(1024));
00080
00081 ros::spin();
00082 return 0;
00083 }
00084