Gazebo | Ignition | Community
Ask Your Question
0

How to build a circuit in gazebo [Update visuals at runtime]

asked 2016-06-08 07:56:37 -0600

savaresef gravatar image

updated 2016-06-28 16:51:30 -0600

Hi all, I am trying to build a circuit in Gazebo but I don't know how I can manage this task. In particular I don't know if I have to Necessarily create a .world file or I can just create a texture for example. I have an image of this circuit and also I can have a gis file, could these files help me? Someone had already faced with this kind of work?

Thanks in advance.

[copied from comments by moderator] I am sorry if I was so inaccurate. I am using Gazebo7 without ROS and I am writing some code for path plannig in autonomous cars scenario. As clarified today by my Ph.D. tutor I just have to update the ground plane texture at runtime. More in detail: I have a module that using Gazebo messages (I don't already know which ones) sends at certain time intervals an image that represents the actual state of the road (for example lanes) and I just want that Gazebo draws for me the new road

UPDATE

Hi all and Hi Peter, I tried to do do what you said but I am not sure that I have done the right things (in fact it doesn't work).

Actually I started from the tutorial at http://gazebosim.org/tutorials?tut=cu... to manage the messages and from your code to update the model.

More precisely:

1: I build a world in which I put a ground model with the texture that I have to modify at runtime.

2: I used all the code that I linked to manage the message exchange but in the function create() I put the code of my interest. I used this function because it seems that is the function that performs the operation when a message arrives. I modified the function in the following way (I commented the initFile because I don't know the perfect meaning and I don't know how to use it and if I have to use it):

 public: void create(CollisionMapRequestPtr &msg)
  {

  std::cout << "Received message" << std::endl;
  modelSDF.reset(new sdf::SDF);
  std::cout << "After Reset"<<std::endl;
  // sdf::initFile("root.sdf", modelSDF);
  sdf::readFile("~/.gazebo/models/my_ground_plane/model.sdf", modelSDF);
  std::cout<< "After reading"<<std::endl;
  world->InsertModelSDF(*modelSDF);
  std::cout << "After inserting"<<std::endl;
  }

Obviously the prints are useful just for debug. As to me it seems to be reasonable.

3:I send a message as shown in the tutorial and before to send it I change the image that I would like use as new texture (is an image exchange so I change the file but I use the same name).

4: I receive the following output (wrong and I have texture no update):

Subscribing to: ~/collision_map/command
[Err] [Scene.cc:2927] Light [sun] not found. Use topic ~/factory/light to spawn a new light.
Received message
After Reset
Error [parser.cc:286] Error finding file [~/.gazebo/models/my_ground_plane/model.sdf].
After reading
After ...
(more)
edit retag flag offensive close merge delete

Comments

What tutorials have you tried? What version of Gazebo are you using? Did you try searching for similar questions on this forum? What is the technical problem with Gazebo that is not working for you?

nkoenig gravatar imagenkoenig ( 2016-06-08 09:36:16 -0600 )edit

also, just curious what is the motivation for doing this?

Peter Mitrano gravatar imagePeter Mitrano ( 2016-06-08 23:37:58 -0600 )edit

I am sorry if I was so inaccurate. I am using Gazebo7 without ROS and I am writing some code for path plannig in autonomous cars scenario. As clarified today by my Ph.D. tutor I just have to update the ground plane texture at runtime. More in detail: I have a module that using Gazebo messages (I don't already know which ones) sends at certain time intervals an image that represents the actual state of the road (for example lanes) and I just want that Gazebo draws for me the new road.

savaresef gravatar imagesavaresef ( 2016-06-09 04:17:58 -0600 )edit

I think we thought you mean electrical circuit...

Peter Mitrano gravatar imagePeter Mitrano ( 2016-06-11 22:51:46 -0600 )edit

Do you need to update collision models? or only visual elements

Peter Mitrano gravatar imagePeter Mitrano ( 2016-06-11 22:53:58 -0600 )edit

I need to update only visual elements. I need just to update road visualization updating lanes for example

savaresef gravatar imagesavaresef ( 2016-06-13 04:36:02 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-06-11 23:02:26 -0600

updated 2016-06-28 17:00:04 -0600

Based on the clarification made in the comments on the original post, I think I understand the question correctly. You want to update characteristics of a model at run time. You mention "draw the new road" and "lane". If you only need to update visual components, then this will be easy. It is still possible with collision elements, but slightly harder.

Here is an example of a project that updates both collision and visual elements of a model.

here's some code and here's some more code

here's a video demo

I use only visuals for creating the little indicators on the maze. video. For visual models, I simply use the gazebo visual message. But I never remove them, I just change their color. I'm not sure how removing them works.

There may be better ways to do this, but the strategy I take for collision models is to delete and regenerate the model. Actually, I do the deletion by hand in gazebo, but you should be able to do it with code as well. Collision messages also exist, but I have not used them.

Lastly, I'll point out that I got a lot of these ideas from the gazebo model editor. Looking at the source code for that might help you a lot in your own project. here's the code for that

UPDATE

Yes, you do need sdf::init("root.sdf"). I don't think using ~/.gazebo/models will work. First, the ~ is a character expanded by bash, and may not be expanded in that function. Second, you need to consider where readFile is relative too. I believe it is relative to the world file you load from.

edit flag offensive delete link more

Comments

Thanks Peter, I am going to try what you suggest. I need only to update visual elements to show how road changes during a car travel. If I have problem in implementing I will comment to this answer. Thanks again

savaresef gravatar imagesavaresef ( 2016-06-13 04:37:46 -0600 )edit

Good to hear. Please accept this answer once you've decided it was useful

Peter Mitrano gravatar imagePeter Mitrano ( 2016-06-13 15:17:42 -0600 )edit

As you asked I have deleted my second answer but I cannot update my previous answer. I have to create a new question?

savaresef gravatar imagesavaresef ( 2016-06-27 04:18:50 -0600 )edit

There is an edit button on your post so you can update that. You're updating your question, not any answer. If you can't figure it out, post it again as before and I will move it to your question.

Peter Mitrano gravatar imagePeter Mitrano ( 2016-06-27 10:23:29 -0600 )edit

I cannot modify the previous question, probabily because you have already updated it. I am going to post the new one so you can modify the first one.

savaresef gravatar imagesavaresef ( 2016-06-28 07:26:45 -0600 )edit

I've updated my answer

Peter Mitrano gravatar imagePeter Mitrano ( 2016-06-29 15:37:06 -0600 )edit

Thanks actually it works but I expected that if I change the texture image before to reload the model I can see the model with the new image. Do you think it is an implementation error or that in this way I cannot do what I am trying to do?

savaresef gravatar imagesavaresef ( 2016-07-01 02:40:32 -0600 )edit

You should be able to do what you're doing. If you still can't figure out why the image isn't changing, I'd open a new question since you've moved significantly beyond the scope of this question

Peter Mitrano gravatar imagePeter Mitrano ( 2016-07-01 10:45:16 -0600 )edit

I believe what you're doing should and can work. If you still can't figure out why the image isn't changing, I'd open a new question since you've moved significantly beyond the scope of this question

Peter Mitrano gravatar imagePeter Mitrano ( 2016-07-01 10:45:45 -0600 )edit

I will try to solve the issue. If I will not have success I will tell you and you can manage as new question or in other way. Thanks a lot !

savaresef gravatar imagesavaresef ( 2016-07-06 02:33:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-08 07:56:37 -0600

Seen: 2,123 times

Last updated: Jun 28 '16