From 8ccfbd922d21e35959111eedb5a760231d09c5ee Mon Sep 17 00:00:00 2001 From: "V3502 (Conference ID)" Date: Fri, 24 Jul 2015 13:15:25 +0100 Subject: [PATCH 1/4] drone --- colorTrackerUtils.js | 2 +- drone-backend.js | 32 ++++++++++++++++++++++++-- drone-frontend.js | 43 +++++++++++++++++++++++++++++++++-- index.html | 54 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 index.html diff --git a/colorTrackerUtils.js b/colorTrackerUtils.js index 523c119..52775d1 100644 --- a/colorTrackerUtils.js +++ b/colorTrackerUtils.js @@ -55,7 +55,7 @@ var TrackerUtils = (function() { deltaG = gRatio / gRatio2; return deltaColorTotal > 0.8 && deltaColorTotal < 1.2 && - deltaR > 0.8 && deltaR < 1.2 && + deltaR > 0.005 && deltaR < 5.0 && deltaG > 0.8 && deltaG < 1.2; }); } diff --git a/drone-backend.js b/drone-backend.js index f37ea06..39b46a5 100644 --- a/drone-backend.js +++ b/drone-backend.js @@ -16,7 +16,35 @@ Cylon.robot() // Fly the bot function fly(robot) { - + bot = robot; + bot.nav.on("navdata", function(data) { + console.log(data); + }); + bot.drone.config('general:navdata_demo', 'TRUE'); + bot.drone.disableEmergency(); + bot.drone.ftrim(); + bot.drone.takeoff(); + bot.drone.left(0.4); + after(1.85*1000, function() { + bot.drone.front(0.4); + }); + after(3.1*1000, function() { + bot.drone.right(0.4); + }); + after(1.85*1000, function() { + bot.drone.back(0.4); + }); + after(1.75*1000, function() { + bot.drone.left(0.4); + }); + after(1.75*1000, function() { + bot.drone.land(); +}); + after(15*1000, function() { + bot.drone.stop(); + }); } -Cylon.start(); \ No newline at end of file +Cylon.start(); + + diff --git a/drone-frontend.js b/drone-frontend.js index 8c32169..09f43f9 100644 --- a/drone-frontend.js +++ b/drone-frontend.js @@ -6,15 +6,54 @@ function init() { function initTracker(element) { // Initialise a color tracker var tracker = new tracking.ColorTracker(); - + TrackerUtils.addTrackingColor("#63A75E", "green", tracker); + TrackerUtils.addTrackingColor("#5EA24E", "green", tracker); + TrackerUtils.addTrackingColor("#57AE78", "green", tracker); + TrackerUtils.addTrackingColor("#CC7E86", "light red", tracker); + TrackerUtils.addTrackingColor("#C4767C", "light red", tracker); + TrackerUtils.addTrackingColor("#B04D3F", "red", tracker); + TrackerUtils.addTrackingColor("#A54F4C", "red", tracker); + TrackerUtils.addTrackingColor("#333A35", "black", tracker); + TrackerUtils.addTrackingColor("#4C5851", "black", tracker); + TrackerUtils.addTrackingColor("#74727C", "grey", tracker); + TrackerUtils.addTrackingColor("#A9A8B6", "grey", tracker); + TrackerUtils.addTrackingColor("#787882", "grey", tracker); + TrackerUtils.addTrackingColor("#A6A6B1", "grey", tracker); + TrackerUtils.addTrackingColor("#BCC0C2", "white", tracker); + TrackerUtils.addTrackingColor("#B9BBB8", "white", tracker); + TrackerUtils.addTrackingColor("#B8B9BE", "white", tracker); + TrackerUtils.addTrackingColor("#C1BAA9", "white", tracker); TrackerUtils.startTrackingColors(tracker); - // Whenever there is a new color detected, mark them tracker.on('track', function(event) { console.log(event.data); + markColors(event.data, element); }); return tracker; } +function writeRectangle(rect) { + jQuery(".output").append("
"); + jQuery(".output").append(rect.color + ": " + rect.x + ", " + rect.y); +} + +function markColors(colors, element) { + var canvas = $(element + ' .canvas').get(0); + var context = canvas.getContext('2d'); + context.clearRect(0, 0, context.width, context.height); + + for (var i = 0; i < colors.length; i++) { + drawRectangle(colors[i], context); + } +} + +function drawRectangle(rect, context) { + context.strokeStyle = rect.color; + context.strokeRect(rect.x, rect.y, rect.width, rect.height); + + console.log(rect); + writeRectangle(rect); +} + window.addEventListener("load", init); \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..23ada21 --- /dev/null +++ b/index.html @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + +

