12 #include <nav_msgs/Path.h> 13 #include <geometry_msgs/PoseStamped.h> 14 #include <geometry_msgs/Pose.h> 15 #include <ros/package.h> 17 #include <eigen3/Eigen/Dense> 55 nh_.param<
string>(
"path_frame", path_frame,
"ocean");
56 nh_.param<
string>(
"wp_file_name", wp_file_name,
"resources/path.txt");
57 nh_.param<
float>(
"plan_res", plan_res, 1.0);
61 path_.header.frame_id = path_frame;
77 path_.header.stamp = ros::Time::now();
91 string package_path = ros::package::getPath(
"mf_experiments");
92 string file_path = package_path +
'/' + file_name;
94 std::ifstream file(file_path.c_str());
96 if (!file.is_open()) {
97 ROS_WARN(
"[control_tester] Path file couldn't be opened at: %s", file_path.c_str());
102 vector<Eigen::Vector3f> p(0);
103 vector<Eigen::Vector3f> o(0);
106 for (
string line; std::getline(file, line); ) {
108 p.emplace_back(Eigen::Vector3f());
109 o.emplace_back(Eigen::Vector3f());
110 std::istringstream in(line);
111 in >> p[k](0) >> p[k](1) >> p[k](2) >> o[k](0) >> o[k](1) >> o[k](2);
120 path_.poses.resize(0);
121 bool last_reached =
false;
124 while (!last_reached) {
128 spline.
evaluate(t, p, o, last_reached);
131 geometry_msgs::PoseStamped pose;
132 pose.pose.position.x = p(0);
133 pose.pose.position.y = p(1);
134 pose.pose.position.z = p(2);
135 to_quaternion(0.0, -asin(o(2)), atan2(o(1), o(0)), pose.pose.orientation);
137 path_.poses.emplace_back(pose);
154 int main(
int argc,
char **argv)
156 ros::init(argc, argv,
"traj_publisher");
void evaluate(float t, Eigen::Vector3f &position, Eigen::Vector3f &orientation, bool &last_reached)
Evaluates the spline at a specific time instant (assuming constant speed)
Declaration of a node to generate hard-coded trajectories.
void to_quaternion(double roll, double pitch, double yaw, tf2::Quaternion &quat)
Converts Roll-Pitch-Yaw Euler angles to a quaternion.
ros::NodeHandle nh_
Node handler.
int main(int argc, char **argv)
Main function called before node initialisation.
Declaration of common functions.
Declaration of a class for 3D spline interpolation.
Class to publish hard-coded trajectories.
void load_path(std::string file_name, float resolution, nav_msgs::Path &path)
Loads a path from a text file.
void run_node()
Runs the node.
nav_msgs::Path path_
Path to publish.
void init_node()
Initialises the node and its parameters.
ros::Publisher path_pub_
Publisher for a path.
bool path_loaded_
Whether the path was loaded with success.
Class for spline interpolation.