Skip to content

Commit

Permalink
Merge pull request #11 from javierganan99/develop
Browse files Browse the repository at this point in the history
Simulation automatically stops
  • Loading branch information
javierganan99 authored Oct 15, 2023
2 parents 04ad8fe + 9901062 commit 94a138a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
12 changes: 3 additions & 9 deletions app/routes/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@


@simulation_blueprint.route("/simulation")
def start_simulation(HOST="localhost", PORT=999):
def start_simulation():
"""
TODO: Provide a more insightful description!
Start a simulation of the vehicle routing problem. This includes creating a server socket thread,
creating client socket processes, and emitting images from the vehicles to the client side.
Parameters:
HOST (str, optional): Host of the server. Default is "localhost".
PORT (int, optional): Port number the server listens to. Default is 999.
Start a simulation of the vehicle routing problem.
"""

def stream(simulation, simulation_path):
Expand All @@ -26,7 +20,7 @@ def stream(simulation, simulation_path):
string_data = f"data: {json.dumps(coords)}\n\n"
yield string_data
except StopIteration:
return "data: None\n\n"
yield "data: None\n\n"

current_app.simulation = True
# Define simulation path
Expand Down
7 changes: 3 additions & 4 deletions app/static/js/simulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ function startSimulation () {
updatePoseMarkers(n_vehicles)
eventSourcePose = new EventSource('/simulation')
eventSourcePose.onmessage = function (event) {
const data = JSON.parse(event.data)
if (data === null) {
// TODO: SOLVE!
console.log(data)
if (event.data == 'None') {
stopSimulation()
return
}
const data = JSON.parse(event.data)
for (let i = 0; i < data.length; i++) {
ml = pose_markers[i].length
if (ml >= 1) {
Expand Down

0 comments on commit 94a138a

Please sign in to comment.