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
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <locomotor/publishers.h>
00036 #include <nav_2d_utils/path_ops.h>
00037 #include <nav_2d_utils/conversions.h>
00038 #include <nav_msgs/Path.h>
00039 #include <geometry_msgs/Twist.h>
00040 #include <string>
00041
00042 namespace locomotor
00043 {
00044 PathPublisher::PathPublisher(ros::NodeHandle& nh)
00045 {
00046 std::string topic, publish_type;
00047 nh.param("global_plan_topic", topic, std::string("global_plan"));
00048 nh.param("global_plan_type", publish_type, std::string("Path3D"));
00049 nh.param("global_plan_epsilon", global_plan_epsilon_, 0.1);
00050
00051 if (publish_type == "Path2D")
00052 {
00053 path_type_ = PathType::PATH_2D;
00054 pub_ = nh.advertise<nav_2d_msgs::Path2D>(topic, 1);
00055 }
00056 else if (publish_type == "")
00057 {
00058 path_type_ = PathType::NO_PATH;
00059 }
00060 else
00061 {
00062 if (publish_type != "Path3D")
00063 {
00064 ROS_ERROR_NAMED("Locomotor", "Unknown global_plan_type \"%s\". Using Path3D instead.", publish_type.c_str());
00065 }
00066 path_type_ = PathType::PATH_3D;
00067 pub_ = nh.advertise<nav_msgs::Path>(topic, 1);
00068 }
00069 }
00070
00071 void PathPublisher::publishPath(const nav_2d_msgs::Path2D& global_plan)
00072 {
00073 if (pub_.getNumSubscribers() == 0) return;
00074
00075 nav_2d_msgs::Path2D to_publish = global_plan;
00076 if (global_plan_epsilon_ >= 0.0)
00077 {
00078 to_publish = nav_2d_utils::compressPlan(global_plan, global_plan_epsilon_);
00079 }
00080 switch (path_type_)
00081 {
00082 case PathType::PATH_2D:
00083 pub_.publish(to_publish);
00084 break;
00085 case PathType::PATH_3D:
00086 pub_.publish(nav_2d_utils::pathToPath(to_publish));
00087 break;
00088 case PathType::NO_PATH:
00089 break;
00090 };
00091 }
00092
00093 TwistPublisher::TwistPublisher(ros::NodeHandle& nh)
00094 {
00095 std::string topic, publish_type;
00096 nh.param("twist_topic", topic, std::string("cmd_vel"));
00097 nh.param("twist_type", publish_type, std::string("Twist3D"));
00098
00099 ros::NodeHandle global_nh;
00100 if (publish_type == "Twist2D")
00101 {
00102 twist_type_ = TwistType::TWIST_2D;
00103 pub_ = global_nh.advertise<nav_2d_msgs::Twist2D>(topic, 1);
00104 }
00105 else if (publish_type == "Twist2DStamped")
00106 {
00107 twist_type_ = TwistType::TWIST_2D_STAMPED;
00108 pub_ = global_nh.advertise<nav_2d_msgs::Twist2DStamped>(topic, 1);
00109 }
00110 else if (publish_type == "")
00111 {
00112 twist_type_ = TwistType::NO_TWIST;
00113 }
00114 else
00115 {
00116 if (publish_type != "Twist3D")
00117 {
00118 ROS_ERROR_NAMED("Locomotor", "Unknown twist_type \"%s\". Using Twist3D instead.", publish_type.c_str());
00119 }
00120 twist_type_ = TwistType::TWIST_3D;
00121 pub_ = global_nh.advertise<geometry_msgs::Twist>(topic, 1);
00122 }
00123 }
00124
00125 void TwistPublisher::publishTwist(const nav_2d_msgs::Twist2DStamped& command)
00126 {
00127 if (pub_.getNumSubscribers() == 0) return;
00128 switch (twist_type_)
00129 {
00130 case TwistType::TWIST_2D:
00131 pub_.publish(command.velocity);
00132 break;
00133 case TwistType::TWIST_2D_STAMPED:
00134 pub_.publish(command);
00135 break;
00136 case TwistType::TWIST_3D:
00137 pub_.publish(nav_2d_utils::twist2Dto3D(command.velocity));
00138 break;
00139 case TwistType::NO_TWIST:
00140 break;
00141 };
00142 }
00143
00144 }