Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing #23

Merged
merged 46 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fa73fba
Tests on the pi
NickofTime6 Dec 12, 2023
d2df216
Add files via upload
NickofTime6 Dec 12, 2023
e2aa981
Apply Black formatting
actions-user Dec 12, 2023
3668bf4
Tried copy pasting instead of replacing the files to preserve commit …
J-MaFf Dec 13, 2023
2ca3bc8
Merge pull request #22 from J-MaFf/commitHistory
J-MaFf Dec 13, 2023
f6dede3
Removed testing folder.
J-MaFf Dec 13, 2023
1df508a
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
NickofTime6 Dec 13, 2023
40b6ccd
Need address.
J-MaFf Dec 13, 2023
46e7613
Apply Black formatting
actions-user Dec 13, 2023
3aec611
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
NickofTime6 Dec 13, 2023
5a3be58
test2
NickofTime6 Dec 13, 2023
a042660
Apply Black formatting
actions-user Dec 13, 2023
321fa20
test3
NickofTime6 Dec 13, 2023
85ca71c
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
NickofTime6 Dec 13, 2023
202b000
Apply Black formatting
actions-user Dec 13, 2023
f78fa68
Change to self.i2c
J-MaFf Dec 13, 2023
d7cb00a
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
J-MaFf Dec 13, 2023
f37fc25
temp accel and baro working
NickofTime6 Dec 13, 2023
7df362b
Apply Black formatting
actions-user Dec 13, 2023
1192693
Removed sensorValue var assignment.
J-MaFf Dec 13, 2023
662d5f6
Updated view to look prettier.
J-MaFf Dec 13, 2023
e499eb4
Apply Black formatting
actions-user Dec 13, 2023
ff50145
sensors return lists not tuples
NickofTime6 Dec 13, 2023
e3b9b4f
Apply Black formatting
actions-user Dec 13, 2023
486bb7a
changes
J-MaFf Dec 13, 2023
346c146
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
J-MaFf Dec 13, 2023
6ceae8a
Apply Black formatting
actions-user Dec 13, 2023
5caf828
Changing view.
J-MaFf Dec 13, 2023
9a7a68e
Apply Black formatting
actions-user Dec 13, 2023
92b8f54
added barometer
NickofTime6 Dec 13, 2023
6543700
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
NickofTime6 Dec 13, 2023
b17bed3
Apply Black formatting
actions-user Dec 13, 2023
fd9988a
update_view method in controler now prints the sensor name.
J-MaFf Dec 13, 2023
5df6341
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
J-MaFf Dec 13, 2023
68d9893
Fixed typo
J-MaFf Dec 13, 2023
9c287e1
Sensor name is no longer included in the data array. Instead, it is p…
J-MaFf Dec 13, 2023
97a9fe5
Apply Black formatting
actions-user Dec 13, 2023
01a1700
changed veiw a bit
NickofTime6 Dec 13, 2023
27432a6
Apply Black formatting
actions-user Dec 13, 2023
e86f6f9
added self
J-MaFf Dec 13, 2023
0162850
Merge branch 'testing' of https://github.com/J-MaFf/RocketNavigator i…
J-MaFf Dec 13, 2023
4176f0f
made output look good
NickofTime6 Dec 13, 2023
23fc62b
output cleaned
NickofTime6 Dec 13, 2023
5c1abdc
Apply Black formatting
actions-user Dec 13, 2023
1c258c1
donezo
NickofTime6 Dec 13, 2023
06e0ae8
donezo
NickofTime6 Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pi-apps
Submodule pi-apps added at 6ebce6
67 changes: 41 additions & 26 deletions src/controller/controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# This is the middleman between your Model and View. It will control the flow of data and handle user input.
import RPi.GPIO as GPIO
from datetime import datetime

from model.model import AccelerometerModel, SensorModel, TemperatureModel
from model.model import (
AccelerometerModel,
BarometerModel,
SensorModel,
TemperatureModel,
GyroModel,
)


