ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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":
   motor_msg.data=int(70)
   pub_motor0.publish(motor_msg)
  if w == "backwall":
   motor_msg.data = int(71)
   pub_motor0.publish(motor_msg)
  if w == "nowall":
   motor_msg.data = int(72)
   pub_motor0.publish(motor_msg)
if __name__ == '__main__':
rospy.init_node('auto_control', anonymous=True)
rospy.Subscriber("/waller", String, callback)
rospy.spin()

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

https://answers.ros.org/question/2781...

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
1

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 data.data not data.String() since it as the error shows it doesn't have a member named string.

edit flag offensive delete link more

Comments

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

Question Tools

1 follower

Stats

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

Seen: 478 times

Last updated: Jan 08 '18