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

from director import lcmUtils 

from director import transformUtils 

import PythonQt 

import bot_core as lcmbotcore 

 

import subprocess 

import select 

import weakref 

 

 

_icpSub = None 

_icpCallbacks = [] 

_icpTransforms = [] 

_initialTransform = None 

_registrarProc = None 

 

 

def addICPCallback(func): 

    #_icpCallbacks.append(weakref.ref(func)) 

    _icpCallbacks.append(func) 

 

 

def storeInitialTransform(): 

    global _initialTransform 

    _initialTransform = _icpTransforms[-1] if len(_icpTransforms) else None 

    if _initialTransform: 

        print 'stored initial icp transform' 

 

 

def getInitialTransform(): 

    return _initialTransform 

 

 

def onICPCorrection(m): 

 

    t = transformUtils.transformFromPose(m.trans, m.quat) 

 

    _icpTransforms.append(t) 

    print 'appending icp transform %d' % len(_icpTransforms) 

 

    if len(_icpTransforms) == 1: 

        storeInitialTransform() 

 

    for func in _icpCallbacks: 

        func(t) 

 

 

def initICPCallback(): 

 

    global _icpSub 

    _icpSub = lcmUtils.addSubscriber('MAP_LOCAL_CORRECTION', lcmbotcore.rigid_transform_t, onICPCorrection) 

 

 

def _readAllSoFar(proc, retVal=''): 

    while proc.poll() is None and (select.select([proc.stdout],[],[],0)[0] != []): 

        retVal += proc.stdout.read(1) 

    return retVal 

 

 

def getRegistarOutput(): 

 

    global _registrarProc 

    output = _readAllSoFar(_registrarProc) 

    return output 

 

 

def startMapsRegistrar(): 

 

    global _registrarProc 

    _registrarProc = subprocess.Popen(['maps-registrar'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 

    return _registrarProc