Merge pull request #11 from Northrop-Grumman-Collaboration-Project/routers

Routers
This commit is contained in:
Justin Nguyen 2024-03-30 22:43:32 -07:00 committed by GitHub
commit 014b5be490
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 227 additions and 22 deletions

44
camServer.py Normal file
View File

@ -0,0 +1,44 @@
#111!/usr/bin/env python
# -*- coding: utf-8 -*
#sudo apt-get install python3-flask
#pip3 install opencv-python
from flask import Flask, render_template, Response
import cv2
app = Flask(__name__)
#app.config["CACHE_TYPE"] = "null"
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
vs = cv2.VideoCapture(0) # Camera 1
vs2 = cv2.VideoCapture(1) # Camera 2
def gen(vs):
"""Video streaming generator function."""
while True:
ret,frame=vs.read()
ret, jpeg = cv2.imencode('.jpg', frame)
frame=jpeg.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
vs.release()
cv2.destroyAllWindows()
@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
return Response(gen(vs),mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/video_feed2')
def video_feed2():
"""Video streaming route for camera 2."""
return Response(gen(vs2), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', port =5000, debug=True, threaded=True)

View File

@ -3,7 +3,7 @@
props: ['cameraNumber'],
data() {
return {
localIp: 'http://192.168.1.173', //maybe change accordingly
localIp: 'http://localhost', //maybe change accordingly .env?
port: '5000', //maybe change accordingly
cameraUrls: {
1: 'video_feed', //cam url here

View File

@ -20,7 +20,6 @@ export default {
<nav style="background-color: #011949; padding: 10px;">
<div style="display: flex; align-items: center;">
<router-link to="/" style="text-decoration: none;">
<img src="../assets/NGCP.svg" alt="" width="40" height="24">
<span style="font-weight: bold; font-size: 1.2rem; margin-left: 10px;">NG</span>
<span style="font-weight: bold; font-size: 1.2rem; color: white">CP</span>
</router-link>

View File

@ -5,7 +5,7 @@
<div :class="percentageCSS" :style="[percentage > 15 ? { width: percentage + '%' } : { width: '15%'}]"></div>
</div>
<div class="battery_widget"></div>
<img class="lightingSymbol" :class="batteryStatus" src="..\assets\lightning-icon-png-5.png" >
<img class="lightingSymbol" :class="batteryStatus" src="..\..\assets\lightning-icon-png-5.png" >
</div>
</template>
@ -50,10 +50,8 @@
.outer_div {
display: flex;
position: relative;
/* height: 110px;
width: 225px; */
height: 12%;
width: 12%;
height: 18%;
width: 18%;
}
.battery_widget {

View File

@ -0,0 +1,76 @@
<template>
<div class="outer_div">
<div class="connection-container">
<div v-if="latency == 0" class="grayed_bar" style='height: 20%'></div>
<div v-else class="bar" style='height: 20%'></div>
<div v-if="latency >= 70 || latency == 0" class="grayed_bar" style='height: 40%'></div>
<div v-else class="bar" style='height: 40%'></div>
<div v-if="latency >= 60 || latency == 0" class="grayed_bar" style='height: 60%'></div>
<div v-else class="bar" style='height: 60%'></div>
<div v-if="latency >= 40 || latency == 0" class="grayed_bar" style='height: 80%'></div>
<div v-else class="bar" style='height: 80%'></div>
</div>
<span class="connection_number">{{ latency }} ms</span>
</div>
</template>
<script lang="ts">
export default {
data() {
return {};
},
props: {
latency: { required: true, type: Number},
},
computed: {
}
};
</script>
<style scoped>
.outer_div {
display: flex;
position: relative;
height: 25%;
width: 10%;
}
.connection-container {
position: relative;
justify-content: center;
display: flex;
gap: 0.05em;
height: 100%;
width: 100%;
border-radius: 12%;
/* background-color: white; */
}
.bar {
width:100%;
background-color: white;
border: 0.1em solid black;
margin-top: auto;
border-radius: 20%;
}
.grayed_bar {
width:100%;
background-color: rgb(136, 135, 135);
border: 0.1em solid black;
margin-top: auto;
opacity: 0.2;
border-radius: 20%;
}
.connection_number {
position: absolute;
left: 110%;
bottom: 0%;
width: 180%;
font-size:0.8em;
}
</style>

View File

@ -1,5 +1,6 @@
import { createApp } from "vue";
import "./styles.css";
import App from "./App.vue";
import router from "./router";
createApp(App).mount("#app");
createApp(App).use(router).mount("#app");

View File

@ -1,18 +1,26 @@
<script setup>
import Battery from './components/Battery.vue';
<!-- Using this to see how the Battery and Connection components look -->
<script setup>
import Battery from './components/VehicleStatus/Battery.vue';
import Connection from './components/VehicleStatus/Connection.vue';
</script>
<template>
<h2>Below is the Connection component</h2>
<!-- <div class="bruh">
<Connection :latency=20 />
<!-- <h2>Below is the Connection component</h2>
<div class="border_div">
<Connection :latency=100 />
</div> -->
<h2>Below is the Battery component</h2>
<!-- <h2>Below is the Battery component</h2>
<div class="border_div">
<Battery :percentage=10 :charging="false"/>
<Battery :percentage=12 :charging="false"/> pass in the current percentage into percentage prop. charging is a boolean ! -->
<!-- </div> -->
<h2>Below is both in one div</h2>
<div class="border_div_2">
<Battery :percentage=12 :charging="false" class="additional_battery_prop"/>
<Connection :latency=56 />
</div>
</template>
@ -28,4 +36,18 @@ import Battery from './components/Battery.vue';
width: 200px; */
}
.border_div_2 {
display: flex;
border: 0.4em solid black;
height: 180px;
width: 380px;
/* height: 100px;
width: 200px; */
}
.additional_battery_prop {
top: 4%;
margin-right: 2%;
}
</style>

View File

@ -1,21 +1,86 @@
<script setup lang="ts">
import Battery from '../components/VehicleStatus/Battery.vue';
import Connection from '../components/VehicleStatus/Connection.vue';
import Camera from "../components/Camera.vue";
</script>
<template>
<div class="grid">
<div>
<Camera :cameraNumber="1"/>
</div>
<div>
<div style="position: relative; display: flex;">
<Camera :cameraNumber="2"/>
<Battery :percentage=85 :charging="false" class="battery_test"/>
<Connection :latency=65 class="connection_test"/>
<!-- the Battery and Connection component's size is dependent on its parent element. So changing 'status_div' size will change their size-->
<!-- <div class="status_div">
<Battery :percentage=89 :charging="false" class="adjust_Battery"/>
<Connection :latency=65 />
</div> -->
</div>
<div>
<div style="position: relative; display: flex;">
<Camera :cameraNumber="2"/>
<Battery :percentage=12 :charging="false" class="battery_test"/>
<Connection :latency=3 class="connection_test"/>
<!-- <div class="status_div">
<Battery :percentage=12 :charging="false" class="adjust_Battery"/>
<Connection :latency=3 />
</div> -->
</div>
<div>
<div style="position: relative; display: flex;">
<Camera :cameraNumber="2"/>
<Battery :percentage=46 :charging="false" class="battery_test"/>
<Connection :latency=82 class="connection_test"/>
<!-- <div class="status_div">
<Battery :percentage=46 :charging="false" class="adjust_Battery"/>
<Connection :latency=82 />
</div> -->
</div>
<div style="position: relative; display: flex;">
<Camera :cameraNumber="1"/>
<Battery :percentage=0 :charging="false" class="battery_test"/>
<Connection :latency=5 class="connection_test"/>
<!-- <div class="status_div">
<Battery :percentage=0 :charging="false" class="adjust_Battery"/>
<Connection :latency=5 />
</div> -->
</div>
</div>
</template>
</template>
<style scoped>
/* currently Battery and Connection's sizes are dependent on the parent element (status_div). If we want their own fixed size, can change
it directly in their file component's style*/
.status_div {
display: flex;
position: absolute;
top: 1%;
left:4%;
/* border: 0.4em solid black; */
height: 130px;
width: 260px;
}
.adjust_Battery {
top: 5%;
margin-right: 3%;
}
.battery_test {
position:absolute;
height: 7%;
width: 6.3%;
top: 4%;
left: 2%;
}
.connection_test {
position:absolute;
height: 11%;
width: 4%;
top: 1%;
left: 9.5%;
}
</style>