-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Error
The example "Sample object manipulation code" from the Robobosimpy subsection of the wiki throws this error:
Traceback (most recent call last):
File "robobosim.py", line 14, in <module>
object_one = objects[0]
~~~~~~~^^^
TypeError: 'dict_keys' object is not subscriptablesim.getObjects() now returns a dict_keys, so the code in the wiki no longer works.
Solution
Convert objects to a list before indexing:
# Import the library
from robobosim.RoboboSim import RoboboSim
# Connect to the RoboboSim
IP = "localhost"
sim = RoboboSim(IP)
sim.connect()
sim.wait(0.5)
# Get the interactable objects of the scene
objects = sim.getObjects()
if objects is not None and len(objects) > 0:
# Get the first object of the list, provided that there is at least one
object_one = list(objects)[0]
print(object_one)
# Get the object's absolute position
loc = sim.getObjectLocation(object_one)
print(loc["position"])
sim.wait(0.5)
# Move the selected object +50 mm along the X axis
pos = loc['position']
pos["x"] += 50
sim.setObjectLocation(object_one, loc['position'])
sim.wait(0.5)
sim.disconnect()Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels