0
$\begingroup$

I am working on a Webots project using the Python R2021a version, in which four E-puck robots are used that push the box to target locations with the Python class for each robot "Class Environment, class robot followed by main control loop"

Error

While running, it is showing the following error message:

Only one instance of the Robot class should be created
Entering reset method...
Releasing existing supervisor instance...
WARNING: 'mycontroller1' controller exited with status: 1.

Code Snippet

_supervisor_instance = None

def __init__(self, use_supervisor=False):
  self.use_supervisor = use_supervisor
  self.TIME_STEP = 32
  self.receiver = None
  self.webots_supervisor = None
  if use_supervisor:
    if Environment._supervisor_instance is None:
      Environment._supervisor_instance = Supervisor()
    self.webots_supervisor = Environment._supervisor_instance
    self.robot = self.webots_supervisor.getFromDef("agent1")
  else:
    if Environment._robot_instance is None:
      Environment._robot_instance = Robot()
    self.robot = Environment._robot_instance

def reset(self):
  print(f"Supervisor: {self.webots_supervisor}")
  # Release existing Robot/Supervisor instance if it exists
  if self.use_supervisor:
    if Environment._supervisor_instance is not None:
      self.webots_supervisor = None
      self.robot = None
      del Environment._supervisor_instance
  else:
    if Environment._robot_instance is not None:
      self.robot = None
      del Environment._robot_instance
  # Create a new Robot/Supervisor instance
  if self.use_supervisor:
    Environment._supervisor_instance = Supervisor()
    self.webots_supervisor = Environment._supervisor_instance
    self.robot = self.webots_supervisor.getFromDef("agent1")
  else:
    if Environment._robot_instance is None:
      Environment._robot_instance = Robot()
    self.robot = Environment._robot_instance
  try:
    # Ensure that Supervisor instance is used when appropriate
    root = (
        self.webots_supervisor.getRoot()
        if self.use_supervisor
        else self. robot.getRoot()
    )
    self.print_node_names(root)
  except AttributeError as e:
    print(f"Error getting nodes: {e}")
$\endgroup$
2
  • $\begingroup$ Welcome to Robotics Stack Exchange! Can you please confirm if it is Python R2021a? R2021a seems MATLAB version though. $\endgroup$
    – ravi
    Commented Jan 25 at 7:45
  • $\begingroup$ @ravi,its python. $\endgroup$
    – Kazim
    Commented Jan 26 at 2:27

0

Your Answer

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

Browse other questions tagged or ask your own question.