Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
77 changes: 76 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,79 @@
Lib/
.idea/

vessel_info.json
vessel_info.json
share/sdl2/bin/LICENSE.png.txt
share/sdl2/bin/LICENSE.opusfile.txt
share/sdl2/bin/zlib1.dll
share/sdl2/bin/SDL2_ttf.dll
share/sdl2/bin/SDL2_mixer.dll
share/sdl2/bin/SDL2_image.dll
share/sdl2/bin/SDL2.dll
share/sdl2/bin/LICENSE.zlib.txt
share/sdl2/bin/LICENSE.webp.txt
share/sdl2/bin/LICENSE.tiff.txt
share/sdl2/bin/LICENSE.opus.txt
share/sdl2/bin/LICENSE.ogg-vorbis.txt
share/sdl2/bin/LICENSE.mpg123.txt
share/sdl2/bin/LICENSE.modplug.txt
share/sdl2/bin/LICENSE.jpeg.txt
share/sdl2/bin/LICENSE.harfbuzz.txt
share/sdl2/bin/LICENSE.freetype.txt
share/sdl2/bin/LICENSE.FLAC.txt
share/sdl2/bin/libwebp-7.dll
share/sdl2/bin/libvorbisfile-3.dll
share/sdl2/bin/libvorbis-0.dll
share/sdl2/bin/libtiff-5.dll
share/sdl2/bin/libpng16-16.dll
share/sdl2/bin/libopusfile-0.dll
share/sdl2/bin/libopus-0.dll
share/sdl2/bin/libogg-0.dll
share/sdl2/bin/libmpg123-0.dll
share/sdl2/bin/libmodplug-1.dll
share/sdl2/bin/libjpeg-9.dll
share/sdl2/bin/libFLAC-8.dll
share/glew/bin/glew32.dll
share/angle/bin/libGLESv2.dll
share/angle/bin/libEGL.dll
share/angle/bin/d3dcompiler_47.dll
Scripts/wsdump.exe
Scripts/rstpep2html.py
Scripts/rst2xml.py
Scripts/rst2xetex.py
Scripts/rst2s5.py
Scripts/rst2pseudoxml.py
Scripts/rst2odt_prepstyles.py
Scripts/rst2odt.py
Scripts/rst2man.py
Scripts/rst2latex.py
Scripts/rst2html5.py
Scripts/rst2html4.py
Scripts/rst2html.py
Scripts/pywin32_testall.py
Scripts/pywin32_postinstall.py
Scripts/pythonw.exe
Scripts/python.exe
Scripts/pyserial-ports.exe
Scripts/pyserial-miniterm.exe
Scripts/pygmentize.exe
Scripts/pip3.exe
Scripts/pip3.10.exe
Scripts/pip.exe
Scripts/pasteurize.exe
Scripts/pasteurize-script.py
Scripts/normalizer.exe
Scripts/jsonschema.exe
Scripts/httpx.exe
Scripts/garden.bat
Scripts/garden
Scripts/futurize.exe
Scripts/futurize-script.py
Scripts/f2py.exe
Scripts/docutils.exe
Scripts/deactivate.bat
Scripts/Activate.ps1
Scripts/activate.bat
Scripts/activate
pyvenv.cfg
Include/site/python3.10/greenlet/greenlet.h
submodules/tinyproto
17 changes: 5 additions & 12 deletions app/content/flight_director/flight_director.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
from asyncio import Future, Task
import asyncio
from datetime import datetime, timedelta
import threading
import time
from typing import Collection, Iterable, Tuple, Type, Union, cast
from typing import Iterable, Tuple, Type, Union
from uuid import UUID, uuid4

from dataclasses import dataclass
from app.content.flight_director.abort_command import AbortCommand
from app.content.flight_director.arm_director_command import ArmDirectorCommand
from app.content.flight_director.start_countdown_command import StartCountDownCommand
from app.content.general_commands.calibrate import CalibrateZeroCommand
from app.content.general_commands.enable import DisableCommand, EnableCommand
from app.content.microcontroller.arduino_serial import ArduinoSerial
from app.content.motor_commands.open import IgniteCommand, OpenCommand
from app.content.sensors.android_native.acceleration_pyjinius import PyjiniusAccelerationSensor
from app.content.sensors.android_native.gyroscope_pyjinius import PyjiniusGyroscopeSensor
from app.content.sensors.android_native.inertial_reference_frame import InertialReferenceFrame
from app.content.sensors.arduino.igniter import IgniterSensor
from app.content.sensors.arduino.servo import ServoSensor
from app.logic.commands.command import Command, Command
from app.content.general_commands.enable import DisableCommand, EnableCommand, ResetCommand
from app.content.microcontroller.arduino.parts.igniter import IgniterSensor
from app.content.microcontroller.arduino.parts.servo import ServoSensor
from app.logic.commands.command import Command

