gcs_bridge.cpp
Go to the documentation of this file.
00001 
00006 /*
00007  * Copyright 2014 Vladimir Ermakov.
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 3 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00016  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License along
00020  * with this program; if not, write to the Free Software Foundation, Inc.,
00021  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 


mavros
Author(s): Vladimir Ermakov
autogenerated on Wed Aug 26 2015 12:29:13