-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use MaterialColor Msg #615
Comments
Oh nvm, I figured it out, basically the rostopic is not to display current material color, but used to be written to update new color. Basically the procedure like following:
|
@yanmiao2 If doing it from a basic node it can be as easy as running: gz sim default.sdf Now add a box to the world from the shape menu: Start a bridge: ros2 run ros_gz_bridge parameter_bridge /world/default/material_color@ros_gz_interfaces/msg/[email protected] Run a node to change the material color (in python for easiest readability): import rclpy
import numpy as np
from rclpy.node import Node
from ros_gz_interfaces.msg import MaterialColor
class MaterialTester(Node):
def __init__(self):
super().__init__('material_tester_node')
self.MaterialColorTopic = '/world/default/material_color'
self.MaterialColorPub = self.create_publisher(MaterialColor,'{:s}'.format(self.MaterialColorTopic), 1)
timer_period = 0.02
self.i=0
self.timer = self.create_timer(timer_period, self.timerCallback)
def timerCallback(self):
if self.i < 49:
self.i+=1
elif self.i >= 49:
self.i=0
msgM=MaterialColor()
msgM.entity_match=1
msgM.entity.name="box_visual"
msgM.diffuse.b = 1.0
msgM.diffuse.g = .1-.1*np.sin(2*np.pi*self.i/49+np.pi/2)
msgM.diffuse.r = .1-.1*np.sin(2*np.pi*self.i/49+np.pi/2)
msgM.diffuse.a = 1.0*np.sin(2*np.pi*self.i/49)
msgM.emissive=msgM.specular=msgM.ambient=msgM.diffuse
self.MaterialColorPub.publish(msgM)
return
if __name__ == '__main__':
rclpy.init()
MT = MaterialTester()
rclpy.spin(MT)
MT.destroy_node()
rclpy.shutdown() Watch colors change: |
Hi, I'm very new to gazebo and ros. I'd like to change material color while launching the simulator, potential using ros? or at least gazebo command line.
I see that it's possible by #486 , but i did not see any tutorials on how to make it happen. I can build the bridge using
ros2 run ros_gz_bridge parameter_bridge /world/material_color/material_color@ros_gz_interfaces/msg/[email protected]
, but there's nothing being published to that topic, did I miss a plug-in? Can someone walk me through what i should do? ThanksI'm using a very simple sdf from https://github.com/gazebosim/gz-sim/pull/2286/files#diff-e3c9cb7abd311a035b602cba1847f3d96c1d7e9cfe0e58c863a8355551700738
The text was updated successfully, but these errors were encountered: