gpt4 book ai didi

c++ - PID Controller ,用于以速度行进精确的距离

转载 作者:太空狗 更新时间:2023-10-29 20:44:55 24 4
gpt4 key购买 nike

我试图通过以线速度发送消息来让模拟中的机器人移动精确的距离。现在我的实现并没有让机器人移动一个精确的距离。这是一些示例代码:

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 Controller 用于反馈回路可以解决这个问题,但在阅读维基百科页面后,我并没有真正理解在这种情况下如何使用它。维基百科页面有 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 Controller 考虑三件事:

错误:你想去哪里 vs. 你现在在哪里

这当然是一个很大的因素。如果您在 A 点,而您的目标在 B 点,那么从 A 到 B 的 vector 会告诉您很多关于您需要如何转向的信息,但这并不是唯一的因素。

导数:你接近的速度有多快

如果你正在快速接近目标并且已经接近目标,那么你实际上需要减速。导数有助于考虑到这一点。

积分:对齐错误

您的机器人实际上可能不会完全按照您的指示去做。积分有助于确定您需要补偿多少。

关于c++ - PID Controller ,用于以速度行进精确的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11999776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com