PID控制器,用于以速度精确行驶距离
PID controllers for travelling an exact distance with velocity
我试图通过以线性速度发送消息来使模拟中的机器人移动精确的距离。现在我的实现并没有使机器人移动精确的距离。这是一些示例代码:
void Robot::travel(double x, double y)
{
// px and py are the current positions (constantly gets updated as the robot moves in the simulation)
// x and y is the target position that I want to go to
double startx = px;
double starty = py;
double distanceTravelled = 0;
align(x, y);
// This gets the distance from the robot's current position to the target position
double distance = calculateDistance(px, py, x, y);
// Message with velocity
geometry_msgs::Twist msg;
msg.linear.x = 1;
msg.angular.z = 0;
ros::Rate loop_rate(10);
while (distanceTravelled < distance)
{
distanceTravelled = calculateDistance(startx, starty, px, py);
// Publishes message telling the robot to move with the linear.x velocity
RobotVelocity_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
}
我四处询问,有人建议使用PID控制器进行反馈循环可以解决这个问题,但是在阅读了维基百科页面后,我真的不知道在这种情况下如何使用它。维基百科页面有PID算法的伪代码,但我不知道什么对应于什么。
previous_error = setpoint - process_feedback
integral = 0
start:
wait(dt)
error = setpoint - process_feedback
integral = integral + (error*dt)
derivative = (error - previous_error)/dt
output = (Kp*error) + (Ki*integral) + (Kd*derivative)
previous_error = error
goto start
我将如何在速度和距离的背景下实现这一点?距离误差吗?还是速度?谁能帮忙?什么是积分?导数?kp?米伊Kd?等
谢谢。
对于您的问题,设定值将为 (x,y)。 process_feedback将是(px,py)。输出将是您需要行驶的速度。 Kp、Ki 和 Kd 是可以调整以获得所需行为类型的参数。 例如,如果Kd太低,您可以通过在接近目标时没有足够减速来射击目标。
PID控制器需要考虑三件事:
错误:你想去的地方与你想去的地方
这当然是一个重要因素。 如果你在A点,你的目标在B点,那么从A到B的向量会告诉你很多关于你需要如何转向的信息,但这不是唯一的因素。
导数:你接近的速度有多快
如果你正在快速接近目标并且你接近它,你实际上需要放慢速度。 导数有助于考虑到这一点。
积分:对齐误差
你的机器人实际上可能不会完全按照你的要求去做。 积分有助于确定您需要补偿多少。
相关文章:
- 为什么在读取文件大小时文件IO速度会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- 文件系统:复制功能的速度秘诀是什么
- 用C++程序计算圆锥体的体积、球体的体积、八边形的面积和两点之间的距离
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 计算所有对之间的曼哈顿距离
- 在C++中使用并行化的预期速度是多少(不是 OpenMp,而是 <thread>)
- 如何使用发送数据包所花费的时间计算两个节点之间的距离?
- Levenshtein 两个文件的距离花费了太多时间
- 两个连续的 OpenMP 并行区域会相互减慢速度
- 查找标准::hash_map与标准::矢量的速度
- 加快在C++中读取/处理日志文件的速度
- 为什么这些算法的运行速度比它们应该的要快?
- 如何提高文件的读取速度?
- 通过libpqxx提高PostgreSQL数据库的更新速度
- 计算车辆之间的距离并设置速度,使距离保持不变,例如 5 米
- PID控制器,用于以速度精确行驶距离
- C++ 初学者,第一个程序.查找速度和距离
- 根据加速度计数据测量速度和距离