├── .gitignore ├── README.md ├── apollo-soyuz.mtl ├── apollo-soyuz.obj └── soyuz.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.ini 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apollo Soyuz Demo 2 | 3 | Demonstration of the IMU sensor on the Sense HAT by [Serge Schneider](https://github.com/XECDesign). 4 | 5 | Assumes the [Sense HAT Python library](https://github.com/RPi-Distro/python-sense-hat) has been installed. 6 | 7 | ## Requirements 8 | 9 | - Python [pi3d](https://pypi.python.org/pypi/pi3d) module 10 | 11 | Python 3: 12 | 13 | ```bash 14 | sudo apt-get install python3-pip 15 | sudo pip3 install pi3d 16 | ``` 17 | 18 | Python 2: 19 | 20 | ```bash 21 | sudo apt-get install python-pip 22 | sudo pip install pi3d 23 | ``` 24 | 25 | ## Usage 26 | 27 | ```bash 28 | git clone git://github.com/astro-pi/apollo-soyuz 29 | cd apollo-soyuz 30 | sudo python3 soyuz.py 31 | ``` 32 | 33 | Pi 1 users will have to wait 3 to 4 minutes for this to load. For Pi 2/3 users it's about 30 seconds. 34 | 35 | Pick up the Astro Pi and start moving it around when you see the spacecraft appear on screen. 36 | 37 | This is a good demonstration of pitch, roll and yaw. 38 | 39 | ## Keys 40 | 41 | - `a` toggle accelerometer on/off 42 | - `g` toggle gyroscope on/off 43 | - `m` toggle magnetometer compass on/off 44 | - `+` increase yaw offset 45 | - `-` decrease yaw offset 46 | - `Esc` quit 47 | -------------------------------------------------------------------------------- /apollo-soyuz.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'Rosetta.blend' 2 | # Material Count: 11 3 | 4 | newmtl anisotropic1SG 5 | Ns 96.078431 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ni 1.000000 10 | d 1.000000 11 | illum 2 12 | 13 | newmtl apollohorns_bli1 14 | Ns 96.078431 15 | Ka 0.000000 0.000000 0.000000 16 | Kd 0.213333 0.213333 0.213333 17 | Ks 0.500000 0.500000 0.500000 18 | Ni 1.000000 19 | d 1.000000 20 | illum 2 21 | 22 | newmtl apollohorns_blin 23 | Ns 96.078431 24 | Ka 0.000000 0.000000 0.000000 25 | Kd 0.614902 0.423529 0.047059 26 | Ks 0.500000 0.500000 0.500000 27 | Ni 1.000000 28 | d 1.000000 29 | illum 2 30 | 31 | newmtl blinn13SG 32 | Ns 96.078431 33 | Ka 0.000000 0.000000 0.000000 34 | Kd 0.389020 0.398431 0.294902 35 | Ks 0.500000 0.500000 0.500000 36 | Ni 1.000000 37 | d 1.000000 38 | illum 2 39 | 40 | newmtl blinn2SG 41 | Ns 96.078431 42 | Ka 0.000000 0.000000 0.000000 43 | Kd 0.213333 0.213333 0.213333 44 | Ks 0.500000 0.500000 0.500000 45 | Ni 1.000000 46 | d 1.000000 47 | illum 2 48 | 49 | newmtl blinn3SG 50 | Ns 96.078431 51 | Ka 0.000000 0.000000 0.000000 52 | Kd 0.542745 0.542745 0.542745 53 | Ks 0.500000 0.500000 0.500000 54 | Ni 1.000000 55 | d 1.000000 56 | illum 2 57 | 58 | newmtl blinn4SG 59 | Ns 96.078431 60 | Ka 0.000000 0.000000 0.000000 61 | Kd 0.599216 0.599216 0.599216 62 | Ks 0.500000 0.500000 0.500000 63 | Ni 1.000000 64 | d 1.000000 65 | illum 2 66 | 67 | newmtl blinn7SG 68 | Ns 96.078431 69 | Ka 0.000000 0.000000 0.000000 70 | Kd 0.800000 0.800000 0.800000 71 | Ks 0.500000 0.500000 0.500000 72 | Ni 1.000000 73 | d 1.000000 74 | illum 2 75 | 76 | newmtl initialShadingGr 77 | Ns 96.078431 78 | Ka 0.000000 0.000000 0.000000 79 | Kd 0.398431 0.398431 0.398431 80 | Ks 0.500000 0.500000 0.500000 81 | Ni 1.000000 82 | d 1.000000 83 | illum 2 84 | 85 | newmtl lambert2SG 86 | Ns 96.078431 87 | Ka 0.000000 0.000000 0.000000 88 | Kd 0.423529 0.567843 0.486275 89 | Ks 0.500000 0.500000 0.500000 90 | Ni 1.000000 91 | d 1.000000 92 | illum 2 93 | 94 | newmtl lambert3SG 95 | Ns 96.078431 96 | Ka 0.000000 0.000000 0.000000 97 | Kd 0.800000 0.800000 0.800000 98 | Ks 0.500000 0.500000 0.500000 99 | Ni 1.000000 100 | d 1.000000 101 | illum 2 102 | -------------------------------------------------------------------------------- /soyuz.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from sense_hat import SenseHat 3 | import math 4 | import pi3d 5 | 6 | sense = SenseHat() 7 | 8 | display = pi3d.Display.create() 9 | cam = pi3d.Camera.instance() 10 | 11 | shader = pi3d.Shader("mat_light") 12 | 13 | model = pi3d.Model( 14 | file_string="apollo-soyuz.obj", 15 | name="model", x=0, y=-1, z=40, sx=1, sy=1, sz=1) 16 | 17 | model.set_shader(shader) 18 | 19 | cam.position((0, 20, 0)) 20 | cam.point_at((0, -1, 40)) 21 | keyb = pi3d.Keyboard() 22 | 23 | compass = gyro = accel = True 24 | sense.set_imu_config(compass, gyro, accel) 25 | 26 | yaw_offset = 72 27 | 28 | while display.loop_running(): 29 | o = sense.get_orientation_radians() 30 | if o is None: 31 | pass 32 | 33 | pitch = o["pitch"] 34 | roll = o["roll"] 35 | yaw = o["yaw"] 36 | 37 | yaw_total = yaw + math.radians(yaw_offset) 38 | 39 | sin_y = math.sin(yaw_total) 40 | cos_y = math.cos(yaw_total) 41 | 42 | sin_p = math.sin(pitch) 43 | cos_p = math.cos(pitch) 44 | 45 | sin_r = math.sin(roll) 46 | cos_r = math.cos(roll) 47 | 48 | abs_roll = math.degrees(math.asin(sin_p * cos_y + cos_p * sin_r * sin_y)) 49 | abs_pitch = math.degrees(math.asin(sin_p * sin_y - cos_p * sin_r * cos_y)) 50 | 51 | model.rotateToZ(abs_roll) 52 | model.rotateToX(abs_pitch) 53 | model.rotateToY(math.degrees(yaw_total)) 54 | model.draw() 55 | 56 | keypress = keyb.read() 57 | 58 | if keypress == 27: 59 | keyb.close() 60 | display.destroy() 61 | break 62 | elif keypress == ord('m'): 63 | compass = not compass 64 | sense.set_imu_config(compass, gyro, accel) 65 | elif keypress == ord('g'): 66 | gyro = not gyro 67 | sense.set_imu_config(compass, gyro, accel) 68 | elif keypress == ord('a'): 69 | accel = not accel 70 | sense.set_imu_config(compass, gyro, accel) 71 | elif keypress == ord('='): 72 | yaw_offset += 1 73 | elif keypress == ord('-'): 74 | yaw_offset -= 1 75 | --------------------------------------------------------------------------------