class RocketController:
Expand All @@ -27,11 +34,12 @@ def __init__(self, model, view):
barometer clock is on pin 13 (gpio2) data line is on pin 11 (gpio0) (bpm338 chip) Hex address 0x77
barometer 2 clock is on pin 22 (gpio22) data line is on pin 21 (gpio21)
"""
sensorPinList = self.check_sensors([7, 5, 3, 16, 15, 13, 11, 22, 21])
# sensorPinList = self.check_sensors([7, 5, 3, 16, 15, 13, 11, 22, 21])
# Create sensor objects
self.sensorObjectList = self.createSensors(sensorPinList)
# self.sensorObjectList = self.createSensors(sensorPinList)
self.sensorObjectList = self.createSensors()

def createSensors(self, sensorPinList):
def createSensors(self): # , sensorPinList):
"""
Creates a list of SensorModel objects from a list of pins.

Expand All @@ -42,42 +50,49 @@ def createSensors(self, sensorPinList):
list: A list of SensorModel objects.
"""
# TODO: Create a list of SensorModel objects
i = 0
# Create Temperature Sensor object
TemperatureSensor = TemperatureModel(sensorPinList[i], addresses)
i += 1
# print(sensorPinList)
# Create Temperature Sensor objects
TemperatureSensor1 = TemperatureModel(28, 0) # sensorPinList[i], 0)
TemperatureSensor2 = TemperatureModel(28, 1) # sensorPinList[i], 1)
TemperatureSensor3 = TemperatureModel(28, 2) # sensorPinList[i], 2)
TemperatureSensor4 = TemperatureModel(28, 3) # sensorPinList[i], 3)
# Create Accelerometer Sensor object
AccelerometerSensor1 = AccelerometerModel(
sensorPinList[i], sensorPinList[i + 1]
)
i += 2
AccelerometerSensor2 = AccelerometerModel(
sensorPinList[i], sensorPinList[i + 1]
)
i += 2
AccelerometerSensor1 = (
AccelerometerModel()
) # sensorPinList[i], sensorPinList[i + 1]
# Create Barometer Sensor object
BarometerSensor1 = SensorModel(sensorPinList[i], sensorPinList[i + 1])
i += 2
BarometerSensor2 = SensorModel(sensorPinList[i], sensorPinList[i + 1])
i += 2
BarometerSensor1 = BarometerModel() # sensorPinList[i], sensorPinList[i + 1])
# Create Gyro sensor object
GyroSensor = GyroModel()

# Return list of sensor objects
return [
TemperatureSensor,
sensorList = [
TemperatureSensor1,
TemperatureSensor2,
TemperatureSensor3,
TemperatureSensor4,
AccelerometerSensor1,
AccelerometerSensor2,
# AccelerometerSensor2,
BarometerSensor1,
BarometerSensor2,
# BarometerSensor2,
GyroSensor,
]
# print(sensorList)
return sensorList

def update_view(self):
"""
Updates the view with the latest sensor data from the model.

