Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lucashicks1/Lambda-Deco3801
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvillr committed Oct 17, 2023
2 parents b4e35ec + ae8e91f commit 15f0226
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 77 deletions.
69 changes: 7 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,8 @@
# Lambda - Deco3801

# Hi Rosti 🪩 Please read!
We really wanted to have our READMEs finished for the snapshot so we could get your feedback on them but unfortunately we're all a bit slammed until the weekend and probably won't make it to them in time :(
We'll just do our best to finish it up & maybe ping you a lot until next studio instead. Hope that's okay! And sorry for the lack of good docs in most places at the moment.
*Promise* they'll be shipshape for the real submission.

## Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!

## Add your files

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:

```
cd existing_repo
git remote add origin https://github.com/lucashicks1/lambda-deco3801
git branch -M main
git push -uf origin main
```

## Integrate with your tools

- [ ] [Set up project integrations](https://gitlab.com/DylanFleming45313345/lambda-deco3801/-/settings/integrations)

## Collaborate with your team

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)

## Test and Deploy

Use the built-in continuous integration in GitLab.

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)

***

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
1. top-level explanation of product
2. overview of github directory structure
3. guide to getting started — order to build in and links to longer readmes for each section

## Name
Choose a self-explaining name for your project.
Expand All @@ -73,23 +23,18 @@ Within a particular ecosystem, there may be a common way of installing things, s
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
If you have any issues building or running this project yourself, please feel free to make a new issue for the team to address. You can also reach out to the project lead (Ali) at a.laherty@uq.edu.au. ***For access to the database credentials, please contact Lucas at l.hicks@uqconnect.edu.au, or if DECO3801 staff you may also refer to our technical report submission.***

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
!TODO what do we put here? I know we have lots of ideas, but this has to be 1-page so what makes it in?

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
Developed by Alex Viller, Lucas Hicks, David Jeong, Dylan Fleming, Maya Baxter, and Ali Laherty at the University of Queensland. Thanks to Rostislav Gusev for all the support.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
!TODO do we need to include this?
74 changes: 59 additions & 15 deletions build/figurines/microcontroller_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@

# =========================== IMPORTS ================================== #

import serial.tools.list_ports
import threading
import time
from time import sleep
import requests
import socket
from json import JSONDecodeError
import json
import logging

import serial.tools.list_ports
import requests
from serial import SerialException, SerialTimeoutException
# =========================== GLOBAL VALUES ================================== #

POLL_DELAY = 15
COM_PORT_PREFIX = "cu.usbmodem" # usbmodem1101 and usbmodem2101
MAX_CONNECTION_COUNT = 10

global connect_status, read_state, port, serialPort
global serial_count # Optimized counter, used to clear the serial input buffer
serial_count = 0
Expand All @@ -30,8 +33,8 @@

# =========================== SERIAL HANDLING ================================== #

logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s")
_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.DEBUG)

def initialise_serial(port):
global serialPort, connect_status
Expand Down Expand Up @@ -106,8 +109,11 @@ def check_presence(port, interval=0.01):


def start_thread():
"""Starts a thread that checks serial port presence"""
global port, connect_status
_LOGGER.info("Starting thread at port %s", port)
# target - callable object invoked by the start() or run() command
# args - arguments passed to check_presence command
port_controller = threading.Thread(target=check_presence, args=(port, 0.1))
port_controller.daemon = True
port_controller.start()
Expand All @@ -117,31 +123,69 @@ def start_thread():


def main():
"""Main script loop that will attempt to connect to the microcontroller.
If so, it will send data via serial to move the servo motors
"""

global port, connect_status
figurine_status = {}
# figurine_status = {}

connection_count = 0

while True:
if connection_count >= MAX_CONNECTION_COUNT:
_LOGGER.error("Could not find valid serial connection and timed out, try again")
return

if not connect_status:
port_device = None
port_device = None
ports = serial.tools.list_ports.comports()
for port in ports:
if COM_PORT_PREFIX in port.name:
_LOGGER.info("Trying port - %s", port.device)
if port.name is not None and COM_PORT_PREFIX in port.name:
port_device = port[0]
break
connection_count += 1
if port_device is not None:
initialise_serial(port_device)
start_thread()
try:
initialise_serial(port_device)
except ValueError as e:
_LOGGER.error("Parameter given is out of range")
_LOGGER.debug(e)
except SerialException as e:
# SerialException derives from IOError
_LOGGER.error("Device can not be found or configured")
_LOGGER.debug(e)

try:
start_thread()
except RuntimeError as e:
_LOGGER.error("start() method called more than once for same thread object")
_LOGGER.debug(e)

else:
connect_status = False
continue
if serialPort.is_open:
try:
response = json.loads(
requests.get('http://127.0.0.1:8000/figurines', timeout=5).text
)
if response != figurine_status:
figurine_status = response
send_to_controller(figurine_status)
response_body = requests.get('http://127.0.0.1:8000/figurines', timeout=5).text
if response_body is not None:
try:
response = json.loads(response_body)
except JSONDecodeError as e:
_LOGGER.error("Not valid JSON document")
_LOGGER.debug(e)
else:
_LOGGER.Error("Got nothing from the api")
continue
try:
send_to_controller(response)
except SerialTimeoutException as e:
_LOGGER.error("Write timeout")
_LOGGER.debug(e)
# if response != figurine_status:
# figurine_status = response
# send_to_controller(figurine_status)
sleep(POLL_DELAY)
except requests.exceptions.ConnectionError as e:
_LOGGER.info("Error making HTTP request")
Expand Down
1 change: 1 addition & 0 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dependencies:
- pymongo=4.5.0=py311ha891d26_1
- pyopenssl=23.2.0=py311hca03da5_0
- pyparsing=3.0.9=py311hca03da5_0
- pyserial=3.5=py311hca03da5_0
- pysocks=1.7.1=py311hca03da5_0
- pytesseract=0.3.10=py311hca03da5_0
- python=3.11.6=h47c9636_0_cpython
Expand Down

0 comments on commit 15f0226

Please sign in to comment.