waypoint_publisher.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2015 Fadri Furrer, ASL, ETH Zurich, Switzerland
00003  * Copyright 2015 Michael Burri, ASL, ETH Zurich, Switzerland
00004  * Copyright 2015 Mina Kamel, ASL, ETH Zurich, Switzerland
00005  * Copyright 2015 Janosch Nikolic, ASL, ETH Zurich, Switzerland
00006  * Copyright 2015 Markus Achtelik, ASL, ETH Zurich, Switzerland
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *     http://www.apache.org/licenses/LICENSE-2.0
00013 
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  */
00020 
00021 #include <fstream>
00022 #include <iostream>
00023 
00024 #include <Eigen/Core>
00025 #include <mav_msgs/conversions.h>
00026 #include <mav_msgs/default_topics.h>
00027 #include <ros/ros.h>
00028 #include <trajectory_msgs/MultiDOFJointTrajectory.h>
00029 
00030 int main(int argc, char** argv) {
00031   ros::init(argc, argv, "waypoint_publisher");
00032   ros::NodeHandle nh;
00033   ros::Publisher trajectory_pub =
00034       nh.advertise<trajectory_msgs::MultiDOFJointTrajectory>(
00035       mav_msgs::default_topics::COMMAND_TRAJECTORY, 10);
00036 
00037   ROS_INFO("Started waypoint_publisher.");
00038 
00039   ros::V_string args;
00040   ros::removeROSArgs(argc, argv, args);
00041 
00042   double delay;
00043 
00044   if (args.size() == 5) {
00045     delay = 1.0;
00046   } else if (args.size() == 6) {
00047     delay = std::stof(args.at(5));
00048   } else {
00049     ROS_ERROR("Usage: waypoint_publisher <x> <y> <z> <yaw_deg> [<delay>]\n");
00050     return -1;
00051   }
00052 
00053   const float DEG_2_RAD = M_PI / 180.0;
00054 
00055   trajectory_msgs::MultiDOFJointTrajectory trajectory_msg;
00056   trajectory_msg.header.stamp = ros::Time::now();
00057 
00058   Eigen::Vector3d desired_position(std::stof(args.at(1)), std::stof(args.at(2)),
00059                                    std::stof(args.at(3)));
00060 
00061   double desired_yaw = std::stof(args.at(4)) * DEG_2_RAD;
00062 
00063   mav_msgs::msgMultiDofJointTrajectoryFromPositionYaw(desired_position,
00064       desired_yaw, &trajectory_msg);
00065 
00066   // Wait for some time to create the ros publisher.
00067   ros::Duration(delay).sleep();
00068 
00069   while (trajectory_pub.getNumSubscribers() == 0 && ros::ok()) {
00070     ROS_INFO("There is no subscriber available, trying again in 1 second.");
00071     ros::Duration(1.0).sleep();
00072   }
00073 
00074   ROS_INFO("Publishing waypoint on namespace %s: [%f, %f, %f].",
00075            nh.getNamespace().c_str(),
00076            desired_position.x(),
00077            desired_position.y(),
00078            desired_position.z());
00079 
00080   trajectory_pub.publish(trajectory_msg);
00081 
00082   ros::spinOnce();
00083   ros::shutdown();
00084 
00085   return 0;
00086 }


rotors_gazebo
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Thu Apr 18 2019 02:43:49