ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Reading a string from a node

asked 2018-01-08 09:03:15 -0500

koboy gravatar image

updated 2018-01-08 09:33:54 -0500

def callback(data):

  w = data.String()

  brush_msg = UInt16()
  motor_msg = UInt16()
  if w=="frontwall":
  if w == "backwall": = int(71)
  if w == "nowall": = int(72)
if __name__ == '__main__':
rospy.init_node('auto_control', anonymous=True)
rospy.Subscriber("/waller", String, callback)

When I run this script this message appears on console: w = data.String() AttributeError: 'String' object has no attribute 'String'

PeteBlacker solved the issue I had with regards the constant publishing and my missunderstanding of the issue. I'm trying to update the same script to publish the message in function of some string data published by an arduino by rosserial in the node "waller".

edit: Oh shit and I tried data.waller and waller.String and such... Same msg.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-01-08 09:34:48 -0500

Hello again koboy, hopefully this one will be simple. If you look at the definition of the ros String message type here. It contains a single value with the type string and the identifier data.

So if I've got this right the value you want to assign to w is not data.String() since it as the error shows it doesn't have a member named string.

edit flag offensive delete link more


And... You are right again. I checked that page and completely missed the point before. I checked the documentation on the joy.msg that I was using for the joystick control and I think I got the point now. You are being really helpful, thanks a lot :)

koboy gravatar image koboy  ( 2018-01-08 09:42:31 -0500 )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


Asked: 2018-01-08 09:03:15 -0500

Seen: 401 times

Last updated: Jan 08 '18