diff --git a/navipy/moving/agent.py b/navipy/moving/agent.py index 2d7f11c8d863afafb2f6ce43b0127c42efdbf4d8..7b30f1721f9bc6a4ebddcbb43949704884ccb7e8 100644 --- a/navipy/moving/agent.py +++ b/navipy/moving/agent.py @@ -49,10 +49,9 @@ class DefaultBrain(): class AbstractAgent(): - def __init__(self): + def __init__(self, convention='rxyz'): self._brain = DefaultBrain() self._alter_posorientvel = defaultcallback - convention = 'rxyz' tuples = [('location', 'x'), ('location', 'y'), ('location', 'z'), (convention, 'alpha_0'), (convention, 'alpha_1'), (convention, 'alpha_2')] @@ -150,8 +149,10 @@ CyberBeeAgent is a close loop agent and need to be run within blender \ """ - def __init__(self, brain): - AbstractAgent.__init__(self) + def __init__(self, brain, convention): + if convention is None: + raise Exception("a convention must be specified") + AbstractAgent.__init__(self, convention) AbstractAgent._alter_posorientvel = \ lambda motion_vec: navimomath.next_pos(motion_vec, move_mode='free_run') @@ -175,12 +176,14 @@ GridAgent is a close loop agent here its position is snap to a grid. """ - def __init__(self, brain, + def __init__(self, brain, convention, posorients_queue=None, results_queue=None): + if convention is None: + raise Exception("convention must be set") if (posorients_queue is not None) and (results_queue is not None): multiprocessing.Process.__init__(self) - AbstractAgent.__init__(self) + AbstractAgent.__init__(self, convention) self._alter_posorientvel = self.snap_to_grid self.brain = brain self._posorients_queue = posorients_queue diff --git a/navipy/moving/maths.py b/navipy/moving/maths.py index faf87530763c04410ee6c360c5b4cbc6628a1cac..55389c762ea1d37fa746d49f06d5f03437e77f9e 100644 --- a/navipy/moving/maths.py +++ b/navipy/moving/maths.py @@ -53,7 +53,7 @@ def next_pos(motion_vec, move_mode, move_param=None): phi = np.arctan2(speed['location']['dy'], speed['location']['dx']) radius = np.sqrt(np.sum(speed**2)) if np.isclose(radius, 0): - scaling = 0 + # scaling = 0 speed = 0 * speed else: tuples = [('location', 'dx'), ('location', 'dy'), @@ -80,10 +80,11 @@ def next_pos(motion_vec, move_mode, move_param=None): else: deltas['location']['dy'] = 0 - scaling = 1 + # scaling = 1 speed = move_param['grid_spacing'] * deltas elif move_mode is 'free_run': - scaling = 1 # <=> dt = 1, user need to scale speed in dt units + pass + # scaling = 1 # <=> dt = 1, user need to scale speed in dt units else: raise ValueError('grid_mode is not supported') toreturn = motion_vec diff --git a/navipy/moving/test_agent.py b/navipy/moving/test_agent.py index b951ce68a0de0483d9d46c26f2a49af52d0eb8ab..3319808148c5b7baca40fbf7fae78345c6810a05 100644 --- a/navipy/moving/test_agent.py +++ b/navipy/moving/test_agent.py @@ -87,7 +87,7 @@ class TestNavipyMovingAgent(unittest.TestCase): # GridAgent # def test_move_gridagent(self): - agent = naviagent.GridAgent(self.brain) + agent = naviagent.GridAgent(self.brain, 'rxyz') initposorient = None with warnings.catch_warnings(record=True): initposorient = self.brain.posorients.loc[13, :] @@ -107,16 +107,16 @@ class TestNavipyMovingAgent(unittest.TestCase): pd.Series(data=1, index=index)}} agent.mode_of_motion = mode_move - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): agent.move() obtained = agent.posorient self.assertTrue(np.allclose( obtained, initposorient.loc[obtained.index])) def test_fly_gridagent(self): - agent = naviagent.GridAgent(self.brain) + agent = naviagent.GridAgent(self.brain, 'rxyz') initposorient = None - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): initposorient = self.brain.posorients.loc[13, :] initposovel = pd.Series(data=0, index=self.__posorient_vel_col) @@ -145,7 +145,7 @@ class TestNavipyMovingAgent(unittest.TestCase): def test_init_graphagent(self): agent = None - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): agent = naviagent.GraphAgent(self.brain) if version < 2: graph_nodes = list(agent.graph.nodes()) @@ -157,7 +157,7 @@ class TestNavipyMovingAgent(unittest.TestCase): def test_graph_setter(self): agent = None - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): agent = naviagent.GraphAgent(self.brain) if version < 2: graph_nodes = list(agent.graph.nodes()) @@ -187,7 +187,7 @@ class TestNavipyMovingAgent(unittest.TestCase): """ # Test all node to first agent = None - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): agent = naviagent.GraphAgent(self.brain) if version < 2: @@ -254,7 +254,7 @@ class TestNavipyMovingAgent(unittest.TestCase): 3. Local minima """ agent = None - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True): agent = naviagent.GraphAgent(self.brain) # Local maxima if version < 2: diff --git a/navipy/moving/test_maths.py b/navipy/moving/test_maths.py index 44219dcfa33cbba49ea68a57ac413695704710d6..75fbc8eef6917163133f4e0045fc4fd44a689f96 100644 --- a/navipy/moving/test_maths.py +++ b/navipy/moving/test_maths.py @@ -116,10 +116,10 @@ class TestNavipyMovingMaths(unittest.TestCase): expected_dict[337] = 6 expected_dict[338] = 7 # equivalent to -22 tuples2 = [('location', 'x'), ('location', 'y'), - ('location', 'z'), ('location', 'dx'), - ('location', 'dy'), ('location', 'dz')] + ('location', 'z'), ('location', 'dx'), + ('location', 'dy'), ('location', 'dz')] index2 = pd.MultiIndex.from_tuples(tuples2, - names=['position', 'orientation']) + names=['position', 'orientation']) for angle, exp_i in expected_dict.items(): alpha = np.deg2rad(angle)