it is an infinite loop, however computational time is pretty low. Most of the time is spent waiting for playerc_client_read(client); to have new data available.

You could run it in a separate thread, but then you need some method of communicating between the two threads. Easier would be to put that code inside your main loop, and assuming your main loop completes often enough it would be fine.


while(1) {
  /* distance code from above */

 /* The code inside your main loop from your existing project */

It could also be implemented as a driver, either that requires a position2d device and does similar to what i posted, or that exists as part of the existing driver and also supports a position1d device with distance. However modifying the driver might be more difficult than it is worth.

On Wed, Apr 23, 2008 at 4:03 PM, Giulio Zecca <> wrote:
Yes, that's kinda what I was thinking about.
The matter is:
 - isn't it getting too much computational power/time for the infinite
 - I suppose that should run on a separate thread, ain't it?


On Wed, 2008-04-23 at 15:26 -0400, Kevin Barry wrote:
> You will have to write one.
> Something like (this is untested)
> oldpx = 0;
> oldpy = 0;
> dist = 0;
> while(1) {
>  player_client_read(client);
>  /* Add distance traveled this cycle to total distance traveled */
>  dist += sqrt( pow(pos2d.px - oldpx, 2), pow( - oldpy, 2) );
> /* Save current position for next cycle */
>  oldpx = pos2d.px;
>  oldpy =;
> }
> On Wed, Apr 23, 2008 at 2:55 PM, Giulio Zecca <>
> wrote:
>         Thanks for the answer, but that function only prints:
>         xpos   ypos    theta   speed   sidespeed       turn    stall
>         I need instead a function to show how many meters the robot
>         covered up
>         to the time of the call, which, of course, is quite different
>         from the
>         mere linear distance.
>         i.e. when the robot reaches its target, my code will print
>         both the
>         shortest path and the real distance made by the robot.
>         So, is there a function to show the accumulated distance?
>         Or do I have to write one? (in that case, any hint will be
>         appreciated)
>         Thanks

This email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.;198757673;13503038;p?
Playerstage-users mailing list