cyberbotics/webots

`Device`s with duplicate names cause unexpected behavior

brettle opened this issue · 0 comments

Describe the Bug
If two Device nodes have the same name, a controller will silently not distinguish between them.

Steps to Reproduce

  1. Create a world with 2 HingeJoints, each with a RotationalMotor and a Brake. Give the RotationalMotor's different names but leave the names of the Brakes at the default "brake". Attach a flywheel solid (with physics) to each HingeJoint so that the motors have something to drive.
  2. In controller code, get each of the Motors and then use motor.getBrake() to get each of the Brakes. For each brake, call brake.setDampingConstant(someValue).
  3. Start the world and use the UI to start each flywheel spinning. One will slow to a stop but the other will spin forever because the damping constant only got set on one of the Brake devices.

Expected behavior
Ideally, both flywheels slow to a stop.

At a minimum, a warning or error message should be displayed indicating that multiple devices with the same name are not supported.

System
Any.

Additional context

I suspect the core of the problem is here:

Device::Device(const string &deviceName) : name(deviceName) {
tag = wb_robot_get_device(name.c_str());
}

Since wb_robot_get_device() returns the tag of the first device with a given name, a Device's tag is fully determined by it's name.