Closed kadirou31 closed 1 year ago
Hello, It works well on my side.
Please check:
e-puck
Hi, I tried it on Windows and Linux, supervisor is enabled on the robot. Could you please help to resolve this issue.
Can you post your world file (.wbt
)?
the code from tutorial :
from controller import Supervisor
TIME_STEP = 32
robot = Supervisor() # create Supervisor instance
# [CODE PLACEHOLDER 1]
bb8_node = robot.getFromDef('BB-8')
translation_field = bb8_node.getField('translation')
root_node = robot.getRoot()
children_field = root_node.getField('children')
children_field.importMFNodeFromString(-1, 'DEF BALL Ball { translation 0 1 1 }')
ball_node = robot.getFromDef('BALL')
color_field = ball_node.getField('color')
i = 0
while robot.step(TIME_STEP) != -1:
# [CODE PLACEHOLDER 2]
if (i == 0):
new_value = [2.5, 0, 0]
translation_field.setSFVec3f(new_value)
if i == 10:
bb8_node.remove()
if i == 20:
children_field.importMFNodeFromString(-1, 'Nao { }')
position = ball_node.getPosition()
print('Ball position: %f %f %f\n' %(position[0], position[1], position[2]))
if position[2] < 0.2:
red_color = [1, 0, 0]
color_field.setSFColor(red_color)
i += 1
There is no DEF in your world so it is normal that the getFromDef
function returns null
how to add DEF to the world
thank you very much, the problem is solved, it was my fault I foroet to add a DEF, again thanks for your quick answers.
Hi, i'm using Webots 2023a under Ubuntu 22 LST, I'm trying to use Supervisor based on the tutorial code, I'm getting this output:
i noticed that robot_node is None !! the used code is: