Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

""" 

Every agent comes with a brain processing the about of \ 

senses or sensors for biological or technical agent, respectively. 

 

The senses of agents in navipy are limited 

to: 

 

* 4d vision (brighness + depth) 

 

The 4d vision sense is controlled by rendering module, either an \ 

online rendering or loaded from a database containing pre-rendered images. 

 

For example to use pre-rendered images from a database: 

 

.. literalinclude:: example/processing/apcv.py 

:lines: 10-11 

 

Then the brain can be updated at a new position orientation: 

 

.. literalinclude:: example/processing/apcv.py 

:lines: 15 

 

Building your own brain 

----------------------- 

 

The Brain class is an abstract Brain, such that it can not control an agent. \ 

To control, an agent, the Brain should have a function called velocity. 

 

For example, an stationary agent should always return a null velocity. 

 

.. literalinclude:: example/brain/static_brain.py 

:lines: 3,9-17 

 

An agent using an average skyline homing vector, could be build as follow 

 

.. literalinclude:: example/brain/asv_brain.py 

:lines: 4-5,11-36 

 

""" 

from navipy.database import DataBase 

import logging 

 

 

class Bunch: 

def __init__(self, **kwds): 

self.__dict__.update(kwds) 

 

 

class Brain(): 

def __init__(self, 

renderer=None): 

self.vision = Bunch(scene=None, 

viewing_directions=None, 

channels=None) 

self.renderer = renderer 

if self.renderer is not None: 

self.vision.scene = None 

self.vision.viewing_directions = renderer.viewing_directions 

self.vision.channels = renderer.channels 

 

def velocity(self): 

raise NotImplementedError("Subclasses should implement this") 

 

def update(self, posorient): 

self.posorient = posorient 

if self.renderer is not None: 

self.vision.scene = self.renderer.scene(posorient) 

 

@property 

def posorients(self): 

if isinstance(self.renderer, DataBase): 

return self.renderer.posorients 

else: 

raise NotImplementedError("Subclasses should implement this, " + 

"when renderer is not DataBaseLoad") 

 

 

def logger(level=logging.INFO, filename='navipy.log'): 

logger = logging.getLogger('navipy') 

logger.setLevel(level) 

# create a file handler 

if filename is not None: 

handler = logging.FileHandler(filename) 

handler.setLevel(level) 

# create a logging format 

formatter = logging.Formatter( 

'%(asctime)s - %(name)s - %(levelname)s - %(message)s') 

handler.setFormatter(formatter) 

# add the handlers to the logger 

logger.addHandler(handler) 

 

 

def unittestlogger(): 

logger(level=logging.CRITICAL, filename=None)