Search code examples
geometryrosrobotics

How can I make a turtlebot in ROS circle around another turtlebot that I am controlling?


Let's say I have a turtlebot which I am controlling and a second turtlebot that should circle around the first turtlebot with a radius r and constant angular speed w. Given the first turtlebot's coordinates in the second turtlebot's coordinate frame (x, y, theta) what translational and angular velocity do I need to set to the second turtlebot to make it circle around the first turtlebot?


Solution

  • That would be both variable and dependent on the relative movement of the first, which is non-deterministic (because you are controlling it). It would be simpler to continuously update the second's target position and incrementally determine the path (bearing, distance) to that position.

    So if for example your desired angular velocity about the first were 5 degrees per second, and you were updating position every 100ms, that is an increment per iteration of 0.05degrees. So given the current angle theta at time t, and the first's position x1,y1, then the target position of the second x2’,y2’ would be:

    • x2’ = x1 + r cos(theta)
    • y2’ = y1 + r sin(theta)

    So at time t and current position x2,y2; you determine the distance and bearing from x2,y2 to x2’,y2’, at a velocity determined by the distance and the time increment (100ms) and execute that.

    At time t + n (where n is the update interval - 100ms in my example), you calculate a new target from the current position (not the previous target, which may not have been achieved), and the updated angle theta.

    This approach has the advantage that if the starting position is not in the orbit, it will "catch up" (subject to some maximum velocity limit) to reduce the error tending to zero until it is "captured".

    Essentially this is a process of "given the current position of the first, where should the second be" then aiming to reach that position.

    You could refine this by, given the current trajectory of the first, predicting its position at t+n and targeting that position. But given a sufficiently small value of n, that is probably an unnecessary refinement.

    One refinement that may be necessary is in the initial capture. The above proposal may lead to somewhat erratic behaviour attempting to achieve a moving target about a moving target. In that case if the distance between the two >> r then you should not update theta over time, but rather set it to the angle between the two until near r.

    You might further refine that by calculating a "collision point" trajectory, allowing an optimal straight-line path to reach the orbit (if the first remains in a constant trajectory).