"""
# print(self.sensorObjectList)
data = []
data.append(datetime.now())
for sensor in self.sensorObjectList:
data = sensor.readData()
self.view.display_data(data)
for point in sensor.readData():
data.append(point)
# line return between each sensor
self.view.display_data(data)

def check_sensors(self, pinList):
"""
Expand Down
24 changes: 24 additions & 0 deletions src/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
2023-12-13 00:01:19.209789,24.062,23.312,23.812,23.5,0.1569064,0.6668522,9.414383999999998,22.26335979066789,1003.4449316768982,81.7380436055835,-0.016493361431346415,-0.07941248096574201,-0.01832595714594046
2023-12-13 00:01:46.746576,24.312,23.562,24.062,23.75,0.1569064,0.6668522,9.492837199999999,22.277085667010397,1003.3940474258737,82.08008813258088,-0.016493361431346415,-0.07422012644105887,-0.014813482026301873
2023-12-13 00:02:10.369771,24.5,23.687,24.25,23.937,0.196133,0.7060788,9.3751574,22.290811501443386,1003.3229578195887,81.99537353155162,-0.015424347264499889,-0.07574728953655392,-0.01756237559819294
2023-12-13 00:02:19.220069,24.562,23.687,24.25,23.937,0.1176798,0.7060788,9.4536106,22.29538677027449,1003.444743994575,81.82594680112628,-0.016035212502697904,-0.07345654489331135,-0.014508049407202865
2023-12-13 00:02:24.914510,24.562,23.75,24.312,24.0,0.1569064,0.6668522,9.414383999999998,22.28623622795567,1003.5156451199671,81.14502885127838,-0.018784106074588976,-0.07192938179781631,-0.01863138976503947
2023-12-13 00:02:30.479088,24.562,23.812,24.375,24.0,0.196133,0.6276256,9.4536106,22.28623622795567,1003.3940474258737,81.73962517629208,-0.01863138976503947,-0.07330382858376185,-0.016493361431346415
2023-12-13 00:02:36.074602,24.625,23.812,24.375,24.062,0.1569064,0.7060788,9.4536106,22.290811501443386,1003.5461395179083,81.22974277307239,-0.017409659288643436,-0.0752891406079054,-0.015271630954950386
2023-12-13 00:02:41.724289,24.687,23.875,24.437,24.125,0.1176798,0.6276256,9.4536106,22.30453729396686,1003.5663440247763,81.74123467171543,-0.01756237559819294,-0.07345654489331135,-0.014202616788103858
2023-12-13 00:02:47.345711,24.687,23.875,24.437,24.125,0.1176798,0.6668522,9.414383999999998,22.29538677027449,1003.5156451199671,81.74123467171543,-0.016035212502697904,-0.06979135346412325,-0.01832595714594046
2023-12-13 00:02:53.002160,24.687,23.937,24.437,24.125,0.1176798,0.6668522,9.414383999999998,22.29996203444898,1003.5156451199671,81.82594680112628,-0.01756237559819294,-0.07635815477475191,-0.015118914645400881
2023-12-13 00:02:58.598573,24.75,23.812,24.5,24.125,0.0784532,0.7060788,9.4536106,22.29538677027449,1003.485149962731,81.48548239201781,-0.017715091907742446,-0.07590000584610342,-0.015118914645400881
2023-12-13 00:03:04.208480,24.562,23.875,24.312,24.062,0.1176798,0.7060788,9.414383999999998,22.29538677027449,1003.5360372406167,81.31445751875889,-0.016951510359994926,-0.07345654489331135,-0.015577063574049392
2023-12-13 00:03:09.793630,24.375,23.812,24.187,24.0,0.1176798,0.7060788,9.3751574,22.30453729396686,1003.5865484680137,81.6565233661774,-0.016340645121796914,-0.07376197751241036,-0.01114829059711378
2023-12-13 00:03:15.412241,24.25,23.75,24.125,23.875,0.1176798,0.6668522,9.414383999999998,22.318263044580817,1003.4748561257517,81.48710322670499,-0.01893682238413848,-0.07635815477475191,-0.018020524526841455
2023-12-13 00:03:20.988935,24.187,23.75,24.0,23.875,0.0784532,0.6668522,9.4536106,22.318263044580817,1003.4342580135592,81.65816456643087,-0.01756237559819294,-0.07696902001294993,-0.013286318930806834
2023-12-13 00:03:26.570774,24.062,23.625,24.0,23.812,0.0784532,0.6668522,9.4536106,22.327413521707058,1003.4950581416638,81.48875198628893,-0.018020524526841455,-0.07284567965511334,-0.012370021073509813
2023-12-13 00:03:32.208755,23.937,23.562,23.875,23.75,0.0784532,0.7060788,9.414383999999998,22.322838285472244,1003.4748561257517,82.16806852727277,-0.016340645121796914,-0.07177666548826682,-0.010384709049366262
2023-12-13 00:03:37.767151,23.875,23.5,23.75,23.687,0.0784532,0.7060788,9.492837199999999,22.313687799032778,1003.5560524518535,81.4023943927706,-0.015882496193148403,-0.06918048822592525,-0.014966198335851376
2023-12-13 00:04:37.441899,23.375,23.0,23.25,23.187,0.1176798,0.7060788,9.4536106,22.318263044580817,1003.4748561257517,81.4023943927706,-0.015882496193148403,-0.06841690667817772,-0.010079276430267254
2023-12-13 00:04:51.096768,23.312,22.937,23.25,23.125,0.0784532,0.7060788,9.414383999999998,22.33198875328526,1003.4138603966162,81.99865362019423,-0.01466076571675237,-0.06841690667817772,-0.010231992739816757
2023-12-13 00:05:04.658839,23.312,22.875,23.187,23.062,0.1176798,0.6668522,9.414383999999998,22.341139202471823,1003.5253610461826,81.7445374384085,-0.014813482026301873,-0.0678060414399797,-0.01786780821729195
2023-12-13 00:05:18.269591,23.25,22.812,23.125,23.0,0.0784532,0.6668522,9.3751574,22.327413521707058,1003.383361393116,82.16974290155184,-0.014508049407202865,-0.0673478925113312,-0.00916297857297023
2023-12-13 00:05:31.893397,23.125,22.75,23.062,22.937,0.0784532,0.7060788,9.414383999999998,22.341139202471823,1003.4035609817219,81.91563311544874,-0.01618792881224741,-0.06811147405907872,-0.013744467859455347
2023-12-13 00:05:45.479582,23.125,22.75,23.0,22.937,0.1176798,0.6668522,9.414383999999998,22.35486484132707,1003.4033584597352,81.32102694557732,-0.015882496193148403,-0.07223481441691533,-0.01786780821729195
8 changes: 7 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
from view.view import RocketView
from controller.controller import RocketController
import csv
import os
import time

