Ask Your Question
1

How to change color of turtlesim background using python code

asked 2018-02-21 16:48:09 -0600

bharadwaj26 gravatar image

updated 2018-02-21 17:11:14 -0600

Hi, guys, I'm trying to publish data to turtlesim color_sensor that is trying to display different colors my problem is it publishing data but it's not working. I did call $ rosservice call /clear after running program but it didn't work

 #!/usr/bin/env python

    import rospy
    from turtlesim.msg import Color

    rospy.init_node('color_sensor')
    pub = rospy.Publisher('/turtle1/color_sensor',Color,queue_size=4)
    rate = rospy.Rate(50)
    change=Color()
    change.r=255
    change.g=255
    change.b=255

    while not rospy.is_shutdown():
       pub.publish(change)
       print  change
edit retag flag offensive close merge delete

Comments

but it didn't work

what does this mean?

jayess gravatar imagejayess ( 2018-02-21 19:25:30 -0600 )edit

it's not publishing those RGB values to color_sensor, even though I am publishing it.i,e Background color is not changing to White(255,255,255)

bharadwaj26 gravatar imagebharadwaj26 ( 2018-02-21 19:35:01 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-02-22 01:21:54 -0600

hamid gravatar image

updated 2018-02-22 01:22:19 -0600

for changing turtlesim Background color you must set param not publish via topic you do something like this in your code:

rospy.set_param('/background_b',100)
rospy.set_param('/background_r',100)
rospy.set_param('/background_g',100)

after that you must call

rosservice call /clear

in terminal or in your code

edit flag offensive delete link more

Comments

can't we publish the rgb values to the color_sensor and change color ,like we publish linear and angular data to cmd_vel in turtlesim to move the turtle

bharadwaj26 gravatar imagebharadwaj26 ( 2018-02-27 12:56:22 -0600 )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

1 follower

Stats

Asked: 2018-02-21 16:48:09 -0600

Seen: 526 times

Last updated: Feb 22 '18