File: multiple_human.py

package info (click to toggle)
morse-simulator 1.4-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 187,116 kB
  • sloc: ansic: 108,311; python: 25,694; cpp: 786; makefile: 126; xml: 34; sh: 7
file content (72 lines) | stat: -rwxr-xr-x 2,514 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env python
"""
This script tests the human model with a pose sensor.
"""

import sys
from morse.testing.testing import MorseTestCase
from pymorse import Morse

# Include this import to be able to use your test file as a regular 
# builder script, ie, usable with: 'morse [run|edit] <your test>.py
try:
    from morse.builder import *
except ImportError:
    pass

class MultipleHumanTest(MorseTestCase):
    def setUpEnv(self):
        """ A very simple test scenario, with 3 static human avatars.
        """
        human1 = Human()
        human1.name = 'roger'
        human1.append(Pose("pose"))
        human1.translate(x = 5.0)
        human1.add_default_interface('socket')

        human2 = Human()
        human2.name = 'raphael'
        human2.append(Pose("pose"))
        human2.translate(x = -5.0)
        human2.add_default_interface('socket')

        human3 = Human()
        human3.name = 'novak'
        human3.append(Pose("pose"))
        keyboard = Keyboard()
        keyboard.properties(Speed=1.15)
        human3.append(keyboard)
        human3.add_default_interface('socket')

        env = Environment('empty', fastmode = True)

    def test_pose(self):
        with Morse() as morse:
            p1 = morse.roger.pose.get()
            p2 = morse.raphael.pose.get()
            p3 = morse.novak.pose.get()

            self.assertAlmostEquals(p1['x'], 5.0, delta=0.01)
            self.assertAlmostEquals(p2['x'], -5.0, delta=0.01)
            self.assertAlmostEquals(p3['x'], 0.0, delta=0.01)
            self.assertAlmostEquals(p1['y'], 0.0, delta=0.01)
            self.assertAlmostEquals(p2['y'], 0.0, delta=0.01)
            self.assertAlmostEquals(p3['y'], 0.0, delta=0.01)

    def test_skeletons(self):
        with Morse() as morse:
            s1 = morse.roger.skeleton.joint_states
            s2 = morse.raphael.skeleton.joint_states
            s3 = morse.novak.skeleton.joint_states

            # Check that the pose is the same for all the models (ie, same joints value)
            for j1, j2 in zip(s1.get_state().result().values(), s2.get_state().result().values()):
                self.assertAlmostEquals(j1, j2, delta=0.001)

            for j1, j3 in zip(s1.get_state().result().values(), s3.get_state().result().values()):
                self.assertAlmostEquals(j1, j3, delta=0.001)

########################## Run these tests ##########################
if __name__ == "__main__":
    from morse.testing.testing import main
    main(MultipleHumanTest)