# This conditional makes sure your code only runs when the script is executed directly
# and not when it's imported as a module in another script.

os.system("modprobe w1-gpio")
os.system("modprobe w1-therm")

if __name__ == "__main__":
# Create an instance of the Model. This is where you'll manage your sensor data
# and database interactions.
Expand All @@ -26,7 +32,7 @@
while True:
# This function call tells the controller to update the View with new data.
controller.update_view()

time.sleep(10)
# If your sensors update frequently, you could add a sleep here.
# For example, time.sleep(1) would pause the loop for 1 second before continuing.
# This is important to prevent your loop from consuming too much CPU by running as fast as possible.
Expand Down
Binary file modified src/model/__pycache__/model.cpython-39.pyc
Binary file not shown.
80 changes: 51 additions & 29 deletions src/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
import board
import digitalio
import busio
import adafruit_lis3dh

# import adafruit_lis3dh
import adafruit_l3gd20
import adafruit_adxl34x


class RocketModel:
def __init__(self, sensors):
def __init__(self): # , sensors):
self.sensors = []

def initSensors(self, sensors):
self.sensors = sensors

def readData(self):
Expand Down Expand Up @@ -70,6 +75,17 @@ def readData(self):
# Generic method to read data from the sensor
return GPIO.input(self.pin)

def sensorType(self):
"""
Returns the type of sensor.

Returns:
--------
str:
The type of sensor.
"""
return self.__class__.__name__


class TemperatureModel(SensorModel):
"""
Expand All @@ -79,17 +95,18 @@ class TemperatureModel(SensorModel):
pin (int): The GPIO pin number to which the sensor is connected.
"""

def __init__(self, pin, addresses):
def __init__(self, pin, address):
super().__init__(pin)
os.system("modprobe w1-gpio") # what are these
os.system("modprobe w1-therm") # Might not be needed

base_dir = "/sys/bus/w1/devices/"
device_folder = glob.glob(base_dir + pin + "*")[
addresses
] # 28 should be pin number
# print(pin)
device_folder = glob.glob(base_dir + str(pin) + "*")[address]
# 28 should be pin number
# This needs to be changed to have a device folder for all the sensors
device_file = device_folder + "/w1_slave"
self.sensor = device_file

def readData(self):
"""
Expand All @@ -98,11 +115,7 @@ def readData(self):
Returns:
float: The temperature in Fahrenheit.
"""
sensorValue = GPIO.input(
self.pin
) # I dont think this is needed as one wire protocol is used

