waypoint_publisher.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Fadri Furrer, ASL, ETH Zurich, Switzerland
3  * Copyright 2015 Michael Burri, ASL, ETH Zurich, Switzerland
4  * Copyright 2015 Mina Kamel, ASL, ETH Zurich, Switzerland
5  * Copyright 2015 Janosch Nikolic, ASL, ETH Zurich, Switzerland
6  * Copyright 2015 Markus Achtelik, ASL, ETH Zurich, Switzerland
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #include <fstream>
22 #include <iostream>
23 
24 #include <Eigen/Core>
25 #include <mav_msgs/conversions.h>
27 #include <ros/ros.h>
28 #include <trajectory_msgs/MultiDOFJointTrajectory.h>
29 
30 int main(int argc, char** argv) {
31  ros::init(argc, argv, "waypoint_publisher");
33  ros::Publisher trajectory_pub =
34  nh.advertise<trajectory_msgs::MultiDOFJointTrajectory>(
36 
37  ROS_INFO("Started waypoint_publisher.");
38 
40  ros::removeROSArgs(argc, argv, args);
41 
42  double delay;
43 
44  if (args.size() == 5) {
45  delay = 1.0;
46  } else if (args.size() == 6) {
47  delay = std::stof(args.at(5));
48  } else {
49  ROS_ERROR("Usage: waypoint_publisher <x> <y> <z> <yaw_deg> [<delay>]\n");
50  return -1;
51  }
52 
53  const float DEG_2_RAD = M_PI / 180.0;
54 
55  trajectory_msgs::MultiDOFJointTrajectory trajectory_msg;
56  trajectory_msg.header.stamp = ros::Time::now();
57 
58  Eigen::Vector3d desired_position(std::stof(args.at(1)), std::stof(args.at(2)),
59  std::stof(args.at(3)));
60 
61  double desired_yaw = std::stof(args.at(4)) * DEG_2_RAD;
62 
64  desired_yaw, &trajectory_msg);
65 
66  // Wait for some time to create the ros publisher.
67  ros::Duration(delay).sleep();
68 
69  while (trajectory_pub.getNumSubscribers() == 0 && ros::ok()) {
70  ROS_INFO("There is no subscriber available, trying again in 1 second.");
71  ros::Duration(1.0).sleep();
72  }
73 
74  ROS_INFO("Publishing waypoint on namespace %s: [%f, %f, %f].",
75  nh.getNamespace().c_str(),
76  desired_position.x(),
77  desired_position.y(),
78  desired_position.z());
79 
80  trajectory_pub.publish(trajectory_msg);
81 
82  ros::spinOnce();
83  ros::shutdown();
84 
85  return 0;
86 }
ros::NodeHandle nh
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define M_PI
void publish(const boost::shared_ptr< M > &message) const
std::vector< std::string > V_string
int main(int argc, char **argv)
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
const std::string & getNamespace() const
static Time now()
void msgMultiDofJointTrajectoryFromPositionYaw(const Eigen::Vector3d &position, double yaw, trajectory_msgs::MultiDOFJointTrajectory *msg)
ROSCPP_DECL void shutdown()
ROSCPP_DECL void removeROSArgs(int argc, const char *const *argv, V_string &args_out)
bool sleep() const
uint32_t getNumSubscribers() const
static constexpr char COMMAND_TRAJECTORY[]
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)


rotors_gazebo
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Mon Feb 28 2022 23:39:12