Uranus Explorers | Make Sense Out of Mars

Team Updates

# Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
# ******************************************************
#
# REAL DATA FROM SERVER (IMU)
#
# def gen_point():
# return client.get_data()
#
# def update_line(num, data, line):
# try:
# x, y, z = gen_point()
# data[0].append(x)
# data[1].append(y)
# data[2].append(z)
#
# line.set_data([data[0][:num], data[1][:num]])
# line.set_3d_properties(data[2][:num])
#
# relimit(data)
# return [line]
# except socket.timeout:
# return [line]
#
# ******************************************************
# ******************************************************
# SIMULATED DATA
# ******************************************************
import dataset
def update_line(num, data, line):
line.set_data(dataset.x[:num], dataset.y[:num])
line.set_3d_properties(dataset.z[:num])
def relimit(data):
max_x = max(0.4, max([abs(i) for i in data[0]]))
max_y = max(0.4, max([abs(i) for i in data[1]]))
max_z = max(0.4, max([abs(i) for i in data[2]]))
x = [-max_x, max_x]
y = [-max_y, max_y]
z = [-max_z, max_z]
ax.set_xlim3d(x)
ax.set_ylim3d(y)
ax.set_zlim3d(z)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# x = np.linspace(-10, 10, 2000)
# y = np.linspace(-10, 10, 2000)
# z = np.sin(x) * np.cos(y)
# theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
# z = np.linspace(-2, 2, 100)
# r = z ** 2 + 1
# x = r * np.sin(theta)
# y = r * np.cos(theta)
data = [[], [], []]
line, = ax.plot(data[0][0:1], data[1][0:1], data[2][0:1])
# Setting the axes properties
ax.set_xlim3d([-4.0, 18.0])
ax.set_ylim3d([-8.0, 10.0])
ax.set_zlim3d([-1.0, 1.0])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('ALPS 3D simulation')
line_ani = animation.FuncAnimation(fig, update_line, fargs=(data, line),
interval=100, blit=False)
# ax.plot(x, y, z, label="Image")
# ax.legend()
plt.show()
view raw app.py hosted with ❤ by GitHub
# Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import socket
import json
print("Initializing client")
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.settimeout(0.1)
host = "raspberrypi.local"
sock.sendto("connect".encode(), (host, 8088))
print("connected")
def get_data():
data = json.loads(sock.recv(1024).decode())
print(data)
return data
view raw client.py hosted with ❤ by GitHub
# Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from numpy import linspace
from numpy.random import rand
# First segment
x1 = (linspace(0, 10, num=130) + (rand(130) - 0.5) * 0.1).tolist()
y1 = (linspace(0, 0, num=130) + (rand(130) - 0.5) * 0.1).tolist()
# Second
x2 = (linspace(10, 10, num=40) + (rand(40) - 0.5) * 0.1).tolist()
y2 = (linspace(0, -4, num=40) + (rand(40) - 0.5) * 0.1).tolist()
# Third
x3 = (linspace(10, 16, num=50) + (rand(50) - 0.5) * 0.1).tolist()
y3 = (linspace(-4, -4, num=50) + (rand(50) - 0.5) * 0.1).tolist()
x = x1 + x2 + x3
y = y1 + y2 + y3
z = (linspace(0, 0, num=220) + (rand(220) - 0.5) * 0.05).tolist()
view raw dataset.py hosted with ❤ by GitHub
# Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#!/usr/bin/python
import smbus
import math
from numpy import array
# Register
power_mgmt_1 = 0x6b
power_mgmt_2 = 0x6c
def read_byte(reg):
return bus.read_byte_data(address, reg)
def read_word(reg):
h = bus.read_byte_data(address, reg)
l = bus.read_byte_data(address, reg + 1)
value = (h << 8) + l
return value
def read_word_2c(reg):
val = read_word(reg)
if (val >= 0x8000):
return -((65535 - val) + 1)
else:
return val
def dist(a, b):
return math.sqrt((a * a) + (b * b))
def get_y_rotation(x, y, z):
radians = math.atan2(x, dist(y, z))
return -math.degrees(radians)
def get_x_rotation(x, y, z):
radians = math.atan2(y, dist(x, z))
return math.degrees(radians)
bus = smbus.SMBus(1) # bus = smbus.SMBus(0) fuer Revision 1
address = 0x68 # via i2cdetect
# Aktivieren, um das Modul ansprechen zu koennen
bus.write_byte_data(address, power_mgmt_1, 0)
# print "Gyroskop"
# print "--------"
#
# gyroskop_xout = read_word_2c(0x43)
# gyroskop_yout = read_word_2c(0x45)
# gyroskop_zout = read_word_2c(0x47)
#
# print "gyroskop_xout: ", ("%5d" % gyroskop_xout), " skaliert: ", (gyroskop_xout / 131)
# print "gyroskop_yout: ", ("%5d" % gyroskop_yout), " skaliert: ", (gyroskop_yout / 131)
# print "gyroskop_zout: ", ("%5d" % gyroskop_zout), " skaliert: ", (gyroskop_zout / 131)
#
# print
# print "Beschleunigungssensor"
# print "---------------------"
#
# beschleunigung_xout = read_word_2c(0x3b)
# beschleunigung_yout = read_word_2c(0x3d)
# beschleunigung_zout = read_word_2c(0x3f)
#
# beschleunigung_xout_skaliert = beschleunigung_xout / 16384.0
# beschleunigung_yout_skaliert = beschleunigung_yout / 16384.0
# beschleunigung_zout_skaliert = beschleunigung_zout / 16384.0
#
# print "beschleunigung_xout: ", ("%6d" % beschleunigung_xout), " skaliert: ", beschleunigung_xout_skaliert
# print "beschleunigung_yout: ", ("%6d" % beschleunigung_yout), " skaliert: ", beschleunigung_yout_skaliert
# print "beschleunigung_zout: ", ("%6d" % beschleunigung_zout), " skaliert: ", beschleunigung_zout_skaliert
#
# print "X Rotation: " , get_x_rotation(beschleunigung_xout_skaliert, beschleunigung_yout_skaliert, beschleunigung_zout_skaliert)
# print "Y Rotation: " , get_y_rotation(beschleunigung_xout_skaliert, beschleunigung_yout_skaliert, beschleunigung_zout_skaliert)
def get_gyro_raw():
gyroskop_xout = read_word_2c(0x43)
gyroskop_yout = read_word_2c(0x45)
gyroskop_zout = read_word_2c(0x47)
_tuple = ((gyroskop_xout / 131),
(gyroskop_yout / 131),
(gyroskop_zout / 131)
)
return array(_tuple)
def calibrate():
global offset
s = array((0.0, 0.0, 0.0))
for i in range(2000):
s += array(get_acceleration_raw())
offset = s / 2000.0
print("offset:", offset)
def get_acceleration_raw():
beschleunigung_xout = read_word_2c(0x3b)
beschleunigung_yout = read_word_2c(0x3d)
beschleunigung_zout = read_word_2c(0x3f)
beschleunigung_xout_skaliert = beschleunigung_xout / 16384.0
beschleunigung_yout_skaliert = beschleunigung_yout / 16384.0
beschleunigung_zout_skaliert = beschleunigung_zout / 16384.0
a = (beschleunigung_xout_skaliert, beschleunigung_yout_skaliert,
beschleunigung_zout_skaliert)
return a
def get_acceleration():
global offset
a_raw = array(get_acceleration_raw())
a = 9.81 * (a_raw - offset)
return tuple(a.tolist())
view raw gyro.py hosted with ❤ by GitHub
Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
view raw LICENSE hosted with ❤ by GitHub
# Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import numpy
import gyro
from threading import Thread
from time import sleep
interval = 0.01
class LPS(Thread):
def __init__(self):
super().__init__()
gyro.calibrate()
self.pos = numpy.array((0, 0, 0))
# self.vel = numpy.array(0, 0, 0)
# self.acc = numpy.array(0, 0, 0)
def run(self):
#a = numpy.array(gyro.get_acceleration())
#sleep(interval)
while True:
a = numpy.array(gyro.get_acceleration())
self.pos = self.pos + a * (interval ** 2)
sleep(interval)
def get_pos(self): return self.pos.tolist()
view raw lps.py hosted with ❤ by GitHub
# Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from PyQt5.QtWidgets import *
from sys import argv
class Application(QWidget):
def __init__(self):
super().__init__()
self.__initialize_window__()
self.__initialize_components__()
def __initialize_window__(self):
self.resize(250, 150)
self.move(300, 300)
self.setWindowTitle('Simple')
self.show()
print("shown")
def __initialize_components__(self):
self.text = QTextEdit("Ciao", self)
self.text.show()
def run(self):
self.app.exec()
app = QApplication(argv)
w = Application()
exit(app.exec_())
view raw sensors.py hosted with ❤ by GitHub
# Copyright 2018 Uranus Explorers Team: Lorenzo Mureu, Andrea Foschiatti, Matteo Stoppa, Juan Carlos Vega Oliver
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import socket
import json
from time import sleep, time
import threading
import lps
import gyro
interval = 1 # 100 ms
lps_thread = lps.LPS()
#gyro.calibrate()
def client_thread(addr):
global lps_thread
while True:
data = lps_thread.get_pos()
#data = {"acceleration": gyro.get_acceleration(), "time": time()}
sock.sendto(json.dumps(data).encode(), addr)
sleep(interval)
conn.close()
print("Initializing server")
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.bind(("", 8088))
# sock.listen(10)
print("Server started")
# now keep talking with the client
while 1:
# wait to accept a connection - blocking call
_data, addr = sock.recvfrom(4096)
print('Connected with ' + addr[0] + ':' + str(addr[1]))
threading.Thread(target=client_thread, args=(addr,)).start()
lps_thread.start()
s.close()
view raw server.py hosted with ❤ by GitHub
L
Lorenzo
NASA Logo

SpaceApps is a NASA incubator innovation program.