Ask Your Question

ros2 how to make turtlesim use the same turtle every time ?

asked 2022-05-04 09:07:55 -0500

flanel gravatar image

when launching turtlesim I usually get a different looking turtle bot every time, probably it's random. Is there some variable I can use to make turtlesim use the same specific turtle every time ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-05-05 02:54:15 -0500

Joe28965 gravatar image

updated 2022-05-05 03:18:26 -0500

The only parameters that show up in rqt's Dynamic Reconfigure (at least in Foxy) are background_b background_g background_r and use_sim_time so I don't think so.

EDIT: So I checked the source code and I found out that it is indeed random. However, this portion is interesting. That code basically adds all the images from turtlesim/images to a vector and that vector is used to randomly pick a turtlebot.

This means you could build ros tutorials from source and simply delete all the files from the folder turtlesim/images except the one you want.

I'm not 100% sure this will work, but I am 95% sure this is the only way to use the same turtlesim every time.

EDIT 2. I decided to check if it would work. There is 1 small thing you need to change to the source code (besides removing the other images from the folder) to get it to work.

This portion is used to create the vector of images. More specifically its length is used. If you don't change it, there will be a vector of 6 'images' where only the first one really exists and the other 'images' don't exist.

So in order to get it to work, you need to remove the appends except for the append of the turtle you want (e.g. if you want to use the 'ardent' one, remove line 82-86).

I'm not sure if you find it worth it to go through all of this just to get the same turtle, but that's the way I found to do it.

edit flag offensive delete link more


:) Really really appreciate the effort on this tiny question. Your details gave me another idea. I'll just try to rename/replace all the other images with the one I want and see if it works.

Thank you very much

flanel gravatar image flanel  ( 2022-05-05 07:00:53 -0500 )edit

That might work too. However, it might also depend on those images having those names, so you might still need to rename them ardent.pngbouncy.png etc. even if they're all copies of the foxy one (for instance). EDIT you already mentioned rename, so nevermind.

Joe28965 gravatar image Joe28965  ( 2022-05-05 07:23:35 -0500 )edit

Confirmed, it works with replace/rename, thanks @Joe28965

flanel gravatar image flanel  ( 2022-05-06 01:52:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2022-05-04 09:07:55 -0500

Seen: 31 times

Last updated: May 05