I am writing a method (Java) that will reset the position of e-puck in Webots. I have been following tutorial on Supervisor approach. I have two controllers in my project:

  • SupervisorController extends Supervisor - responsible for genetic algorithm and resetting e-puck's position
  • EpuckController extends Robot - drives the robot

Robots are communicating via Emitter and Receiver, and everything works fine but the position reset. This is what I'm doing in SupervisorController:

412 Node epuck = getFromDef("epuck");    
413 Field fldTranslation = epuck.getField("translation");

And as a result I get this exception:

[SupervisorController] Exception in thread "main" java.lang.NullPointerException
[SupervisorController]  at SupervisorController.initialise(SupervisorController.java:413)
[SupervisorController]  at SupervisorController.main(SupervisorController.java:497)

epuck variable is null. I tried calling different methods on epuck, and they all resulted in NullPointerException. The name of e-puck matches the world file.

DEF EPUCK DifferentialWheels {
  translation 0.134826 -0.000327529 0.107963
  rotation 0.0244439 0.999246 -0.0301538 1.95838
  children [
  name "epuck"
  controller "EpuckController"
  axleLength 0.052
  wheelRadius 0.0205
  maxSpeed 6.28
  speedUnit 0.00628

I would appreciate any advice on how to get a handle to the robot or where to look for issues in simulation/code.


1 Answer 1


The Solid nodes (including Robot and Supervisor nodes) have a DEF name, like any other node and it is usually written in upper-case. These nodes also have a field "name". Both may be used by a Supervisor, it depends on which function is called.

In my case, the function getFromDef() expects a DEF name as argument, and not the name from the "name" field. The DEF name of my e-puck is "EPUCK" - hence modifying controller to:

Node epuck = getFromDef("EPUCK");

solved the problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.