Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8410465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:11:01+00:00 2026-06-10T00:11:01+00:00

I am trying to make a robot in a simulation move an exact distance

  • 0

I am trying to make a robot in a simulation move an exact distance by sending messages with a linear velocity. Right now my implementation doesn’t make the robot move an exact distance. This is some sample code:

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();
    }
}

I asked around and someone suggested that using a PID controller for a feedback loop would solve this problem, but after reading the Wikipedia page I don’t really get how I’d use it in this context. The Wikipedia page has pseudo code for the PID algorithm, but I have no idea what corresponds to what.

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

How would I implement this in the context of velocities and distances? Is distance error? Or velocity? Can anyone help please? What is the integral? Derivative? Kp? Ki? Kd? e.t.c.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:11:03+00:00Added an answer on June 10, 2026 at 12:11 am

    For your problem, the setpoint will be (x,y). process_feedback will be (px,py). and output will be the velocity at which you need to travel. Kp, Ki, and Kd are parameters that you can tune to get the kind of behavior you want. For example, if Kd is too low you could shoot past the target by not slowing down enough as you approach it.

    A PID controller takes three things into consideration:

    error: where you want to be vs. where you are

    This is certainly a big factor. If you are at point A and your target is at point B, then the vector from A to B tells you a lot about how you need to steer, but it isn’t the only factor.

    derivative: how fast you are approaching

    If you are approaching the target quickly and you are close to it, you actually need to slow down. The derivative helps take that into consideration.

    integral: alignment error

    Your robot may not actually do exactly what you tell it to do. The integral helps determine how much you need to compensate for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to program yahoo messenger robot,now my robot can get messages and answer
I'm trying to make a balance_bst(bstNode root) function, but i'm struggling with the implementation.
I am trying to use Robot in Java to make an image file of
i'm trying to test my server, and to do that, i make a robot
I'm trying to make a little programme in C using SDL, displaying a robot
I trying to make a schema for the following xml. <root> <allow_any_name id=string> <required_tag_1>string</required_tag_1>
I'm trying make a login window where a user is prompted to enter their
I'm trying make an entity with doctrine that has three associations with other entities
I am trying make long screen to vertical direction. So, I need a screen
I am fairly new to iOS development and trying make a simple app which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.