Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: only one Robot instance can be created per controller process. #6496

Closed
kazim27 opened this issue Feb 9, 2024 · 0 comments
Closed

Comments

@kazim27
Copy link

kazim27 commented Feb 9, 2024

Describe the Bug
I am working on a Webots project in which four E-puck robots are used that push box to target locations with separate controller ,each controller consists of "Class Environment, class robot followed by main control loop"

_robot_instance = None
_supervisor_instance = None

def __init__(self, use_supervisor=False):
    self.use_supervisor = use_supervisor
    self.robot = None
    self.webots_supervisor = None
    self.TIME_STEP = 64

    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
        self.webots_supervisor = None

    self.time_step = self.robot.getBasicTimeStep() if not use_supervisor else None
def reset(self):
    print(f"Supervisor: {self.webots_supervisor}")
    # Release existing Robot/Supervisor instance if it exists
    if self.use_supervisor and Environment._supervisor_instance is not None:
        del Environment._supervisor_instance
    elif not self.use_supervisor and Environment._robot_instance is not 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:
        Environment._robot_instance = Robot()
        self.robot = Environment._robot_instance
        self.webots_supervisor = None
    try:
        # Corrected the Supervisor instance
        root = self.webots_supervisor.getRoot()
        self.print_node_names(root)

when I run it I end up getting an error like this: "Only one instance of the Robot class should be created per controller process"
I have been trying for days to solve the issue, but unfortunately, I am unable to figure it out. I would be grateful if you could provide me with some suggestions to help me solve the problem.

@cyberbotics cyberbotics locked and limited conversation to collaborators Feb 9, 2024
@omichel omichel converted this issue into discussion #6497 Feb 9, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Development

No branches or pull requests

1 participant