Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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