ROS创建移动的类
ROS create class that moves the turtlesim
我想创建一个将 turtlesim 节点移动到 x,y 位置的类。但是,当我检查 rostopic/turtle1/cmd_vel 时,它没有显示任何扭曲,并且 turtlesim 节点根本没有移动。我仍然得到的位置,但由于没有移动,所以它只是永远卡在while循环中。任何帮助将不胜感激。
class PathFinding{
Private:
turtlesim::Pose initLocation;
turtlesim::Pose finalLocation;
double distance_tolerance;
ros::Publisher cmd_vel_pub;
ros::Subscriber pose_sub;
ros::NodeHandle nh;
public:
PathFinding(turtlesim::Pose goal, double d, ros::NodeHandle &n){
finalLocation = goal;
nh = n;
distance_tolerance = d;
cmd_vel_pub = nh.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel", 10);
pose_sub = nh.subscribe("/turtle1/pose", 1000, &PathFinding::poseCallBack,this);
}
double getDistance(double x1, double y1, double x2,double y2){
return sqrt(pow((x1-x2),2) + pow((y1-y2),2));
}
void moveGoal(){
geometry_msgs::Twist vel_msg;
ros::Rate loop_rate(10);
do{
vel_msg.linear.x = 1.5*getDistance(initLocation.x,initLocation.y,finalLocation.x,finalLocation.y);
vel_msg.linear.y = 0;
vel_msg.linear.z = 0;
vel_msg.angular.x = 0;
vel_msg.angular.y = 0;
vel_msg.angular.z = 4*(atan2(finalLocation.y-initLocation.y,finalLocation.x-initLocation.x) - initLocation.theta);
cmd_vel_pub.publish(vel_msg);
ros::spinOnce();
loop_rate.sleep();
}
while(getDistance(initLocation.x,initLocation.y,finalLocation.x,finalLocation.y) > distance_tolerance);
vel_msg.linear.x = 0;
vel_msg.angular.z = 0;
cmd_vel_pub.publish(vel_msg);
}
void poseCallBack(const turtlesim::Pose &p_msg){
initLocation.x = p_msg.x;
initLocation.y = p_msg.y;
initLocation.theta = p_msg.theta;
}
};
}
这就是我使用它的方式:
int main(int argc, char **argv) {
ros::init(argc, argv, "turtleClassMoving");
ros::NodeHandle n;
turtlesim::Pose goal;
goal.x = 1;
goal.y = 1;
goal.theta = 0;
PathFinding t(goal, 0.5, n);
t.moveGoal();
ros::spin();
return(0);
}
将节点句柄传递给类时的一个常见错误(如您的情况(是忘记传递专用节点句柄。因此,也许您的程序实际上正在发送有关主题的命令,但不是您期望的命令。
因此,首先检查是否发送了任何其他cmd vel
罗托姆列表
如果如我所料,有一个类似的名称主题,具有不同的前缀,请尝试将您的 main 修改为
ros::NodeHandle n("~"(;
相关文章:
- 在从仅移动类型派生的类中定义析构函数在使用 std::vector emplace_back或push_back创建时会
- Qt 创建器:将库移动到 subdir 后无法打开共享对象文件
- 从从可调用参数创建的线程对象参数移动构造 C++11 线程
- c++ 从成员函数创建新线程并移动对象和整个对象
- 如何找到通过仅移动相邻字符创建的字符串的排列?-C++
- ROS创建移动的类
- 通过移动从两个向量创建元组向量
- 创建一个移动分配函数,不断得到"pointer being freed was not allocated"
- std ::移动不要创建派生类
- 如何创建可变参数模板函数来移动参数值并处理左值和右值
- 绘制像素以在Qt中创建移动效果
- 将原始指针移动到已创建函数中的下一个字符
- 我正在从 C 移动到 C++ 并且我没有得到这个类的创建
- 为什么在这种情况下不调用我的移动构造函数?(首先分配 r 值引用并创建对象)
- 如果 std::string 从未被修改,它可以在创建后移动吗?
- 是否可以创建一个只有const/reference成员的可移动类
- 使用可移动节点创建有向图(使用 QT / Boost)
- 将 QFile::copy 创建创建文件的副本或将内容从一个文件移动到另一个文件
- 首先创建字符串,然后通过移动语义将其添加到 vector 或在 vector 中创建元素是否具有内存效率
- 如何以编程方式区分由 subst 命令创建的虚拟驱动器和实际的可移动驱动器