Printing and searching python namespaces from rospy.get_param()
I am catkin-izing, updating, and making revisions to the nxt ROS packages. I have hit an issue that seems basic but I could use some help to get through it. Searches for accessing Python dictionaries haven't helped much.
The code:
host = rospy.get_param("~host", None)
sock = nxt.locator.find_one_brick(host)
b = sock.connect()
config = rospy.get_param("~"+ns)
components = []
for c in config:
rospy.loginfo("Creating %s with name %s on %s",c['type'],c['name'],c['port'])
if c['type'] == 'motor':
components.append(Motor(c, b))
elif c['type'] == 'touch':
components.append(TouchSensor(c, b))
elif c['type'] == 'ultrasonic':
components.append(UltraSonicSensor(c, b))
elif c['type'] == 'color':
components.append(ColorSensor(c, b))
elif c['type'] == 'intensity':
components.append(IntensitySensor(c, b))
elif c['type'] == 'gyro':
components.append(GyroSensor(c, b))
elif c['type'] == 'accelerometer':
components.append(AccelerometerSensor(c, b))
else:
rospy.logerr('Invalid sensor/actuator type %s'%c['type'])
My issue is with the c['text']
in the for loop. When I print config[c]
it prints the value of the key. Printing 'c' alone prints the key. However, when c['text']
is called ROS fires back an error:
TypeError: string indices must be intergers, not str
The namespace (returned into the config variable) can have several sensors set up by a .yaml file.
Thank you for your time.
What does
print(config)
give you?Where is the official source for the nxt packages? The source link on the wiki page is dead
I am not sure how to report the source link being broken issue. There is more on this at sig/NXT. Between the ros wiki and the sig/NXT I figured out indiviuals working with this and selected a repository to grab the variant of ros nxt.
As for your previous comment: If I use rospy.loginfo() to print 'config' to screen it prints the entire dictionary, which in my case only pertains to one sensor or a single dictonary. There are several sensors.