[SOLVED] Add more color to object in "Object Inspector"


#1

Dear All,

For my experiments i need more colors than the 5 default colors available in the object inspector (Black, Gray, Red, Green and Blue). In particular i need to add more colors at the virtual screen object. I searched in the installation folder, in particular in the Model and Gazebo folders but i didn’t find any files that can help me to resolve my problem. Do you know a method to add more colors to default objects in the neurorobotics platform? I think the last thing i can do is to create a new object in Gazebo and import it in the platform but i hope there is a more simple method.

Thank you very much.
Simone


#2

Hi Simone,

The exact feature that you are looking for, already exists, in the form of adding a custom texture in the NRP and displaying it on a screen with a state machine. This works as following:

first you go to your experiment files from the list of experiments. From the list of files on the left there is a folder called resources and in there a folder called textures. Upload your desired colour there in the form of a .png (probably works with jpg as well). You can create your colour in any image editing software i.e. gimp . Then when you start the simulation this image is added as an extra material automatically inside gazebo and you can use it from your gazebo models. For your specific use case, changing the screen colour, this can be done through a state machine like this one

import hbp_nrp_excontrol.nrp_states as states
from smach import StateMachine

FINISHED = 'FINISHED'
ERROR = 'ERROR'
PREEMPTED = 'PREEMPTED'

sm = StateMachine(outcomes=[FINISHED, ERROR, PREEMPTED])

import hbp_nrp_excontrol.nrp_states as states

with sm:
    # Waits until a simulation time of 20s is reached
    StateMachine.add(
     "timeline_condition",
     states.WaitToClockState(20),
     transitions = {"valid": "timeline_condition",
                    "invalid": "set_left_screen_red",
                    "preempted": PREEMPTED}
    )
    StateMachine.add(
      "set_left_screen_red",
      states.SetMaterialColorServiceState("left_vr_screen",
                                          "body",
                                          "screen_glass",
                                          "yourFilename.png"),
      transitions = {"succeeded": "delay_set_left_screen_blue",
                     "aborted": FINISHED,
                     "preempted": "set_left_screen_green"}
    )
    StateMachine.add(
      "set_left_screen_blue",
      states.SetMaterialColorServiceState("left_vr_screen",
                                          "body",
                                          "screen_glass",
                                          "yourFilename.png"),
      transitions = {"succeeded": "delay_set_left_screen_red",
                     "aborted": FINISHED,
                     "preempted": "set_left_screen_green"}
    )
    StateMachine.add(
      "delay_set_left_screen_blue",
      states.ClockDelayState(5),
      transitions = {"invalid": "set_left_screen_blue",
                     "valid": "delay_set_left_screen_blue",
                     "preempted": "set_left_screen_green"}
    )
    StateMachine.add(
      "delay_set_left_screen_red",
      states.ClockDelayState(5),
      transitions = {"invalid": "set_left_screen_red",
                     "valid": "delay_set_left_screen_red",
                     "preempted": "set_left_screen_green"}
    )
    StateMachine.add(
      "set_left_screen_green",
      states.SetMaterialColorServiceState("left_vr_screen",
                                          "body",
                                          "screen_glass",
                                          "yourFilename.png"),
      transitions = {"succeeded": FINISHED,
                     "aborted": FINISHED,
                     "preempted": PREEMPTED}
    )

Note that in the state machine there is an argument called “yourFilename.png” which should be the same as the name of the png that you uploaded in resources/textures .I hope this is what you are looking for. Let me know if it worked.

Best regards,
Manos


#3

Hi Manos,

I followed all the steps that you suggested me and the state machine script works fine.
Thank you for the help.

Best regards,
Simone