from app.logic.rocket_definition import Part, Rocket

Expand Down Expand Up @@ -139,7 +132,7 @@ def run_arm(self, c: ArmDirectorCommand):

if not self.calibrated:
c.state = 'failed'
c.response_message = 'Sensors not yet calibrated'
c.response_message = 'sensors not yet calibrated'
return

if not self.arduino.connected:
Expand Down
73 changes: 73 additions & 0 deletions app/content/microcontroller/arduino/messages/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from typing import Collection, Iterable, Tuple, Type, Union, cast

class ResponseMessage:
arr: bytearray()

def __init__(self, arr):
self.arr = arr

def getPart(self) -> chr:
mask = 63;

return self.arr[0] & mask;

def getCommand(self) -> chr:
mask = 15;

return (self.arr[2] >> 4) & mask

def getIndex(self) -> chr:
return self.arr[1]

def getResponseRequestByte(self) -> chr:
mask = 1
return self.arr[0] >> 6 & mask

def getResult(self) -> chr:
mask = 15;

return self.arr[2] & mask;


class SensorData:
arr: bytearray()

def __init__(self, arr):
self.arr = arr

def getPart(self) -> chr:
mask = 127;

return self.arr[0] & mask;

def getType(self) -> chr:
mask = 15;

return (self.arr[1] >> 4) & mask;

def getPayloadLength(self) -> int:
mask = 15;

return self.arr[1] & mask;

def getData(self) -> list[int]:
arr = []
for i in range(self.getPayloadLength()):
arr.append(int.from_bytes(self.arr[2 + i * 2: 4 + i * 2], 'little'))

return arr


messageIndex = 1
def sendCommand(partID : chr, commandID : chr, pl : chr = 0):
global messageIndex
arr = bytearray(0 for x in range(3))

arr[0] |= 1 << 7
arr[0] |= partID
arr[1] |= messageIndex
arr[2] |= commandID << 4
arr[2] |= pl

messageIndex += 1
return arr, messageIndex - 1
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
from asyncio import Future, Task
from asyncio import Future
from datetime import timedelta
from typing import Collection, Iterable, Tuple, Type, Union, cast
from typing import Iterable, Tuple, Type, Union
from uuid import UUID

from dataclasses import dataclass
from app.content.general_commands.enable import DisableCommand, EnableCommand
from app.content.motor_commands.open import OpenCommand, CloseCommand, IgniteCommand
from app.content.sensors.arduino.servo import ServoSensor
from app.logic.commands.command import Command, Command
from app.content.general_commands.enable import DisableCommand, EnableCommand, ResetCommand
from app.content.motor_commands.open import IgniteCommand
from app.content.microcontroller.arduino.parts.servo import ServoSensor
from app.logic.commands.command import Command
from app.content.microcontroller.arduino_serial import ArduinoSerial
from app.logic.rocket_definition import Part, Rocket

from kivy.utils import platform


class IgniterSensor(Part):
type = 'Igniter'

enabled: bool = True

min_update_period = timedelta(milliseconds=20)
min_update_period = timedelta(milliseconds=100)

min_measurement_period = timedelta(milliseconds=1000)

Expand All @@ -38,13 +33,26 @@ class IgniterSensor(Part):

state: str

commandList : dict()

partID : chr

def __init__(self, _id: UUID, name: str, parent: Union[Part, Rocket, None], arduino_parent: Union[ArduinoSerial, None], parachute: ServoSensor, start_enabled=True):
self.arduino = arduino_parent
self.enabled = start_enabled
self.state = 'ready'
self.parachute = parachute
super().__init__(_id, name, parent, list()) # type: ignore

self.partID = 2
self.commandList = { 'Ignite' : 0 }

self.arduino.addCallback(self.partID, self.proccessCommand)

def proccessCommand(self, command : Command):
command.response_message = 'Ignited'

self.arduino.launchPhase = 'LiftOff'

def get_accepted_commands(self) -> list[Type[Command]]:
return [IgniteCommand]
Expand All @@ -60,24 +68,20 @@ def update(self, commands: Iterable[Command], now, iteration):