Seek 'n' Destroy Drone

+
+
+ + + +
+
+
+
+
+
+
+
+
+

+ +

+
+
+
+
+
+
+
+
+
+

What do I see?

+
+ Colours! +
+
+
+ + \ No newline at end of file From 47f79c25fc4b3d11cdc4958b8292735c706a4210 Mon Sep 17 00:00:00 2001 From: "V3502 (Conference ID)" Date: Fri, 24 Jul 2015 13:59:56 +0100 Subject: [PATCH 2/4] drone --- drone-backend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drone-backend.js b/drone-backend.js index 39b46a5..00ec3d9 100644 --- a/drone-backend.js +++ b/drone-backend.js @@ -40,7 +40,7 @@ function fly(robot) { after(1.75*1000, function() { bot.drone.land(); }); - after(15*1000, function() { + after(12.3*1000, function() { bot.drone.stop(); }); } From b487211873e0c2d50a26cf28fe1b734f47010019 Mon Sep 17 00:00:00 2001 From: gofarrell Date: Fri, 24 Jul 2015 14:17:37 +0100 Subject: [PATCH 3/4] Update drone-backend.js --- drone-backend.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drone-backend.js b/drone-backend.js index 00ec3d9..2ec9a77 100644 --- a/drone-backend.js +++ b/drone-backend.js @@ -28,16 +28,16 @@ function fly(robot) { after(1.85*1000, function() { bot.drone.front(0.4); }); - after(3.1*1000, function() { + after(4.95*1000, function() { bot.drone.right(0.4); }); - after(1.85*1000, function() { + after(6.8*1000, function() { bot.drone.back(0.4); }); - after(1.75*1000, function() { + after(8.55*1000, function() { bot.drone.left(0.4); }); - after(1.75*1000, function() { + after(10.3*1000, function() { bot.drone.land(); }); after(12.3*1000, function() { From 4f8e70183a914f5b8c31a1e76b8839f2f2336948 Mon Sep 17 00:00:00 2001 From: gofarrell Date: Fri, 24 Jul 2015 14:42:56 +0100 Subject: [PATCH 4/4] Update drone-backend.js --- drone-backend.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drone-backend.js b/drone-backend.js index 2ec9a77..59d5311 100644 --- a/drone-backend.js +++ b/drone-backend.js @@ -17,30 +17,30 @@ Cylon.robot() // Fly the bot function fly(robot) { bot = robot; - bot.nav.on("navdata", function(data) { - console.log(data); - }); + //bot.nav.on("navdata", function(data) { + //console.log(data); + //}); bot.drone.config('general:navdata_demo', 'TRUE'); bot.drone.disableEmergency(); bot.drone.ftrim(); bot.drone.takeoff(); - bot.drone.left(0.4); - after(1.85*1000, function() { + bot.drone.left(0.2); + after(0.85*1000, function() { bot.drone.front(0.4); }); - after(4.95*1000, function() { + after(1.8*1000, function() { bot.drone.right(0.4); }); - after(6.8*1000, function() { + after(2.65*1000, function() { bot.drone.back(0.4); }); - after(8.55*1000, function() { + after(3.5*1000, function() { bot.drone.left(0.4); }); - after(10.3*1000, function() { + after(3.8*1000, function() { bot.drone.land(); }); - after(12.3*1000, function() { + after(4.1*1000, function() { bot.drone.stop(); }); }