From 5ae2fcbdda79e67531a1584a99eab5a087dbbbc3 Mon Sep 17 00:00:00 2001 From: Innokenty Date: Thu, 27 Jun 2024 14:44:50 +0300 Subject: [PATCH] fixes for MC version update --- tests/vereya/test_image.py | 8 +-- tests/vereya/test_observation.py | 2 +- tests/vereya/test_placement.py | 9 ++- tests/vereya/test_vereya.py | 104 ------------------------------- 4 files changed, 9 insertions(+), 114 deletions(-) delete mode 100644 tests/vereya/test_vereya.py diff --git a/tests/vereya/test_image.py b/tests/vereya/test_image.py index f1a1563..035eeb5 100644 --- a/tests/vereya/test_image.py +++ b/tests/vereya/test_image.py @@ -19,12 +19,12 @@ class TestData(BaseTest): @classmethod def setUpClass(cls, *args, **kwargs): - start = (-126, 73.0) - mc, obs = init_mission(None, start_x=start[0], start_z=start[1], seed='4', forceReset='true') + start = (-108.0, -187.0) + mc, obs = init_mission(None, start_x=start[0], start_z=start[1], seed='5', forceReset='true') cls.mc = mc cls.rob = obs - mc.safeStart() - time.sleep(1) + assert mc.safeStart() + time.sleep(4) @classmethod def tearDownClass(cls, *args, **kwargs): diff --git a/tests/vereya/test_observation.py b/tests/vereya/test_observation.py index 0b71883..e3a82e7 100644 --- a/tests/vereya/test_observation.py +++ b/tests/vereya/test_observation.py @@ -66,7 +66,7 @@ def test_observation_from_ray_cached(self): return self._observation_from_ray(lambda: self.rob.getCachedObserve('getLineOfSights')) def test_observation_from_chat(self): - logger.info("send chat ") + logger.info("send chat") self.mc.sendCommand("chat get wooden_axe") time.sleep(1) logger.info("wait chat") diff --git a/tests/vereya/test_placement.py b/tests/vereya/test_placement.py index ee7e424..01223b6 100644 --- a/tests/vereya/test_placement.py +++ b/tests/vereya/test_placement.py @@ -9,13 +9,12 @@ class TestPlacement(BaseTest): @classmethod def setUpClass(cls, *args, **kwargs): - start = (-125.0, 73) - mc, obs = init_mission(None, start_x=start[0], start_z=start[1], seed=4, - forceReset='true') + start = (-108.0, -187.0) + mc, obs = init_mission(None, start_x=start[0], start_z=start[1], seed='5', forceReset='true') cls.mc = mc cls.rob = obs - mc.safeStart() - time.sleep(1) + assert mc.safeStart() + time.sleep(4) @classmethod def tearDownClass(cls, *args, **kwargs): diff --git a/tests/vereya/test_vereya.py b/tests/vereya/test_vereya.py deleted file mode 100644 index 8c16599..0000000 --- a/tests/vereya/test_vereya.py +++ /dev/null @@ -1,104 +0,0 @@ -import cv2 -import os -import math -import numpy -from collections import deque, defaultdict -import time -import tagilmo.utils.mission_builder as mb -from tagilmo.utils.vereya_wrapper import MCConnector, RobustObserver -from tagilmo.utils import segment_mapping - - -IMAGE = 0 -SEGMENT = 1 -BLOCKS = 2 -WIDTH = 320 -HEIGHT = 240 - - -def start_mission(): - colourmap_producer = mb.ColourMapProducer(width=WIDTH, height=HEIGHT) - video_producer = mb.VideoProducer(width=WIDTH, height=HEIGHT, want_depth=False) - - obs = mb.Observations(bNearby=True, bRecipes=True) - - agent_handlers = mb.AgentHandlers(observations=obs, - colourmap_producer=colourmap_producer, - video_producer=video_producer) - - miss = mb.MissionXML(agentSections=[mb.AgentSection(name='Cristina', - agenthandlers=agent_handlers,)]) - # agenthandlers=agent_handlers,)], namespace='ProjectMalmo.microsoft.com') - - # good point seed='2', x=-90, y=71, z=375 - # good point seed='3', x=6, y=71, z=350 - # good point seed='31' - world = mb.defaultworld( - seed='5', - forceReset="false", - forceReuse="true") - - miss.setWorld(world) - miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager" - # uncomment to disable passage of time: - miss.serverSection.initial_conditions.time_pass = 'false' - miss.serverSection.initial_conditions.time_start = "1000" - mc = MCConnector(miss) - obs1 = RobustObserver(mc) - return mc, obs1 - - - -def get_img(mc): - img_frame = mc.waitNotNoneObserve('getImageFrame') - if img_frame is None: - return None, None - pos = numpy.asarray((img_frame.pitch, img_frame.yaw, img_frame.xPos, img_frame.yPos, img_frame.zPos)) - return pos, img_frame - - -def get_segment(mc): - img_frame = mc.waitNotNoneObserve('getSegmentationFrame') - if img_frame is None: - return None, None - pos = numpy.asarray((img_frame.pitch, img_frame.yaw, img_frame.xPos, img_frame.yPos, img_frame.zPos)) - return pos, img_frame - - -def get_distance(mc): - aPos = mc.getAgentPos() - coords1 = aPos[:3] - coords = [mc.getLineOfSight('x'), - mc.getLineOfSight('y'), - mc.getLineOfSight('z')] - - height = 1.6025 - coords1[1] += height - - dist = numpy.linalg.norm(numpy.asarray(coords) - numpy.asarray(coords1), 2) - return dist - - -def extract(data): - img_data = cv2.resize(data, (WIDTH, HEIGHT)) - return img_data - - -def main(): - from tagilmo import VereyaPython - - mc, obs = start_mission() - mc.safeStart() - mc.sendCommand('recipes') - while True: - cv2.waitKey(300) - obs.clear() - pos1, img = get_img(obs) - if img is not None: - img = extract(img.pixels) - # print(mc.getNearEntities()) - if mc.observe[0] is not None and 'recipes' in mc.observe[0]: - print("got recipes") - mc.sendCommand('recipes off') - cv2.imshow('img', img) -main()