我试图通过以线速度发送消息来使模拟中的机器人移动精确的距离。现在我的实现并没有让机器人移动一个精确的距离。这是一些示例代码:
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 控制器进行反馈循环可以解决这个问题,但是在阅读了 Wikipedia 页面后,我真的不明白在这种情况下我会如何使用它。维基百科页面有 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
我将如何在速度和距离的背景下实现这一点?是距离误差吗?还是速度?有人可以帮忙吗?什么是积分?衍生物?克普?基?KD?ETC
谢谢。