예제 #1
0
    async def analyze_sdf(self, sdf, max_attempts=5):
        """
        Coroutine that returns with a (collisions, bounding box) tuple,
        assuming analysis succeeds.

        :param max_attempts:
        :param sdf:
        :type sdf: SDF
        :return:
        """
        msg = None
        rh = self.request_handler
        for _ in range(max_attempts):
            response = await rh.do_gazebo_request("analyze_body", str(sdf))
            if response.response == "success":
                msg = BodyAnalysisResponse()
                msg.ParseFromString(response.serialized_data)
                break

        if not msg:
            logger.error("analyze_sdf returned not valid message")
            return None

        if msg.HasField("boundingBox"):
            bbox = msg.boundingBox
        else:
            bbox = None

        internal_collisions = len(msg.contact)
        return internal_collisions, bbox
예제 #2
0
 async def _restart_simulator(self, i):
     # restart simulator
     logger.error("Restarting simulator")
     self._connections[i].disconnect()
     await (await self._supervisors[i].relaunch(5))
     await asyncio.sleep(5)
     self._connections[i] = await World.create(self._settings,
                                               world_address=("127.0.0.1",
                                                              11345 + i))
예제 #3
0
    async def _worker_evaluate_robot(self, connection, robot, future, conf):
        await asyncio.sleep(0.01)
        start = time.time()
        try:
            timeout = self.EVALUATION_TIMEOUT  # seconds
            result = await asyncio.wait_for(self._evaluate_robot(
                connection, robot, conf),
                                            timeout=timeout)
        except asyncio.TimeoutError:
            # WAITED TO MUCH, RESTART SIMULATOR
            elapsed = time.time() - start
            logger.error(f"Simulator restarted after {elapsed}")
            return False
        except Exception:
            logger.exception(f"Exception running robot {robot.phenotype}")
            return False

        elapsed = time.time() - start
        logger.info(f"time taken to do a simulation {elapsed}")

        robot.failed_eval_attempt_count = 0
        future.set_result(result)
        return True
예제 #4
0
 async def _restart_simulator(self, i):
     # restart simulator
     address = '127.0.0.1'
     port = self._port_start + i
     logger.error("Restarting simulator")
     logger.error("Restarting simulator... disconnecting")
     try:
         await asyncio.wait_for(self._connections[i].disconnect(), 10)
     except asyncio.TimeoutError:
         pass
     logger.error("Restarting simulator... restarting")
     await self._supervisors[i].relaunch(10, address=address, port=port)
     await asyncio.sleep(10)
     logger.debug("Restarting simulator done... connecting")
     self._connections[i] = await self._connect_to_simulator(
         self._settings, address, port)
     logger.debug("Restarting simulator done... connection done")