if c.state == 'received':
self.last_command = c
self.last_ignite_future = self.arduino.send_message(0x02, 0x01)
self.last_ignite_future = self.arduino.send_message(self.partID, self.commandList['Ignite'])
self.last_ignited = now
self.parachute_triggered = False

self.arduino.commandProccessingDict[self.last_ignite_future.result()] = c
c.state = 'processing'


if c.state == 'processing' and self.last_command != c:
c.state = 'failed'
c.response_message = 'Another ignite command was send, this command will no longer be processed'
continue

if c.state == 'processing' and self.last_ignite_future is not None and self.last_ignite_future.done():
exception = self.last_ignite_future.exception()
if exception is not None:
c.state = 'failed'
c.response_message = exception.args[0]
continue
c.state = 'success'
c.response_message = 'Igniter triggered'


else:
c.state = 'failed' # Part cannot handle this command
Expand All @@ -86,7 +90,7 @@ def update(self, commands: Iterable[Command], now, iteration):
if self.arduino is not None and self.last_ignited is not None and not self.parachute_triggered and (now - self.last_ignited) >= self.deploy_parachute_delay:

self.parachute_triggered = True
self.arduino.send_message(0x01, 0x04)
self.arduino.send_message(self.parachute.partID, self.parachute.commandList['Open'])


# def add_command_to_queue(command_code: int, payload):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@

from dataclasses import dataclass
from app.content.general_commands.enable import DisableCommand, EnableCommand
from app.content.motor_commands.open import OpenCommand, CloseCommand, IgniteCommand
from app.logic.commands.command import Command, Command
from app.content.general_commands.enable import DisableCommand, EnableCommand, ResetCommand
from app.content.motor_commands.open import OpenCommand, CloseCommand
from app.logic.commands.command import Command
from app.content.microcontroller.arduino_serial import ArduinoSerial
from app.logic.rocket_definition import Part, Rocket

from kivy.utils import platform


class ServoSensor(Part):
type = 'Servo'

enabled: bool = True

min_update_period = timedelta(milliseconds=20)
min_update_period = timedelta(milliseconds=200)

min_measurement_period = timedelta(milliseconds=1000)

Expand All @@ -31,15 +28,27 @@ class ServoSensor(Part):

last_command: Union[None, Command] = None

commandList : dict()

partID : chr

def __init__(self, _id: UUID, name: str, parent: Union[Part, Rocket, None], arduino_parent: Union[ArduinoSerial, None],start_enabled=True):
self.arduino = arduino_parent
self.enabled = start_enabled
self.state = 'close'
super().__init__(_id, name, parent, list()) # type: ignore

self.partID = 1
self.commandList = { 'Close' : 0, 'Open' : 1 }
self.arduino.addCallback(self.partID, self.proccessCommand)

def proccessCommand(self, command : Command):
command.response_message = 'Servo activated'

print("ssssssssss")

def get_accepted_commands(self) -> list[Type[Command]]:
return [OpenCommand, CloseCommand]
return [DisableCommand, EnableCommand, OpenCommand, CloseCommand]

def update(self, commands: Iterable[Command], now, iteration):

Expand All @@ -55,34 +64,35 @@ def update(self, commands: Iterable[Command], now, iteration):
c.response_message = 'Another ignite command was send, this command will no longer be processed'
continue

if c.state == 'processing' and self.last_ignite_future is not None and self.last_ignite_future.done():
exception = self.last_ignite_future.exception()
if exception is not None:
c.state = 'failed'
c.response_message = exception.args[0]
continue
c.state = 'success'
c.response_message = 'Servo actuated'
if c.state == 'processing':
print("jas")
continue



if isinstance(c, CloseCommand):

if c.state == 'received':
self.last_command = c
self.last_ignite_future = self.arduino.send_message(0x01, 0x03)
self.last_ignite_future = self.arduino.send_message(self.partID, self.commandList["Close"])

self.arduino.commandProccessingDict[self.last_ignite_future.result()] = c
c.state = 'processing'

elif isinstance(c, OpenCommand):

if c.state == 'received':
self.last_command = c
self.last_ignite_future = self.arduino.send_message(0x01, 0x04)
self.last_ignite_future = self.arduino.send_message(self.partID, self.commandList["Open"])

self.arduino.commandProccessingDict[self.last_ignite_future.result()] = c
c.state = 'processing'


else:
c.state = 'failed' # Part cannot handle this command
continue

# def add_command_to_queue(command_code: int, payload):

def get_measurement_shape(self) -> Iterable[Tuple[str, Type]]:
return [
Expand Down
Loading