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.
importmatplotlib.pyplotasplt
importnumpyasnp
frommpl_toolkits.mplot3dimportAxes3D
importmatplotlib.animationasanimation
# ******************************************************
#
# 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
# ******************************************************
importdataset
defupdate_line(num, data, line):
line.set_data(dataset.x[:num], dataset.y[:num])
line.set_3d_properties(dataset.z[:num])
defrelimit(data):
max_x=max(0.4, max([abs(i) foriindata[0]]))
max_y=max(0.4, max([abs(i) foriindata[1]]))
max_z=max(0.4, max([abs(i) foriindata[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.
importsocket
importjson
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")
defget_data():
data=json.loads(sock.recv(1024).decode())
print(data)
returndata
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.
fromnumpyimportlinspace
fromnumpy.randomimportrand
# 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
importsmbus
importmath
fromnumpyimportarray
# Register
power_mgmt_1=0x6b
power_mgmt_2=0x6c
defread_byte(reg):
returnbus.read_byte_data(address, reg)
defread_word(reg):
h=bus.read_byte_data(address, reg)
l=bus.read_byte_data(address, reg+1)
value= (h<<8) +l
returnvalue
defread_word_2c(reg):
val=read_word(reg)
if (val>=0x8000):
return-((65535-val) +1)
else:
returnval
defdist(a, b):
returnmath.sqrt((a*a) + (b*b))
defget_y_rotation(x, y, z):
radians=math.atan2(x, dist(y, z))
return-math.degrees(radians)
defget_x_rotation(x, y, z):
radians=math.atan2(y, dist(x, z))
returnmath.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)
defget_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)
)
returnarray(_tuple)
defcalibrate():
globaloffset
s=array((0.0, 0.0, 0.0))
foriinrange(2000):
s+=array(get_acceleration_raw())
offset=s/2000.0
print("offset:", offset)
defget_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)
returna
defget_acceleration():
globaloffset
a_raw=array(get_acceleration_raw())
a=9.81* (a_raw-offset)
returntuple(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.
importnumpy
importgyro
fromthreadingimportThread
fromtimeimportsleep
interval=0.01
classLPS(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)
defrun(self):
#a = numpy.array(gyro.get_acceleration())
#sleep(interval)
whileTrue:
a=numpy.array(gyro.get_acceleration())
self.pos=self.pos+a* (interval**2)
sleep(interval)
defget_pos(self): returnself.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.
fromPyQt5.QtWidgetsimport*
fromsysimportargv
classApplication(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()
defrun(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.
importsocket
importjson
fromtimeimportsleep, time
importthreading
importlps
importgyro
interval=1# 100 ms
lps_thread=lps.LPS()
#gyro.calibrate()
defclient_thread(addr):
globallps_thread
whileTrue:
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
while1:
# 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.