return self.convertData(self.device_file)
return [self.convertData(self.sensor)]

def convertData(self, device_file):
"""
Expand All @@ -114,6 +127,7 @@ def convertData(self, device_file):
Returns:
float: The temperature in celcius.
"""
# print(device_file)
lines = self.read_temp_raw(device_file)
while lines[0].strip()[-3:] != "YES":
time.sleep(0.2)
Expand All @@ -126,7 +140,7 @@ def convertData(self, device_file):
return temp_c
# return sensorValue * 1.8 + 32 # CHECK CONVERSION FORMULA

def read_temp_raw(device_file):
def read_temp_raw(self, device_file):
"""
Read the raw temperature data from the device file.

Expand Down Expand Up @@ -191,18 +205,23 @@ class AccelerometerModel(SensorModel):
pin (int): The GPIO pin number to which the sensor is connected.
"""

def __init__(self, clkPin, pin):
def __init__(self): # , clkPin, pin):
"""
Initializes the Model object with the specified pin.

Args:
pin (int): The pin number to use for the Model object.
"""
i2c = board.I2C()
address = 0x53
self.accelerometer = adafruit_adxl34x.ADXL343(i2c, address)
"""
super().__init__(pin)
self.clkPin = clkPin
i2c = busio.I2C(board.SCL, board.SDA)
int1 = digitalio.DigitalInOut(board.D24)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
"""

def readData(self):
"""
Expand All @@ -211,9 +230,13 @@ def readData(self):
Returns:
int: The sensor value read from the GPIO pin.
"""
x, y, z = self.accelerometer.acceleration
return [x, y, z]
"""
sensorValue = GPIO.input(self.pin)
x, y, z = lis3dh.acceleration
return x, y, z
"""


class GPSModel(SensorModel):
Expand Down Expand Up @@ -267,17 +290,18 @@ class BarometerModel(SensorModel):
pin (int): The GPIO pin number to which the sensor is connected.
"""

def __init__(self, clkPin, pin):
def __init__(self): # , clkPin, pin):
"""
Initializes the Model class with a given pin.

Args:
pin (int): The pin number to be used for initialization.
"""
super().__init__(pin)
self.clkPin = clkPin
# super().__init__(pin)
# self.clkPin = clkPin
i2c = board.I2C()
bmp = adafruit_bmp3xx.BMP3XX_I2C(i2c)
self.bmp = adafruit_bmp3xx.BMP3XX_I2C(i2c)
print("test")

def readData(self):
"""
Expand All @@ -286,15 +310,13 @@ def readData(self):
Returns:
int: The sensor value.
"""
sensorValue = GPIO.input(self.pin)
bmp = adafruit_bmp3xx.BMP3XX_I2C(self.i2c)
temperature = bmp.temperature
pressure = bmp.pressure
altitude = bmp.altitude
return temperature, pressure, altitude
temperature = self.bmp.temperature
pressure = self.bmp.pressure
altitude = self.bmp.altitude
return [temperature, pressure, altitude]


class GyroSensor(SensorModel):
class GyroModel(SensorModel):
"""
A class representing a Gyro model.

Expand All @@ -305,19 +327,19 @@ class GyroSensor(SensorModel):
pin (int): The GPIO pin number to which the sensor is connected.
"""

def __init__(self, pin):
def __init__(self): # , pin):
"""
Initializes a new instance of the Model class.

Args:
pin (int): The BCM pin number to which the sensor is connected.
"""

self.pin = pin
# self.pin = pin

# Set up your sensor pins and initialize them
# For example, if you have a sensor on BCM pin 23
GPIO.setup(pin, GPIO.IN)
# GPIO.setup(pin, GPIO.IN)
i2c = board.I2C()
self.sensor = adafruit_l3gd20.L3GD20_I2C(i2c)

Expand All @@ -331,5 +353,5 @@ def readData(self):
The value read from the sensor.
"""
# Generic method to read data from the sensor
gyro_data = self.sensor.gyro
return gyro_data
x, y, z = self.sensor.gyro
return [x, y, z]
Loading
Loading