[SOLVED] Add new texture for spawned boxes


#1

Dear all,

I would like to add texture to boxes spawned in the NRP state machine.
Somehow I can not make this work with the new
NRP version on Ubuntu 18.04. I created a script
repeated.material which is calling the texture
checkerboard.png. Here the script:

material RepeatedTexture
{
technique
{
pass
{
texture_unit
{
// Relative to the location of the material script
texture …/textures/checkerboard.png
// Repeat the texture over the surface (4 per face)
scale 0.5 0.5
}
}
}
}

In the state machine I define the box like this:

	# Creates box object at random position
	smach.StateMachine.add('set_object_position', 				states.SpawnBox(model_name=model_name_function,size=(1,1,2),position=position_value_function,can_collide= False, gravity_factor= False,color='RepeatedTexture'),
	transitions = {'succeeded': 'check_runs', 'aborted': 'ACTION_ERROR', 'preempted': 'ACTION_PREEMPTED'})

Where do I have to add the script and texture and do I have to recompile anything to make this work?
Thanks a lot and best regards,
Thorben


#2

Dear Thorben,

For custom textures, there is an easy mechanism described by Manos in this post:


The example changes the texture on a virtual screen, but it should work on boxes as well. Give it a try.

Axel


#4

Dear Axel,

Thank you for the fast reply.
I was able to implement the state machine function
but I do not know which “part_name” and “surface_name”
I have to set when referring to a box spawned with the state
machine function Spawn.box(). Also when I try to inspect the object
I only receive the obejct_name.

Best regards,
Thorben


#5

Dear Thorben,

I understand the issue indeed… Can you send your state machine code here, so that the dev team can have a look at it? There might be a hack to get surface names, or if not we have a feature missing in the NRP that I would pass on to the dev team.

Best regards
Axel


#6

Dear Axel,

I uploaded the state machine as file state_machine.txt.
The state machine picks a random number of 0 to 500 boxes
and places them randomly in a 50x50 meters environment.
After placing a box the state machine tries to change its colour.
When all boxes are placed the state machine waits for a collision
or the time to be over. When one of these events occurs the simulation
stops and all data will be saved at a predefined location.
Thanks a lot for your help.

Best regards,
Thorben

state_machine.txt (7.3 KB)


#7

Dear Thorben,

I passed on to the developers and they said this is what you should try.
There is a ros service that gives back the names of the visuals. From a terminal:

rosservice call /gazebo/export_world_sdf

then find the section that has the box, in my case I inserted one which had the name box_0.
Then the hierarchy is model_name::link_name::visual_name
Then the state machine code looks like:

states.SetMaterialColorServiceState("box_0",
                                      "link",
                                      "visual",
                                      "yourFilename.png")

#8

Dear Axel,

This seems like a nice and clean solution.
I found a faster “hack” for myself by changing
the path in “NRP/ExperimentControl/hbp_nrp_excontrol/hbp_nrp_excontrol/nrp_states/_ModelServiceState.py” in line 117 to the location of my .material script.

Thank you very much for your help and best regards,
Thorben Schoepe