Skip to content

Commit

Permalink
student's beep sat
Browse files Browse the repository at this point in the history
  • Loading branch information
maholli committed Jun 30, 2021
1 parent 4cc92e5 commit 7944850
Show file tree
Hide file tree
Showing 15 changed files with 1,644 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# For PCBs designed using KiCad: http://www.kicad-pcb.org/
# Format documentation: http://kicad-pcb.org/help/file-formats/

*/media/*

# Temporary files
*.000
*.bak
*.bck
*.kicad_pcb-bak
*.sch-bak
*~
_autosave-*
*.tmp
*-save.pro
*-save.kicad_pcb
fp-info-cache

# Netlist files (exported from Eeschema)
*.net

# Autorouter files (exported from Pcbnew)
*.dsn
*.ses

# Exported BOM files
*.xml
*.PNG

# CircuitPython drive files
*.fseventsd/
*.metadata_never_index
*.Trashes
*boot_out.txt
*.URL
sha.py
*secrets*

*.xlsx
16 changes: 16 additions & 0 deletions beep_sat/Tasks/imu_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Task to obtain IMU sensor readings

class Task:
def __init__(self, satellite):
self.cubesat = satellite

async def main_task(self):
reading = self.cubesat.IMU.gyro
print("Sending Gyro Readings....")
self.cubesat.radio2.send(','.join(map(str,reading)), keep_listening=True)
print("Done Sending Gyro Readings")

priority = 2
frequency = 1/10
task_id = 2
schedule_later=False
34 changes: 34 additions & 0 deletions beep_sat/Tasks/radio_receive_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Task to listen for "killswitch" command on Radio

import Tasks.stop_tasks as stop_tasks

class Task:
def __init__(self, satellite):
self.cubesat = satellite
self.include = True
self.cubesat.radio2.listen()

def __await__(self):

while self.cubesat.radio2.rx_done() == 0:
yield
message = self.cubesat.radio2.receive()
msg_text = str(message, "ascii")
if msg_text == "killswitch":
print("Sending message.....")
self.cubesat.radio2.send(
"Killswitch received, Bye World......", keep_listening=True
)

#Stop desired tasks
stop_tasks.StopTask(self.cubesat, 3, [1,2,3]).stop()

async def main_task(self):
print("Awaiting message")
await self
print("Done awaiting message")

priority = 1
frequency = 1
task_id = 1
schedule_later= False
16 changes: 16 additions & 0 deletions beep_sat/Tasks/radio_send_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Task to send "Hello World" on the radio

class Task:
def __init__(self, satellite):
self.cubesat = satellite

async def main_task(self):
print("Sending message from PyCubed....")
self.cubesat.radio2.send("Hello World!", keep_listening=True)
print("Message sent from PyCubed")

priority = 3
frequency = 1
task_id = 3
schedule_later=False

37 changes: 37 additions & 0 deletions beep_sat/Tasks/stop_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class StopTask:
"""
The StopTask object that is used to stop tasks from within a task.
"""
def __init__(self, satellite, num_of_tasks, task_ids):
"""
Initialise the StopTask object by regsitering the cubesat on it.
This is required to access the list of scheduled task objects from which
the appropriate tasks are stopped.
:type satellite: Satellite
:param satellite: The cubesat to be registered
:type num_of_tasks: int
:param num_of_tasks: The number of tasks to be stopped
:type task_ids: list of int
:param task_ids: A list containing the integer task_ids of the tasks to be stopped
"""
self.cubesat = satellite
self.num = num_of_tasks
self.task_id_list = task_ids
self.count = 0

def stop(self):
"""
Object method that is used to stop the tasks specified by the parameters provided during initialisation.
"""
for task in self.cubesat.scheduled_objects:
if task.get_task_id() in self.task_id_list:
task.stop()
self.count = self.count + 1
assert self.count == self.num, "Multiple tasks have the same task_id!"
43 changes: 43 additions & 0 deletions beep_sat/Tasks/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Task:

"""
The Task Object.
Attributes:
priority: The priority level assigned to the task.
frequency: Number of times the task must be executed in 1 second (Hz).
task_id: User defined task identifier.
schedule_later: If **True**, the task is scheduled after the first 'frequency' Hz interval.
"""

priority: int = 3
frequency: float = 1
task_id: int = 3
schedule_later: bool=False

def __init__(self, satellite):
"""
Initialise the Task by registering the cubesat object on it.
This is required to access the functionalities offered by the
PyCubed board.
:type satellite: Satellite
:param satellite: The cubesat to be registered
"""

self.cubesat = satellite

async def main_task(self, *args, **kwargs):
"""
Contains the code for the user defined task.
:param `*args`: Variable number of arguments used for task execution.
:param `**kwargs`: Variable number of keyword arguments used for task execution.
"""
print("Sending message from PyCubed....")
self.cubesat.radio2.send("Hello World!", keep_listening=True)
print("Message sent from PyCubed")


32 changes: 32 additions & 0 deletions beep_sat/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Import cubesat- Starting point of all programs

from pycubed import cubesat

import os
import sys

for f in os.listdir("Tasks"):
if f == "stop_tasks.py" or f=="task.py":
continue
str = "Tasks." + f[:-3]
obj = __import__(str, globals(), locals(), [], 0)
if obj.Task(cubesat).schedule_later == False:
cubesat.scheduled_objects.append(
cubesat.schedule(
obj.Task(cubesat).frequency,
obj.Task(cubesat).main_task,
obj.Task(cubesat).priority,
obj.Task(cubesat).task_id,
)
)
else:
cubesat.scheduled_objects.append(
cubesat.schedule_later(
obj.Task(cubesat).frequency,
obj.Task(cubesat).main_task,
obj.Task(cubesat).priority,
obj.Task(cubesat).task_id,
)
)

cubesat.run()
Loading

0 comments on commit 7944850

Please sign in to comment.