diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..967b54ead --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.venv +.mongo_data +*.pyc \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..775c5c11e --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,48 @@ +FROM ubuntu:20.04 + +WORKDIR /code + +# Set noninteractive mode +ENV DEBIAN_FRONTEND=noninteractive + +# Install Python3 and pip +RUN apt-get update && \ + apt-get install -y python3-pip + +# Install system dependencies +RUN apt-get install -y \ + g++ \ + gcc \ + gfortran \ + liblapack-dev \ + libffi-dev \ + libssl-dev \ + python3-dev \ + build-essential \ + wget \ + libfreetype6-dev \ + libpng-dev \ + libportaudio2 \ + portaudio19-dev \ + libasound-dev \ + libjack-dev \ + libgl1-mesa-glx + +# Set environment variables +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +COPY requirements.txt /code +RUN pip3 install -r requirements.txt + +COPY . . + +# ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD} +# ENV POSTGRES_DB=${POSTGRES_DB} +# ENV POSTGRES_USER=${POSTGRES_USER} +# ENV DB_HOST_FOR_BACKEND=${DB_HOST_FOR_BACKEND} +# ENV DB_PORT_FOR_BACKEND=${DB_PORT_FOR_BACKEND} + +EXPOSE 5000 + +CMD ["python3", "PythonClient/server/simulation_server.py"] \ No newline at end of file diff --git a/backend/PythonClient/airsim/JSON_files/cesium.json b/backend/PythonClient/airsim/JSON_files/cesium.json new file mode 100644 index 000000000..544b7b4dd --- /dev/null +++ b/backend/PythonClient/airsim/JSON_files/cesium.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/backend/PythonClient/airsim/JSON_files/settings.json b/backend/PythonClient/airsim/JSON_files/settings.json new file mode 100644 index 000000000..6fd59b25c --- /dev/null +++ b/backend/PythonClient/airsim/JSON_files/settings.json @@ -0,0 +1,30 @@ +{ + "SettingsVersion": 1.2, + "SimMode": "Multirotor", + "ClockType" : "SteppableClock", + "Vehicles" : { + "PX4" : { + "VehicleType" : "PX4Multirotor", + "UseSerial" : false, + "LockStep" : true, + "UseTcp" : true, + "TcpPort" : 4560, + "ControlPortLocal" : 14540, + "ControlPortRemote" : 14580, + "Sensors" : { + "Barometer" : { + "SensorType" : 1, + "Enabled" : true, + "PressureFactorSigma" : 0.0001825 + } + }, + "Parameters" : { + "NAV_RCL_ACT" : 0, + "NAV_DLL_ACT" : 0, + "COM_OBL_ACT" : 1, + "LPE_LAT" : 38.6348, + "LPE_LON" : 90.2336 + } + } + } +} diff --git a/backend/PythonClient/multirotor/airsim_application.py b/backend/PythonClient/multirotor/airsim_application.py index 6c02ec620..1877f58c0 100644 --- a/backend/PythonClient/multirotor/airsim_application.py +++ b/backend/PythonClient/multirotor/airsim_application.py @@ -33,13 +33,19 @@ def __init__(self): @staticmethod def load_airsim_setting(): - with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'settings.json', 'r') as f: + current_pwd = os.getcwd() + settings_path = os.path.join(current_pwd, "PythonClient", "airsim", "JSON_files", "settings.json") + with open(settings_path, mode = 'r') as f: + #with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'settings.json', 'r') as f: setting_json = json.load(f) return setting_json @staticmethod def load_cesium_setting(): - with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'cesium.json', 'r') as f: + current_pwd = os.getcwd() + settings_path = os.path.join(current_pwd, "PythonClient", "airsim", "JSON_files", "cesium.json") + with open(settings_path, mode = 'r') as f: + #with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'cesium.json', 'r') as f: cesium_json = json.load(f) return cesium_json diff --git a/backend/PythonClient/multirotor/control/simulation_task_manager.py b/backend/PythonClient/multirotor/control/simulation_task_manager.py index bea263aa8..5e0631978 100644 --- a/backend/PythonClient/multirotor/control/simulation_task_manager.py +++ b/backend/PythonClient/multirotor/control/simulation_task_manager.py @@ -283,14 +283,20 @@ def __remove_non_default_params(single_drone_setting_copy): @staticmethod def __save_settings_dot_json(new_setting_dot_json): - with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'settings.json', - 'w') as outfile: + current_pwd = os.getcwd() + settings_path = os.path.join(current_pwd, "PythonClient", "airsim", "JSON_files", "settings.json") + with open(settings_path, mode = 'w') as outfile: + #with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'settings.json', + #'w') as outfile: json.dump(new_setting_dot_json, outfile, indent=4) @staticmethod def __save_cesium_dot_json(cesium_setting): - with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'cesium.json', - 'w') as outfile: + current_pwd = os.getcwd() + settings_path = os.path.join(current_pwd, "PythonClient", "airsim", "JSON_files", "cesium.json") + with open(settings_path, mode = 'w') as outfile: + #with open(os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'cesium.json', + #'w') as outfile: json.dump(cesium_setting, outfile, indent=4) def stop(self): @@ -521,7 +527,9 @@ def __environment_check(): """ Initialize json files if do not exist """ - file_path = os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'settings.json' + current_pwd = os.getcwd() + file_path = os.path.join(current_pwd, "PythonClient", "airsim", "JSON_files", "settings.json") + #file_path = os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'settings.json' if not os.path.exists(file_path): open(file_path, 'w').close() default_settings = { @@ -539,7 +547,9 @@ def __environment_check(): with open(file_path, 'w') as outfile: json.dump(default_settings, outfile, indent=4) - file_path = os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'cesium.json' + + file_path = os.path.join(current_pwd, "PythonClient", "airsim", "JSON_files", "cesium.json") + #file_path = os.path.join(os.path.expanduser('~'), "Documents", "AirSim") + os.sep + 'cesium.json' if not os.path.exists(file_path): open(file_path, 'w').close() default_settings = { diff --git a/backend/PythonClient/server/simulation_server.py b/backend/PythonClient/server/simulation_server.py index 87003b6b6..ea19a0d59 100644 --- a/backend/PythonClient/server/simulation_server.py +++ b/backend/PythonClient/server/simulation_server.py @@ -326,5 +326,5 @@ def get_map(): if __name__ == '__main__': - app.run(host='0.0.0.0', port=5000) + app.run(host='0.0.0.0', port=5000, debug = True) # makes it discoverable by other devices in the network diff --git a/backend/requirements.txt b/backend/requirements.txt index 4361e2ae6..e7f176b13 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,7 +1,7 @@ -msgpack-rpc-python -numpy==1.25.0 +numpy==1.24.4 numpy_stl==3.0.1 pyaudio +msgpack-rpc-python opencv-contrib-python matplotlib==3.7.1 flask==2.3.2 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..f8647f299 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,82 @@ +# Use root/example as user/password credentials +version: '3.9' + +services: + + mongo_db: + image: mongo + restart: always + container_name: mongo_db + environment: + MONGO_INITDB_ROOT_USERNAME: uav_user + MONGO_INITDB_ROOT_PASSWORD: uavPassword + expose: + - 27017 + volumes: + - ./.mongo_data:/data/db + ports: + - 27017:27017 + env_file: + - ./dockerConfig.env + networks: + - backend_network + + mongo-express: + image: mongo-express + restart: always + container_name: mongo-express + ports: + - 8081:8081 + expose: + - 8081 + environment: + ME_CONFIG_MONGODB_ADMINUSERNAME: uav_user + ME_CONFIG_MONGODB_ADMINPASSWORD: uavPassword + ME_CONFIG_MONGODB_URL: mongodb://uav_user:uavPassword@mongo_db:27017/ + ME_CONFIG_BASICAUTH: false + networks: + - backend_network + env_file: + - ./dockerConfig.env + + python_backend: + build: + context: ./backend + dockerfile: Dockerfile + restart: always + env_file: + - ./dockerConfig.env + container_name: python_backend + ports: + - 5000:5000 + networks: + - frontend_network + - backend_network + depends_on: + - mongo_db + - mongo-express + expose: + - 5000 + + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + restart: always + env_file: + - ./dockerConfig.env + container_name: frontend + ports: + - 3000:3000 + networks: + - frontend_network + expose: + - 3000 + depends_on: + - mongo_db + - mongo-express + - python_backend + +networks: + backend_network: + frontend_network: \ No newline at end of file diff --git a/dockerConfig.env b/dockerConfig.env new file mode 100644 index 000000000..9ebe00044 --- /dev/null +++ b/dockerConfig.env @@ -0,0 +1 @@ +MONGO_DB_USERNAME=uav_user \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 7cc46d205..89e23eaa2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -11,7 +11,6 @@ "@mui/lab": "5.0.0-alpha.118", "@mui/material": "^5.11.5", "@mui/system": "5.15.20", - "@mui/styles": "5.11.2", "@mui/x-date-pickers": "5.0.17", "@react-google-maps/api": "2.18.1", "@testing-library/jest-dom": "^5.16.5",