From 9d19eeea22b287ab4eb267edba46c54fc49eae6d Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 8 Apr 2019 16:10:56 +0200 Subject: [PATCH] Fix forklift movement Bug where forklift couldnt get to certain nodes is removed by reimplementing vecdtor addition and substarction. --- SZI1/__pycache__/__init__.cpython-37.pyc | Bin 154 -> 140 bytes SZI1/__pycache__/settings.cpython-37.pyc | Bin 2429 -> 2415 bytes SZI1/__pycache__/urls.cpython-37.pyc | Bin 975 -> 961 bytes SZI1/__pycache__/wsgi.cpython-37.pyc | Bin 551 -> 537 bytes magazine/__pycache__/__init__.cpython-37.pyc | Bin 158 -> 144 bytes magazine/__pycache__/admin.cpython-37.pyc | Bin 199 -> 185 bytes magazine/__pycache__/urls.cpython-37.pyc | Bin 447 -> 433 bytes magazine/__pycache__/views.cpython-37.pyc | Bin 1636 -> 1618 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 169 -> 155 bytes magazine/static/magazine/forklift.js | 18 +++++++---- magazine/static/magazine/sketch.js | 30 +++++++++--------- magazine/views.py | 3 +- 12 files changed, 28 insertions(+), 23 deletions(-) diff --git a/SZI1/__pycache__/__init__.cpython-37.pyc b/SZI1/__pycache__/__init__.cpython-37.pyc index 3b07cb9c5288df55936b902e257b2e999d6f8d77..290e05d0a315dc472b119d721c9acacea91ea5cd 100644 GIT binary patch delta 60 zcmbQm*u%)}#LLUY00dkwW=!O^P&L&LElw>e*3U{z&QH>J$xklLP0cGQ)(N#4JVeV008uR5}W`4 delta 74 zcmeBSoW;oP#LLUY00gXZD<^VW7(45S7N-^!>zAeGm6Yb{yQCIpm*f}d2bYwlWG3o6 cdg=!h^j?U|iIiI6TxVos*eXGWjh>69AO{8ZQ6< diff --git a/SZI1/__pycache__/urls.cpython-37.pyc b/SZI1/__pycache__/urls.cpython-37.pyc index c9fa243b275f83c6e1e546f7f08d114c04e27325..fcabce6b101ec41c75c7afa946485227578b8bdb 100644 GIT binary patch delta 62 zcmX@levqBpiIhoLK_^QQH(R delta 76 zcmX@eex9A%iI&<`#tP038u ecl6W`D9X=D%`VY*%yi2y%FfA5E15i#Spxt}kQiS8 diff --git a/SZI1/__pycache__/wsgi.cpython-37.pyc b/SZI1/__pycache__/wsgi.cpython-37.pyc index f66d4666b52b56dbfd904c71f19de9a0ae2e016f..07660ed13165a364a7593c022f0368540c6f534b 100644 GIT binary patch delta 62 zcmZ3^GLwbdiISU)Qe)-OxVD=E#@cS$YIF3B&@4=yQ9$xPID c^wbY1%Fjy8F41?)bjvTw&dE$GnV6vg0RNm9ZvX%Q diff --git a/magazine/__pycache__/admin.cpython-37.pyc b/magazine/__pycache__/admin.cpython-37.pyc index 5bb16c779003a65c02566fd431b56ce111087cfb..576760e9e3001555070d16a0f898bb2bfb35999d 100644 GIT binary patch delta 60 zcmX@kxRa6FiISU)Qe)-OxVD=E#@cS$YIF3B&@4=yQ9$xPID c^wbY1%Fjy8F41?)bjvTw&dE$GnK(ri03cu(6951J diff --git a/magazine/__pycache__/urls.cpython-37.pyc b/magazine/__pycache__/urls.cpython-37.pyc index fd782af95304708de0152026e87248ff77109658..60a76daad0e5c51ac57ec4c420315327eec9801a 100644 GIT binary patch delta 62 zcmdnbypfsPiIhuR4=qkDD%Q_ROwLczcgasK%}vcKDb^1t%Fjwo P1~P)9JPjvLWYhxyBu*1G delta 76 zcmdnUyq}rdiI&<`#tP038u ecl6W`D9X=D%`VY*%yi2y%FfA5E1BHPs0RR4BN%f4 diff --git a/magazine/__pycache__/views.cpython-37.pyc b/magazine/__pycache__/views.cpython-37.pyc index 442ad0b907408e938f9a5ed9c5f5f1534232a7fc..57eb524be25a73d8045c1631848c0697c115fdf5 100644 GIT binary patch delta 354 zcmX9)u}T9$5S^X9^KwTnqM)z{h7<}>dD?JWEOE6Z5eq_Oi8oHH{p^Y+bSW_IS;&#Zgox(<-Z%Jlql=>Be%yt7Ut?s(0s zdU);mVg0tQE4>IAB_;{(0V-c}WpOhAGXC4T~iBh)75mvIa}JTirfmm%8G zhgjI-V@T}YxY5S`u4ncOC)h@hOG#3B$x57aUU$|2ebB54ewT!iE_$!#{0Vpa>SC1E>l zl2ZSI`VX|Rv=n>wAGnv`6fW5X#;o~=!&cY%S@XSvW?3}7i*il2 z&ON`}3}wCH?aNkBIrcVpy**K{mP6@nR<`RRJgb~ay-1#>B}H;g2p|cF3yKCbU^jrY z$MiQ@7-N0#;hG>tR)A<#&(Z8vq7TY$Pa^f9G^&`isv|fus9zQ#NE)0dK>HT$4iUKk z6mPGfZF+NxArBx-iDzVrN00H83&wL7LJ*Hbwg_$C=ozjzP%o_?Qk7PjVIOAn3r*)g z|FfxhK3xFhn2cleSp>9uN#uRARdlC+X?ErWM|&w#cU*|sAyQ6qdUO^vSSU)QiWElw>e)-OxVD=E#@cS$YIF3B&@4=yQ9$xPID c^wbY1%Fjy8F41?)bjvTw&dE$GnV4Y=00>SOn*aa+ diff --git a/magazine/static/magazine/forklift.js b/magazine/static/magazine/forklift.js index 80a7d62..dfe9c57 100644 --- a/magazine/static/magazine/forklift.js +++ b/magazine/static/magazine/forklift.js @@ -39,24 +39,30 @@ class Forklift { } setVelocity() { - p5.Vector.sub( - sections[this.currentTarget], - this.positoin, - this.direction - ); + debugger; + this.direction = this.sub(sections[this.currentTarget], this.positoin); this.velocity = this.direction.setMag(this.speed); } move() { - this.positoin = p5.Vector.add(this.positoin, this.velocity); + this.positoin = this.add(this.positoin, this.velocity); if ( Math.abs(this.positoin.x - sections[this.currentTarget].x) <= this.speed && Math.abs(this.positoin.y - sections[this.currentTarget].y) <= this.speed ) { + this.positoin = sections[this.currentTarget]; this.nextTarget(); this.setVelocity(); } } + + sub(target, pos) { + return createVector(target.x - pos.x, target.y - pos.y); + } + + add(target, pos) { + return createVector(target.x + pos.x, target.y + pos.y); + } } diff --git a/magazine/static/magazine/sketch.js b/magazine/static/magazine/sketch.js index b1f65d1..45ab43c 100644 --- a/magazine/static/magazine/sketch.js +++ b/magazine/static/magazine/sketch.js @@ -8,7 +8,7 @@ let target; // This runs once at start function setup() { - createCanvas(500, 500).parent('canvas'); + createCanvas(600, 600).parent('canvas'); frameRate(30); @@ -44,7 +44,7 @@ function drawMagazine() { sections[road[0]].x, sections[road[0]].y, sections[road[1]].x, - sections[road[1]].y + sections[road[1]].y, ); } noStroke(); @@ -67,7 +67,7 @@ function deliver() { let data = { graph: magazineToGraph(), start_node: forklift.currentSection, - dest_node: int(target.value()) + dest_node: int(target.value()), }; httpPost( 'http://localhost:8000/shortestPath', @@ -80,21 +80,21 @@ function deliver() { }, error => { console.log(error); - } + }, ); } function createMagazineLayout() { - unit = width / 5; + unit = width / 6; sections = { - 0: { x: unit * 2, y: 0 }, - 1: createVector(unit, unit), - 2: createVector(unit, 2 * unit), - 3: createVector(unit, 3 * unit), - 4: createVector(3 * unit, unit), - 5: createVector(3 * unit, 2 * unit), - 6: createVector(3 * unit, 3 * unit) + 0: { x: 2 * unit, y: unit }, + 1: createVector(unit, 2 * unit), + 2: createVector(unit, 3 * unit), + 3: createVector(unit, 4 * unit), + 4: createVector(3 * unit, 2 * unit), + 5: createVector(3 * unit, 3 * unit), + 6: createVector(3 * unit, 4 * unit), }; roads = [ [1, 5], @@ -105,7 +105,7 @@ function createMagazineLayout() { [5, 6], [3, 6], [4, 2], - [5, 3] + [5, 3], ]; } @@ -119,11 +119,11 @@ function magazineToGraph() { end = road[1]; graph[start][end] = Math.sqrt( Math.pow(sections[start].x - sections[end].x, 2) + - Math.pow(sections[start].y - sections[end].y, 2) + Math.pow(sections[start].y - sections[end].y, 2), ); graph[end][start] = Math.sqrt( Math.pow(sections[start].x - sections[end].x, 2) + - Math.pow(sections[start].y - sections[end].y, 2) + Math.pow(sections[start].y - sections[end].y, 2), ); } return graph; diff --git a/magazine/views.py b/magazine/views.py index 30bba36..aaac5f9 100644 --- a/magazine/views.py +++ b/magazine/views.py @@ -20,7 +20,6 @@ def classify(request): @csrf_exempt def shortestPath(request): loaded_request = json.load(request) - print(loaded_request) graph = loaded_request["graph"] graph = {int(k): v for k, v in graph.items()} @@ -62,4 +61,4 @@ def shortestPath(request): current = predecessor[current] path[node] = p[::-1] - return HttpResponse(path[dest_node]) + return HttpResponse(path[dest_node][1:])