diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml new file mode 100644 index 0000000..ddb5f8d --- /dev/null +++ b/.github/workflows/sphinx.yml @@ -0,0 +1,24 @@ +name: "Sphinx: Render docs" + +on: push + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Build HTML + uses: ammaraskar/sphinx-action@master + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: html-docs + path: docs/_build/html/ + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + if: github.ref == 'refs/heads/dev' + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/_build/html diff --git a/.gitignore b/.gitignore index 1cdd6a9..ea9d907 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ venv.bak/ **.freq frequency_analysis.json +**_build \ No newline at end of file diff --git a/CommandScripts/AutoHelp.py b/CommandScripts/AutoHelp.py index 3143e74..52508b3 100644 --- a/CommandScripts/AutoHelp.py +++ b/CommandScripts/AutoHelp.py @@ -1,6 +1,6 @@ import math #from modules.LSM303 import Compass -from modules.LSM303 import Compass +from proj_modules.LSM303 import Compass import json class AutoHelp: @@ -75,12 +75,15 @@ def jsonify_commands(self, commands): def get_bearing(self, current_GPS, target_GPS): - """Returns the angle between two GPS coordinates + """ + Returns the angle between two GPS coordinates + PARAMS: current_GPS (tuple): (latitude, longitude) target_GPS (tuple): (latitude, longitude) RETURNS: float. angle between the two coordinates + """ try: current_latitude = math.radians(current_GPS[1]) diff --git a/CommandScripts/GPS_NAV.py b/CommandScripts/GPS_NAV.py index 82c6d2a..9ae4436 100644 --- a/CommandScripts/GPS_NAV.py +++ b/CommandScripts/GPS_NAV.py @@ -2,7 +2,7 @@ import os, sys sys.path.insert(0, os.path.abspath("..")) -from modules.LSM303 import Compass +from proj_modules.LSM303 import Compass from CommandScripts import AutoHelp from simple_pid import PID import time @@ -19,6 +19,7 @@ def get_target_angle( self, lidar_data, rover_angle, current_longlat, target_longlat ): """Obstacle avoidance logic that uses vector field histogram (VFH) + PARAMS: lidar_data (list): array of 360 elements. each index is an angle rover_angle (int): the angle that the rover is currently facing diff --git a/CommandScripts/MMT-drive-command.py b/CommandScripts/MMT-drive-command.py deleted file mode 100644 index d024c91..0000000 --- a/CommandScripts/MMT-drive-command.py +++ /dev/null @@ -1,25 +0,0 @@ -import sys -import requests -import serial.tools.list_ports as port_list -import os, sys -sys.path.insert(0, os.path.abspath("..")) -from modules.Serial import SerialSystem - -port = "/dev/ttyUSB0" -get_initial_commands_url = "http://192.168.1.133:5000/drive" - -web_response = requests.get(get_initial_commands_url) -print("Getting data from: " + web_response.text) - -try: - serial = SerialSystem(port, 38400) - print("Using port: " + port) -except: - ports = list(port_list.comports()) - print('====> Designated Port not found. Using Port:', ports[0].device) - port = ports[0].device - serial = SerialSystem(port, 38400) - -while True: - web_response = requests.get(get_initial_commands_url) - serial.read_write_serial(web_response.text) \ No newline at end of file diff --git a/CommandScripts/MMT_drive_command.py b/CommandScripts/MMT_drive_command.py new file mode 100644 index 0000000..9121d49 --- /dev/null +++ b/CommandScripts/MMT_drive_command.py @@ -0,0 +1,26 @@ +import sys +import requests +import serial.tools.list_ports as port_list +import os, sys +sys.path.insert(0, os.path.abspath("..")) +from proj_modules.Serial import SerialSystem + +if __name__=='__main__': + port = "/dev/ttyUSB0" + get_initial_commands_url = "http://192.168.1.133:5000/drive" + + web_response = requests.get(get_initial_commands_url) + print("Getting data from: " + web_response.text) + + try: + serial = SerialSystem(port, 38400) + print("Using port: " + port) + except: + ports = list(port_list.comports()) + print('====> Designated Port not found. Using Port:', ports[0].device) + port = ports[0].device + serial = SerialSystem(port, 38400) + + while True: + web_response = requests.get(get_initial_commands_url) + serial.read_write_serial(web_response.text) \ No newline at end of file diff --git a/CommandScripts/autonomy.py b/CommandScripts/autonomy.py index 713c84c..7ccc58a 100644 --- a/CommandScripts/autonomy.py +++ b/CommandScripts/autonomy.py @@ -7,8 +7,8 @@ sys.path.insert(0, os.path.abspath("..")) from CommandScripts.GPS_NAV import GPS_Nav from CommandScripts import AutoHelp -from modules.LSM303 import Compass -from modules.WiFi import WiFi +from proj_modules.LSM303 import Compass +from proj_modules.WiFi import WiFi import time import threading diff --git a/CommandScripts/drive-command.py b/CommandScripts/drive-command.py deleted file mode 100644 index 37e7838..0000000 --- a/CommandScripts/drive-command.py +++ /dev/null @@ -1,30 +0,0 @@ -import sys -import requests -import serial.tools.list_ports as port_list -import os, sys -sys.path.insert(0, os.path.abspath("..")) -from modules.Serial import SerialSystem - -port = "/dev/ttyUSB0" -get_initial_commands_url = "http://192.168.50.243:5000/drive" - -web_response = requests.get(get_initial_commands_url) -print("Getting data from: " + web_response.text) - -try: - serial = SerialSystem(port, 38400) - print("Using port: " + port) -except: - ports = list(port_list.comports()) - print('====> Designated Port not found. Using Port:', ports[0].device) - port = ports[0].device - serial = SerialSystem(port, 38400) - -homing_end = "Starting control loop..." -while True: - response = serial.read_serial() - if homing_end in response: - while True: - web_response = requests.get(get_initial_commands_url) - serial.read_write_serial(web_response.text) - \ No newline at end of file diff --git a/CommandScripts/drive_command.py b/CommandScripts/drive_command.py new file mode 100644 index 0000000..91c8f08 --- /dev/null +++ b/CommandScripts/drive_command.py @@ -0,0 +1,31 @@ +import sys +import requests +import serial.tools.list_ports as port_list +import os, sys +sys.path.insert(0, os.path.abspath("..")) +from proj_modules.Serial import SerialSystem + +if __name__=='__main__': + port = "/dev/ttyUSB0" + get_initial_commands_url = "http://192.168.50.243:5000/drive" + + web_response = requests.get(get_initial_commands_url) + print("Getting data from: " + web_response.text) + + try: + serial = SerialSystem(port, 38400) + print("Using port: " + port) + except: + ports = list(port_list.comports()) + print('====> Designated Port not found. Using Port:', ports[0].device) + port = ports[0].device + serial = SerialSystem(port, 38400) + + homing_end = "Starting control loop..." + while True: + response = serial.read_serial() + if homing_end in response: + while True: + web_response = requests.get(get_initial_commands_url) + serial.read_write_serial(web_response.text) + \ No newline at end of file diff --git a/Missions/MMT_testing.py b/Missions/MMT_testing.py index 3b0fad8..9391506 100644 --- a/Missions/MMT_testing.py +++ b/Missions/MMT_testing.py @@ -2,9 +2,9 @@ sys.path.insert(0, os.path.abspath("..")) import requests import serial.tools.list_ports as port_list -from modules.Serial import SerialSystem +from proj_modules.Serial import SerialSystem from CommandScripts.autonomy import Autonomy -from modules.old_GPS import gpsRead +from proj_modules.old_GPS import gpsRead import json serial_port = "/dev/ttyACM2" @@ -16,51 +16,52 @@ server = 'http://13.56.207.97:5000' GPS_list = [] -try: - serial = SerialSystem(serial_port, serial_baudrate) - print("Using port: " + serial_port, "For Serial Comms") -except: - ports = list(port_list.comports()) - print('====> Designated Port not found. Using Port:', ports[0].device, "For Serial Connection") - serial_port = ports[0].device - serial = SerialSystem(serial_port, serial_baudrate) +if __name__=='__main__': + try: + serial = SerialSystem(serial_port, serial_baudrate) + print("Using port: " + serial_port, "For Serial Comms") + except: + ports = list(port_list.comports()) + print('====> Designated Port not found. Using Port:', ports[0].device, "For Serial Connection") + serial_port = ports[0].device + serial = SerialSystem(serial_port, serial_baudrate) -try: - GPS = gpsRead(gps_port,gps_baudrate) - print("Using port: " + gps_port, "For GPS") -except: - port_number = 0 - ports = list(port_list.comports()) - print('====> Designated Port not found. Using Port:', ports[port_number].device, "For GPS Connection") - port = ports[port_number].device - GPS = gpsRead(port,gps_baudrate) - while GPS.get_position() == ['error', 'error'] or GPS.get_position() == ["None", "None"]: - print("Port not found, going to next port...") - port_number += 1 - gps_port = ports[port_number].device - try: - GPS = gpsRead(port,gps_baudrate) - except: - continue - break + try: + GPS = gpsRead(gps_port,gps_baudrate) + print("Using port: " + gps_port, "For GPS") + except: + port_number = 0 + ports = list(port_list.comports()) + print('====> Designated Port not found. Using Port:', ports[port_number].device, "For GPS Connection") + port = ports[port_number].device + GPS = gpsRead(port,gps_baudrate) + while GPS.get_position() == ['error', 'error'] or GPS.get_position() == ["None", "None"]: + print("Port not found, going to next port...") + port_number += 1 + gps_port = ports[port_number].device + try: + GPS = gpsRead(port,gps_baudrate) + except: + continue + break -GPS_map_url = f"{server}/gps" -try: - GPS_map = requests.get(GPS_map_url) -except: - print("Could not get GPS map from mission control") - exit(1) + GPS_map_url = f"{server}/gps" + try: + GPS_map = requests.get(GPS_map_url) + except: + print("Could not get GPS map from mission control") + exit(1) -GPS_map = json.loads(GPS_map.text) + GPS_map = json.loads(GPS_map.text) -for i in GPS_map: - GPS_list.append(GPS_map[i]) -print("GPS List:", GPS_list) + for i in GPS_map: + GPS_list.append(GPS_map[i]) + print("GPS List:", GPS_list) -GPS_list = [[-121.8818685, 37.33699716666666], [-121.881868, 37.33696233333334], [-121.88177050000002, 37.336928833333324]] -print("GPS List:", GPS_list) + GPS_list = [[-121.8818685, 37.33699716666666], [-121.881868, 37.33696233333334], [-121.88177050000002, 37.336928833333324]] + print("GPS List:", GPS_list) -rover = Autonomy(serial, server, max_speed, max_angle, GPS, GPS_list) -rover.start_mission() + rover = Autonomy(serial, server, max_speed, max_angle, GPS, GPS_list) + rover.start_mission() diff --git a/modules/__init__.py b/Missions/__init__.py similarity index 100% rename from modules/__init__.py rename to Missions/__init__.py diff --git a/Missions/drive.py b/Missions/drive.py index 17f5a1f..a7e423c 100644 --- a/Missions/drive.py +++ b/Missions/drive.py @@ -3,9 +3,9 @@ sys.path.insert(0, os.path.abspath("..")) import requests import serial.tools.list_ports as port_list -from modules.WiFi import WiFi +from proj_modules.WiFi import WiFi from CommandScripts.autonomy import Autonomy -from modules.GPS import gpsRead +from proj_modules.GPS import gpsRead import json import time @@ -20,64 +20,65 @@ rover_comms = WiFi(server) -try: - GPS = gpsRead(gps_port, gps_baudrate) - print("Using port: " + gps_port, "For GPS") -except: - port_number = 0 - ports = list(port_list.comports()) - print( - "====> Designated Port not found. Using Port:", - ports[port_number].device, - "For GPS Connection", - ) - port = ports[port_number].device - GPS = gpsRead(port, gps_baudrate) - while GPS.get_position() == ["error", "error"] or GPS.get_position() == [ - "None", - "None", - ]: - print("Port not found, going to next port...") - port_number += 1 - gps_port = ports[port_number].device - try: - GPS = gpsRead(port, gps_baudrate) - except: - continue - break +if __name__=='__main__': + try: + GPS = gpsRead(gps_port, gps_baudrate) + print("Using port: " + gps_port, "For GPS") + except: + port_number = 0 + ports = list(port_list.comports()) + print( + "====> Designated Port not found. Using Port:", + ports[port_number].device, + "For GPS Connection", + ) + port = ports[port_number].device + GPS = gpsRead(port, gps_baudrate) + while GPS.get_position() == ["error", "error"] or GPS.get_position() == [ + "None", + "None", + ]: + print("Port not found, going to next port...") + port_number += 1 + gps_port = ports[port_number].device + try: + GPS = gpsRead(port, gps_baudrate) + except: + continue + break -# GPS_map_url = f"{server}/gps_map" -# try: -# GPS_map = requests.get(GPS_map_url) -# except: -# print("Could not get GPS map from mission control") -# exit(1) + # GPS_map_url = f"{server}/gps_map" + # try: + # GPS_map = requests.get(GPS_map_url) + # except: + # print("Could not get GPS map from mission control") + # exit(1) -# GPS_map = json.loads(GPS_map.text) + # GPS_map = json.loads(GPS_map.text) -# for i in GPS_map: -# GPS_list.append(GPS_map[i]) + # for i in GPS_map: + # GPS_list.append(GPS_map[i]) -GPS_list = [ - [-121.8818545, 37.3370768], - [-121.8818535, 37.3370083], - [-121.8817744, 37.3369864], -] -print("GPS List:", GPS_list) + GPS_list = [ + [-121.8818545, 37.3370768], + [-121.8818535, 37.3370083], + [-121.8817744, 37.3369864], + ] + print("GPS List:", GPS_list) -try: - rover = Autonomy(rover_comms, server, max_speed, max_angle, GPS, GPS_list) + try: + rover = Autonomy(rover_comms, server, max_speed, max_angle, GPS, GPS_list) - # start mission - you need to control c your program - rover.start_mission() -except KeyboardInterrupt: - print("stopping...") -except Exception as e: - raise -finally: - rover.rover_comms.write_data( - {"HB": 0, "IO": 1, "WO": 0, "DM": "D", "CMD": [0, 0], "LS": 3} - ) - print("finished stopping") - quit() + # start mission - you need to control c your program + rover.start_mission() + except KeyboardInterrupt: + print("stopping...") + except Exception as e: + raise + finally: + rover.rover_comms.write_data( + {"HB": 0, "IO": 1, "WO": 0, "DM": "D", "CMD": [0, 0], "LS": 3} + ) + print("finished stopping") + quit() diff --git a/Vision/__init__.py b/Vision/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Vision/depthai-examples/__init.py b/Vision/depthai-examples/__init.py new file mode 100644 index 0000000..e69de29 diff --git a/Vision/depthai-examples/gen2-box_measurement/__init__.py b/Vision/depthai-examples/gen2-box_measurement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Vision/proj_modules/__init__.py b/Vision/proj_modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Vision/modules/camera-test.py b/Vision/proj_modules/camera-test.py similarity index 100% rename from Vision/modules/camera-test.py rename to Vision/proj_modules/camera-test.py diff --git a/Vision/modules/object-width.py b/Vision/proj_modules/object-width.py similarity index 100% rename from Vision/modules/object-width.py rename to Vision/proj_modules/object-width.py diff --git a/Vision/modules/stereo-vision-test.py b/Vision/proj_modules/stereo-vision-test.py similarity index 100% rename from Vision/modules/stereo-vision-test.py rename to Vision/proj_modules/stereo-vision-test.py diff --git a/demos/Compass/run.py b/demos/Compass/run.py index 01b6e5a..6005665 100644 --- a/demos/Compass/run.py +++ b/demos/Compass/run.py @@ -1,7 +1,7 @@ import sys import time sys.path.append( '../../') -from modules.LSM303 import Compass +from proj_modules.LSM303 import Compass if __name__ == '__main__': try: diff --git a/demos/GPS-demo/run.py b/demos/GPS-demo/run.py index eadf2e4..e66a119 100644 --- a/demos/GPS-demo/run.py +++ b/demos/GPS-demo/run.py @@ -3,7 +3,7 @@ import time import serial.tools.list_ports as port_list sys.path.append("../../") -from modules.GPS import gpsRead +from proj_modules.GPS import gpsRead if __name__ == '__main__': try: diff --git a/demos/IR_Sensor-demo/run.py b/demos/IR_Sensor-demo/run.py index 775fa9e..f7e4aba 100644 --- a/demos/IR_Sensor-demo/run.py +++ b/demos/IR_Sensor-demo/run.py @@ -1,7 +1,7 @@ import sys sys.path.append( '../../') import time -from modules.IR_Sensor import IR_Sensor +from proj_modules.IR_Sensor import IR_Sensor sensor = 12 rover_detection = IR_Sensor(sensor) diff --git a/demos/MPU6050-demo/run.py b/demos/MPU6050-demo/run.py index 3db2386..6cc4c7d 100644 --- a/demos/MPU6050-demo/run.py +++ b/demos/MPU6050-demo/run.py @@ -1,6 +1,6 @@ import sys sys.path.append( '../../') -from modules.MPU6050 import MPU6050 +from proj_modules.MPU6050 import MPU6050 mpu = MPU6050() mpu.read_data() \ No newline at end of file diff --git a/demos/Serial-demo/run.py b/demos/Serial-demo/run.py index e5ed5f5..86c733b 100644 --- a/demos/Serial-demo/run.py +++ b/demos/Serial-demo/run.py @@ -1,7 +1,7 @@ import sys import serial.tools.list_ports as port_list sys.path.append( '../../') -from modules.Serial import SerialSystem +from proj_modules.Serial import SerialSystem import json port = "/dev/ttyACM2" diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/CommandScripts.rst b/docs/CommandScripts.rst new file mode 100644 index 0000000..23f7095 --- /dev/null +++ b/docs/CommandScripts.rst @@ -0,0 +1,61 @@ +CommandScripts package +====================== + +Submodules +---------- + +CommandScripts.AutoHelp module +------------------------------ + +.. automodule:: CommandScripts.AutoHelp + :members: + :undoc-members: + :show-inheritance: + +CommandScripts.GPS\_NAV module +------------------------------ + +.. automodule:: CommandScripts.GPS_NAV + :members: + :undoc-members: + :show-inheritance: + +CommandScripts.MMT\_drive\_command module +----------------------------------------- + +.. automodule:: CommandScripts.MMT_drive_command + :members: + :undoc-members: + :show-inheritance: + +CommandScripts.Trajectory module +-------------------------------- + +.. automodule:: CommandScripts.Trajectory + :members: + :undoc-members: + :show-inheritance: + +CommandScripts.autonomy module +------------------------------ + +.. automodule:: CommandScripts.autonomy + :members: + :undoc-members: + :show-inheritance: + +CommandScripts.drive\_command module +------------------------------------ + +.. automodule:: CommandScripts.drive_command + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: CommandScripts + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/Missions.rst b/docs/Missions.rst new file mode 100644 index 0000000..386dda8 --- /dev/null +++ b/docs/Missions.rst @@ -0,0 +1,29 @@ +Missions package +================ + +Submodules +---------- + +Missions.MMT\_testing module +---------------------------- + +.. automodule:: Missions.MMT_testing + :members: + :undoc-members: + :show-inheritance: + +Missions.drive module +--------------------- + +.. automodule:: Missions.drive + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: Missions + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/Vision.proj_modules.rst b/docs/Vision.proj_modules.rst new file mode 100644 index 0000000..f7fb7f1 --- /dev/null +++ b/docs/Vision.proj_modules.rst @@ -0,0 +1,37 @@ +Vision.proj\_modules package +============================ + +Submodules +---------- + +Vision.proj\_modules.camera\-test module +---------------------------------------- + +.. automodule:: Vision.proj_modules.camera-test + :members: + :undoc-members: + :show-inheritance: + +Vision.proj\_modules.object\-width module +----------------------------------------- + +.. automodule:: Vision.proj_modules.object-width + :members: + :undoc-members: + :show-inheritance: + +Vision.proj\_modules.stereo\-vision\-test module +------------------------------------------------ + +.. automodule:: Vision.proj_modules.stereo-vision-test + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: Vision.proj_modules + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/Vision.rst b/docs/Vision.rst new file mode 100644 index 0000000..a5e1fd7 --- /dev/null +++ b/docs/Vision.rst @@ -0,0 +1,18 @@ +Vision package +============== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + Vision.proj_modules + +Module contents +--------------- + +.. automodule:: Vision + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..60da475 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,33 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup ---------------------------------------------- +import os +import sys +sys.path.insert(0, '..') + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'Autonomy@SJSU-Robotics' +copyright = '2024, Rahul' +author = 'Rahul' +release = '0.1.0' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = ['sphinx.ext.autodoc'] + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'sphinx_rtd_theme' +html_static_path = ['_static'] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..e68b0a4 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,24 @@ +.. Autonomy@SJSU-Robotics documentation master file, created by + sphinx-quickstart on Sat Mar 23 20:26:36 2024. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Autonomy@SJSU-Robotics's documentation! +================================================== + +Hi Welcome to documentation + +.. toctree:: + :maxdepth: 10 + :caption: Contents: + + modules + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/modules.rst b/docs/modules.rst new file mode 100644 index 0000000..c7e07d1 --- /dev/null +++ b/docs/modules.rst @@ -0,0 +1,11 @@ +autonomy_setup_test +=================== + +.. toctree:: + :maxdepth: 4 + + CommandScripts + Missions + Vision + proj_modules + unified_frameworks diff --git a/docs/proj_modules.rst b/docs/proj_modules.rst new file mode 100644 index 0000000..3a0591e --- /dev/null +++ b/docs/proj_modules.rst @@ -0,0 +1,69 @@ +proj\_modules package +===================== + +Submodules +---------- + +proj\_modules.GPS module +------------------------ + +.. automodule:: proj_modules.GPS + :members: + :undoc-members: + :show-inheritance: + +proj\_modules.IR\_Sensor module +------------------------------- + +.. automodule:: proj_modules.IR_Sensor + :members: + :undoc-members: + :show-inheritance: + +proj\_modules.LSM303 module +--------------------------- + +.. automodule:: proj_modules.LSM303 + :members: + :undoc-members: + :show-inheritance: + +proj\_modules.MPU6050 module +---------------------------- + +.. automodule:: proj_modules.MPU6050 + :members: + :undoc-members: + :show-inheritance: + +proj\_modules.Serial module +--------------------------- + +.. automodule:: proj_modules.Serial + :members: + :undoc-members: + :show-inheritance: + +proj\_modules.WiFi module +------------------------- + +.. automodule:: proj_modules.WiFi + :members: + :undoc-members: + :show-inheritance: + +proj\_modules.old\_GPS module +----------------------------- + +.. automodule:: proj_modules.old_GPS + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: proj_modules + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..84269a4 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,8 @@ +docutils==0.20.1 +sphinx-rtd-theme +numpy +matplotlib +shapely +requests +rplidar-roboticia +websockets \ No newline at end of file diff --git a/docs/unified_frameworks.bridge.rst b/docs/unified_frameworks.bridge.rst new file mode 100644 index 0000000..1a7f619 --- /dev/null +++ b/docs/unified_frameworks.bridge.rst @@ -0,0 +1,45 @@ +unified\_frameworks.bridge package +================================== + +Submodules +---------- + +unified\_frameworks.bridge.acync\_demos module +---------------------------------------------- + +.. automodule:: unified_frameworks.bridge.acync_demos + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.bridge.client\_side module +---------------------------------------------- + +.. automodule:: unified_frameworks.bridge.client_side + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.bridge.exceptions module +-------------------------------------------- + +.. automodule:: unified_frameworks.bridge.exceptions + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.bridge.rover\_side module +--------------------------------------------- + +.. automodule:: unified_frameworks.bridge.rover_side + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: unified_frameworks.bridge + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/unified_frameworks.rst b/docs/unified_frameworks.rst new file mode 100644 index 0000000..712de85 --- /dev/null +++ b/docs/unified_frameworks.rst @@ -0,0 +1,102 @@ +unified\_frameworks package +=========================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + unified_frameworks.bridge + unified_frameworks.sensor_array + +Submodules +---------- + +unified\_frameworks.NavigatorClass module +----------------------------------------- + +.. automodule:: unified_frameworks.NavigatorClass + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.a\_star\_navigator module +--------------------------------------------- + +.. automodule:: unified_frameworks.a_star_navigator + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.captain module +---------------------------------- + +.. automodule:: unified_frameworks.captain + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.pathfinder module +------------------------------------- + +.. automodule:: unified_frameworks.pathfinder + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.pathfinder\_visualizer module +------------------------------------------------- + +.. automodule:: unified_frameworks.pathfinder_visualizer + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.rapid\_random\_tree module +---------------------------------------------- + +.. automodule:: unified_frameworks.rapid_random_tree + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.straight\_shot module +----------------------------------------- + +.. automodule:: unified_frameworks.straight_shot + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.unified\_utils module +----------------------------------------- + +.. automodule:: unified_frameworks.unified_utils + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.worldview module +------------------------------------ + +.. automodule:: unified_frameworks.worldview + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.worldview\_visualizer module +------------------------------------------------ + +.. automodule:: unified_frameworks.worldview_visualizer + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: unified_frameworks + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/unified_frameworks.sensor_array.gps_compass.rst b/docs/unified_frameworks.sensor_array.gps_compass.rst new file mode 100644 index 0000000..82e267e --- /dev/null +++ b/docs/unified_frameworks.sensor_array.gps_compass.rst @@ -0,0 +1,53 @@ +unified\_frameworks.sensor\_array.gps\_compass package +====================================================== + +Submodules +---------- + +unified\_frameworks.sensor\_array.gps\_compass.actual\_gps\_compass module +-------------------------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.gps_compass.actual_gps_compass + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.gps\_compass.fake\_gps\_compass module +------------------------------------------------------------------------ + +.. automodule:: unified_frameworks.sensor_array.gps_compass.fake_gps_compass + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.gps\_compass.gps\_compass module +------------------------------------------------------------------ + +.. automodule:: unified_frameworks.sensor_array.gps_compass.gps_compass + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.gps\_compass.gps\_compass\_class module +------------------------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.gps_compass.gps_compass_class + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.gps\_compass.wireless\_gps\_compass module +---------------------------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.gps_compass.wireless_gps_compass + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: unified_frameworks.sensor_array.gps_compass + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/unified_frameworks.sensor_array.rst b/docs/unified_frameworks.sensor_array.rst new file mode 100644 index 0000000..87f2840 --- /dev/null +++ b/docs/unified_frameworks.sensor_array.rst @@ -0,0 +1,133 @@ +unified\_frameworks.sensor\_array package +========================================= + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + unified_frameworks.sensor_array.gps_compass + +Submodules +---------- + +unified\_frameworks.sensor\_array.LidarClass module +--------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.LidarClass + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.actual\_gps\_test module +---------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.actual_gps_test + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.actual\_lidar module +------------------------------------------------------ + +.. automodule:: unified_frameworks.sensor_array.actual_lidar + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.bridge\_gps module +---------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.bridge_gps + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.bridge\_lidar module +------------------------------------------------------ + +.. automodule:: unified_frameworks.sensor_array.bridge_lidar + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.client\_bridge\_lidar module +-------------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.client_bridge_lidar + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.client\_lidar module +------------------------------------------------------ + +.. automodule:: unified_frameworks.sensor_array.client_lidar + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.fake\_lidar module +---------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.fake_lidar + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.lidar module +---------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.lidar + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.lidar\_visualizer module +---------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.lidar_visualizer + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.server\_gps module +---------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.server_gps + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.server\_lidar module +------------------------------------------------------ + +.. automodule:: unified_frameworks.sensor_array.server_lidar + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.websocket\_client module +---------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.websocket_client + :members: + :undoc-members: + :show-inheritance: + +unified\_frameworks.sensor\_array.websocket\_server module +---------------------------------------------------------- + +.. automodule:: unified_frameworks.sensor_array.websocket_server + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: unified_frameworks.sensor_array + :members: + :undoc-members: + :show-inheritance: diff --git a/env_files/all_requirements.txt b/env_files/all_requirements.txt index d3cc44a..8e3ad89 100644 --- a/env_files/all_requirements.txt +++ b/env_files/all_requirements.txt @@ -9,4 +9,11 @@ jupyterlab voila rplidar-roboticia pyqt6 -websockets \ No newline at end of file +websockets +Sphinx +sphinx-rtd-theme +board +adafruit-circuitpython-lsm303dlh-mag +simple-pid +RPi.GPIO +smbus \ No newline at end of file diff --git a/modules/GPS.py b/proj_modules/GPS.py similarity index 100% rename from modules/GPS.py rename to proj_modules/GPS.py diff --git a/modules/IR_Sensor.py b/proj_modules/IR_Sensor.py similarity index 100% rename from modules/IR_Sensor.py rename to proj_modules/IR_Sensor.py diff --git a/modules/LSM303.py b/proj_modules/LSM303.py similarity index 100% rename from modules/LSM303.py rename to proj_modules/LSM303.py diff --git a/modules/MPU6050.py b/proj_modules/MPU6050.py similarity index 100% rename from modules/MPU6050.py rename to proj_modules/MPU6050.py diff --git a/modules/Serial.py b/proj_modules/Serial.py similarity index 100% rename from modules/Serial.py rename to proj_modules/Serial.py diff --git a/modules/WiFi.py b/proj_modules/WiFi.py similarity index 91% rename from modules/WiFi.py rename to proj_modules/WiFi.py index 40b1d65..c68c97c 100644 --- a/modules/WiFi.py +++ b/proj_modules/WiFi.py @@ -9,6 +9,7 @@ def __init__(self, address_url): def read_data(self, max_retries=3, wait_time=1): """Gets data from mission control. Expected response: {"HB":int, "IO":int, "WO":int, "DM":char, "CMD":list} + PARAMS: max_retries [int]: max number of requests we send to web server before giving up RETURNS: @@ -31,6 +32,7 @@ def read_data(self, max_retries=3, wait_time=1): def write_data(self, data): """Sends data to mission control using an http post request + PARAMS: data [dict]: something RETURNS: @@ -49,6 +51,7 @@ def send_command(self, data): self.write_data(data) def get_status(self, max_retries=3, wait_time=1): """Gets data from mission control. Expected response: {"HB":int, "IO":int, "WO":int, "DM":char, "CMD":list} + PARAMS: max_retries [int]: max number of requests we send to web server before giving up RETURNS: @@ -77,13 +80,15 @@ def make_drive_command(mode=None, speed_percent=None, angle_degrees=None): Parameters ---------- - mode: Specify the mode in which to interpret command - D: Drive, S: Spin, T: Translate - Default to "D" - speed_percent: Specify the speed as a % of max speed. Can be +- - angle_degree: Specify angle the rover should deviate by - Look forward to this parameter being modified in the future - """ + mode: str + Specify the mode in which to interpret command + D: Drive, S: Spin, T: Translate + Default to "D" + speed_percent: int + Specify the speed as a % of max speed. Can be +- + angle_degree: int + Specify angle the rover should deviate by + Look forward to this parameter being modified in the future""" command = { "HB": 0, # Heart Beat "IO": 1, # Is Operational diff --git a/proj_modules/__init__.py b/proj_modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/old_GPS.py b/proj_modules/old_GPS.py similarity index 100% rename from modules/old_GPS.py rename to proj_modules/old_GPS.py diff --git a/unified_frameworks/__init__.py b/unified_frameworks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unified_frameworks/a_star_navigator.py b/unified_frameworks/a_star_navigator.py index 53d5e32..77358ac 100644 --- a/unified_frameworks/a_star_navigator.py +++ b/unified_frameworks/a_star_navigator.py @@ -1,3 +1,13 @@ +""" +This is a navigator that implementes an A* stearch in a continous space +to find a path from the current position to the destination position +bla bla bla + +""" +import sys +import re +root = (next(re.finditer(".*unified_frameworks", __file__)).group()) +sys.path.append(root) if root not in sys.path else None from numpy import ndarray from NavigatorClass import Navigator from math import pi diff --git a/unified_frameworks/bridge/__init__.py b/unified_frameworks/bridge/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unified_frameworks/captain.py b/unified_frameworks/captain.py index aec7a14..5084c1e 100644 --- a/unified_frameworks/captain.py +++ b/unified_frameworks/captain.py @@ -1,15 +1,19 @@ """This script is responsible for taking in the path from pathfinder and determining a command to send to the rover""" +import sys +import re +root = (next(re.finditer(".*unified_frameworks", __file__)).group()) +sys.path.append(root) if root not in sys.path else None from math import pi from unified_utils import Service import sys, os try: - from modules.WiFi import WiFi, make_drive_command, Modes + from proj_modules.WiFi import WiFi, make_drive_command, Modes except: sys.path.append(os.path.realpath(__file__ + os.sep + ".." + os.sep + "..")) - from modules.WiFi import WiFi, make_drive_command, Modes + from proj_modules.WiFi import WiFi, make_drive_command, Modes from unified_frameworks.sensor_array.gps_compass import gps_compass import pathfinder_visualizer import time diff --git a/unified_frameworks/pathfinder.py b/unified_frameworks/pathfinder.py index 30c5774..635ca4d 100644 --- a/unified_frameworks/pathfinder.py +++ b/unified_frameworks/pathfinder.py @@ -4,16 +4,17 @@ Thoughts on further development -- Currently this limits charting by number of iterations, make it so that its - always charting a route and only resets the obstacles every once in a while. -- Update get neighbors to get neighbors with realistic constraints, like no - sharp turns +- Currently this limits charting by number of iterations, make it so that its always charting a route and only resets the obstacles every once in a while. +- Update get neighbors to get neighbors with realistic constraints, like no sharp turns - Update cost function to have higher cost for points near obstacles. -- ^this can be used to create a potential field, and that potential field could be - used to update an existing path for a new environment instead of invalidating it - due to a new environment +- ^this can be used to create a potential field, and that potential field could be used to update an existing path for a new environment instead of invalidating it due to a new environment + """ +import sys +import re +root = (next(re.finditer(".*unified_frameworks", __file__)).group()) +sys.path.append(root) if root not in sys.path else None import worldview import importlib importlib.reload(worldview) diff --git a/unified_frameworks/sensor_array/__init__.py b/unified_frameworks/sensor_array/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unified_frameworks/sensor_array/actual_gps_test.py b/unified_frameworks/sensor_array/actual_gps_test.py index 33ea860..e2a97b3 100644 --- a/unified_frameworks/sensor_array/actual_gps_test.py +++ b/unified_frameworks/sensor_array/actual_gps_test.py @@ -1,9 +1,15 @@ +import sys +import re +root = (next(re.finditer(".*sensor_array", __file__)).group()) +sys.path.append(root) if root not in sys.path else None from gps_compass.actual_gps_compass import ActualGPSCompass import time -gps = ActualGPSCompass() -try: - while 1: - print(gps.get_cur_gps(), gps.get_cur_angle()) - time.sleep(1) -except KeyboardInterrupt: - gps.disconnect() + +if __name__=='__main__': + gps = ActualGPSCompass() + try: + while 1: + print(gps.get_cur_gps(), gps.get_cur_angle()) + time.sleep(1) + except KeyboardInterrupt: + gps.disconnect() diff --git a/unified_frameworks/sensor_array/gps_compass/__init__.py b/unified_frameworks/sensor_array/gps_compass/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unified_frameworks/sensor_array/gps_compass/actual_gps_compass.py b/unified_frameworks/sensor_array/gps_compass/actual_gps_compass.py index c810b7a..5c5df89 100644 --- a/unified_frameworks/sensor_array/gps_compass/actual_gps_compass.py +++ b/unified_frameworks/sensor_array/gps_compass/actual_gps_compass.py @@ -3,12 +3,15 @@ import sys import serial.tools.list_ports as port_list -root = __file__[: __file__.index("\\unified_frameworks")] -sys.path.append(root + "\\modules") + +import sys +import re +root = (next(re.finditer(".*unified_frameworks", __file__)).group()) +sys.path.append(root) if root not in sys.path else None # import from modules -import GPS -import LSM303 +import proj_modules.GPS +import proj_modules.LSM303 class ActualGPSCompass(GPSCompass): diff --git a/unified_frameworks/sensor_array/gps_compass/gps_compass_class.py b/unified_frameworks/sensor_array/gps_compass/gps_compass_class.py index f364961..534d2a1 100644 --- a/unified_frameworks/sensor_array/gps_compass/gps_compass_class.py +++ b/unified_frameworks/sensor_array/gps_compass/gps_compass_class.py @@ -43,11 +43,13 @@ def get_distance( def get_bearing(current_GPS, target_GPS): """Returns the angle between two GPS coordinates + PARAMS: current_GPS (tuple): (latitude, longitude) target_GPS (tuple): (latitude, longitude) RETURNS: float. angle between the two coordinates + """ try: current_latitude = math.radians(current_GPS[1]) diff --git a/unified_frameworks/sensor_array/lidar_visualizer.py b/unified_frameworks/sensor_array/lidar_visualizer.py index b94e475..1786a21 100644 --- a/unified_frameworks/sensor_array/lidar_visualizer.py +++ b/unified_frameworks/sensor_array/lidar_visualizer.py @@ -8,38 +8,39 @@ import time # lidar.config[''] -lidar.start_lidar_service() -# time.sleep(20) -try: - fig = plt.figure() - ax = plt.subplot(111, projection='polar') - obstacle_points = ax.scatter([],[], s=1) - obstacle_groups = LineCollection([], color=(0,0,0,0.5), linewidths=5) - ax.add_collection(obstacle_groups) +if __name__=='__main__': + lidar.start_lidar_service() + # time.sleep(20) + try: + fig = plt.figure() + ax = plt.subplot(111, projection='polar') + obstacle_points = ax.scatter([],[], s=1) + obstacle_groups = LineCollection([], color=(0,0,0,0.5), linewidths=5) + ax.add_collection(obstacle_groups) - rmax=10 - rmax_=0.01 - ax.set_rmax(rmax) - def update_plot(_): - modded = [] - # Visualizing Point Cloud - point_clouds = lidar.get_point_clouds() - measures = sum(point_clouds, []) if point_clouds is not None else [] - if measures: - obstacle_points.set_offsets(measures) - modded.append(obstacle_points) # - #--------------------- - # Visualizing Obstacles - # obstacle_groups.set_segments(obstacles) - obstacle_groups.set_segments(lidar.get_obstacles()) - modded.append(obstacle_groups) - #--------------------- - return modded + rmax=10 + rmax_=0.01 + ax.set_rmax(rmax) + def update_plot(_): + modded = [] + # Visualizing Point Cloud + point_clouds = lidar.get_point_clouds() + measures = sum(point_clouds, []) if point_clouds is not None else [] + if measures: + obstacle_points.set_offsets(measures) + modded.append(obstacle_points) # + #--------------------- + # Visualizing Obstacles + # obstacle_groups.set_segments(obstacles) + obstacle_groups.set_segments(lidar.get_obstacles()) + modded.append(obstacle_groups) + #--------------------- + return modded - anime = anim.FuncAnimation(fig, update_plot, 1, interval=50, blit=True) + anime = anim.FuncAnimation(fig, update_plot, 1, interval=50, blit=True) - plt.show() -except: - pass -lidar.stop_lidar_service() + plt.show() + except: + pass + lidar.stop_lidar_service() diff --git a/unified_frameworks/sensor_array/server_gps.py b/unified_frameworks/sensor_array/server_gps.py index a598604..74ef444 100644 --- a/unified_frameworks/sensor_array/server_gps.py +++ b/unified_frameworks/sensor_array/server_gps.py @@ -3,7 +3,7 @@ import json from gps_compass.actual_gps_compass import ActualGPSCompass -gps = ActualGPSCompass() +# gps = ActualGPSCompass() # Commented this cuz it should not run if the file is not __main__ print("successfully made actual gps") clients = [] # @note List of clients connected in the server diff --git a/unified_frameworks/sensor_array/websocket_client.py b/unified_frameworks/sensor_array/websocket_client.py index 9e43501..246f72a 100644 --- a/unified_frameworks/sensor_array/websocket_client.py +++ b/unified_frameworks/sensor_array/websocket_client.py @@ -10,4 +10,5 @@ async def receive_data(): print(f"Received: {data}") count+=1 -asyncio.get_event_loop().run_until_complete(receive_data()) +if __name__=='__main__': + asyncio.get_event_loop().run_until_complete(receive_data()) diff --git a/unified_frameworks/sensor_array/websocket_server.py b/unified_frameworks/sensor_array/websocket_server.py index a38f770..6e9f74d 100644 --- a/unified_frameworks/sensor_array/websocket_server.py +++ b/unified_frameworks/sensor_array/websocket_server.py @@ -11,7 +11,8 @@ async def data_stream(websocket, path): await websocket.send(data) await asyncio.sleep(1) # Adjust the delay as needed -start_server = websockets.serve(data_stream, "localhost", 8765) +if __name__=='__main__': + start_server = websockets.serve(data_stream, "localhost", 8765) -asyncio.get_event_loop().run_until_complete(start_server) -asyncio.get_event_loop().run_forever() \ No newline at end of file + asyncio.get_event_loop().run_until_complete(start_server) + asyncio.get_event_loop().run_forever() \ No newline at end of file diff --git a/unified_frameworks/worldview_visualizer.py b/unified_frameworks/worldview_visualizer.py index dd00b66..355b9ec 100644 --- a/unified_frameworks/worldview_visualizer.py +++ b/unified_frameworks/worldview_visualizer.py @@ -7,39 +7,40 @@ import worldview import time -# worldview.config[''] -worldview.start_worldview_service() -# time.sleep(20) -try: - fig = plt.figure() - ax = plt.subplot(111, projection='polar') - obstacle_points = ax.scatter([],[], s=1) - obstacle_groups = LineCollection([], color=(0,0,0,0.5), linewidths=5) - ax.add_collection(obstacle_groups) +if __name__=='__main__': + # worldview.config[''] + worldview.start_worldview_service() + # time.sleep(20) + try: + fig = plt.figure() + ax = plt.subplot(111, projection='polar') + obstacle_points = ax.scatter([],[], s=1) + obstacle_groups = LineCollection([], color=(0,0,0,0.5), linewidths=5) + ax.add_collection(obstacle_groups) - rmax=10 - rmax_=0.01 - ax.set_rmax(rmax) - def update_plot(_): - modded = [] - # Visualizing Point Cloud - # point_clouds = worldview.get_point_clouds() - # measures = sum(point_clouds, []) if point_clouds is not None else [] - # if measures: - # obstacle_points.set_offsets(measures) - # modded.append(obstacle_points) # - #--------------------- - # Visualizing Obstacles - # obstacle_groups.set_segments(obstacles) - obstacle_groups.set_segments(worldview.get_obstacles()) - modded.append(obstacle_groups) - #--------------------- - return modded + rmax=10 + rmax_=0.01 + ax.set_rmax(rmax) + def update_plot(_): + modded = [] + # Visualizing Point Cloud + # point_clouds = worldview.get_point_clouds() + # measures = sum(point_clouds, []) if point_clouds is not None else [] + # if measures: + # obstacle_points.set_offsets(measures) + # modded.append(obstacle_points) # + #--------------------- + # Visualizing Obstacles + # obstacle_groups.set_segments(obstacles) + obstacle_groups.set_segments(worldview.get_obstacles()) + modded.append(obstacle_groups) + #--------------------- + return modded - anime = anim.FuncAnimation(fig, update_plot, 1, interval=50, blit=True) + anime = anim.FuncAnimation(fig, update_plot, 1, interval=50, blit=True) - plt.show() -except: - pass -worldview.stop_worldview_service() + plt.show() + except: + pass + worldview.stop_worldview_service()