From 079aaf5dc08035a0252faad3b224afeaef60ba07 Mon Sep 17 00:00:00 2001 From: thoang21 <54091854+thoang21@users.noreply.github.com> Date: Thu, 12 Mar 2020 10:26:12 +0700 Subject: [PATCH 1/2] Tung's Path --- main.js | 182 +++++--------------------------------------------------- 1 file changed, 14 insertions(+), 168 deletions(-) diff --git a/main.js b/main.js index b358935..35a9a1b 100644 --- a/main.js +++ b/main.js @@ -23,21 +23,16 @@ I will be syncing with this repository on my computer and pasting the code into async function startProgram() { //Jake' Movement Here (Stage 1): - await EMWStage1() - await EMWStage2() - await EMWStage3() - await EMWStage4() - await EMWStage5() - await EMWStage6() - await EMWStage7() - + await TungStage1() + await TungStage2() + await TungStage3() exitProgram() } -async function EMWStage1(){ - //Travel to (0,30) at a heading of 0 degrees +async function TungStage1(){ + //Travel to (240,0) at a heading of 90 degrees - let setpoint = 30; + let setpoint = 240; let k = 2.0; let kD = 0.5; let kI = 0.001; @@ -53,7 +48,7 @@ async function EMWStage1(){ while(stageComplete != true){ //get the current location of the robot. - var location = getLocation().y; + var location = getLocation().x; //Use a PID algorithm to set the position of the robot var error = directionSign*(setpoint - location); @@ -96,21 +91,21 @@ async function EMWStage1(){ async function EMWStage2(){ -//Turn to a heading of 90 degrees. +//Turn to a heading of 180 degrees. //This function rolls the motors at a heading of 90, with a motor speed of 50, for 0.1 seconds. -await roll(90,50,0.1) +await roll(180,50,0.1) //...and then this moves it back. -await roll(90,-50,0.1) +await roll(180,-50,0.1) } async function EMWStage3(){ - //Travel to (60,30) at a heading of 90 degrees + //Travel to (240,-60) at a heading of 90 degrees //Make sure to change the heading at line 150! - let setpoint = 60; + let setpoint = -60; let k = 2.0; let kD = 0.5; let kI = 0.001; @@ -118,14 +113,14 @@ async function EMWStage3(){ var oldError = 0; var successTimer = 0.0; var maxSpeed = 100; - var directionSign = 1; //-1 for moving left or down, 1 for moving right or up + var directionSign = -1; //-1 for moving left or down, 1 for moving right or up stageComplete = false; await setMainLed({r:0,g:0,b:255}) while(stageComplete != true){ //get the current location of the robot. Note that this uses the x-coordinate this time, not y. - var location = getLocation().x; + var location = getLocation().y; //Use a PID algorithm to set the position of the robot var error = directionSign*(setpoint - location); @@ -165,152 +160,3 @@ async function EMWStage3(){ } } -async function EMWStage4(){ - - -//Turn to a heading of 0 degrees - -//This function rolls the motors at a heading of 90, with a motor speed of 50, for 0.1 seconds. -await roll(0,50,0.1) -//...and then this moves it back. -await roll(0,-50,0.1) -} - -async function EMWStage5(){ - //Travel to (60,90) at a heading of 0 degrees - //Make sure to change the heading at line 223! - - let setpoint = 90; - - let k = 2.0; - let kD = 0.5; - let kI = 0.001; - var accumulatedError = 0; - var oldError = 0; - var successTimer = 0.0; - var maxSpeed = 100; - var directionSign = 1; //-1 for moving left or down, 1 for moving right or up - - var stageComplete = false; - - //Visual feedback to know which stage we are on - await setMainLed({r:255,g:0,b:0}) - - while(stageComplete != true){ - //get the current location of the robot. - var location = getLocation().y; - - //Use a PID algorithm to set the position of the robot - var error = directionSign*(setpoint - location); - var changeError = error - oldError; - accumulatedError = error + accumulatedError - - - var output = k*error - kD*changeError + kI*accumulatedError; - oldError = error - - if(output >maxSpeed){ - - output = maxSpeed; - - } - if(output < -255){ - - output = -maxSpeed; - } - - //This function rolls the motors at a heading of 0, with a motor speed of output, for 0.2 seconds. - await roll(0,output,0.2); - - if(error < 2.0){ - successTimer += 0.1; - - } - - //If the error has been less than 2.0 cm for more than half a second, finish the stage. - if(successTimer > 0.5){ - stageComplete = true - } - - await delay(0.025); - //If our error is less than 1.0 cm, keep track of how long that has been the case. - - - } - -} - -async function EMWStage6(){ - -//Turn to a heading of 270 degrees - -//This function rolls the motors at a heading of 90, with a motor speed of 50, for 0.1 seconds. -await roll(270,-50,0.1) -//...and then this moves it back. -await roll(270,50,0.1) -} - -async function EMWStage7(){ - - //Travel to (0,90) at a heading of 270 degrees - //Make sure to change the heading at line 298! - - let setpoint = 0; //drive for 3 tiles - - let k = 2.0; - let kD = 0.5; - let kI = 0.001; - var accumulatedError = 0; - var oldError = 0; - var successTimer = 0.0; - var maxSpeed = 100; - var directionSign = -1; //-1 for moving left or down, 1 for moving right or up - - var stageComplete = false; - - //Visual feedback to know which stage we are on - await setMainLed({r:255,g:0,b:0}) - - while(stageComplete != true){ - //get the current location of the robot. - var location = getLocation().x; - - //Use a PID algorithm to set the position of the robot - var error = directionSign*(setpoint - location); - var changeError = error - oldError; - accumulatedError = error + accumulatedError - - - var output = k*error - kD*changeError + kI*accumulatedError; - oldError = error - - if(output >maxSpeed){ - - output = maxSpeed; - - } - if(output < -255){ - - output = -maxSpeed; - } - - //This function rolls the motors at a heading of 0, with a motor speed of output, for 0.2 seconds. - await roll(270,output,0.2); - - if(error < 2.0){ - successTimer += 0.1; - - } - - //If the error has been less than 2.0 cm for more than half a second, finish the stage. - if(successTimer > 0.5){ - stageComplete = true - } - - await delay(0.025); - //If our error is less than 1.0 cm, keep track of how long that has been the case. - - - } - -} From e723a3e0db04c94cfdf76bb34cc715b8ee761100 Mon Sep 17 00:00:00 2001 From: thoang21 <54091854+thoang21@users.noreply.github.com> Date: Thu, 12 Mar 2020 10:31:10 +0700 Subject: [PATCH 2/2] Update main.js --- main.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index 35a9a1b..da66b7b 100644 --- a/main.js +++ b/main.js @@ -22,7 +22,7 @@ I will be syncing with this repository on my computer and pasting the code into */ async function startProgram() { - //Jake' Movement Here (Stage 1): + //Tung's Movement Here: await TungStage1() await TungStage2() await TungStage3() @@ -70,7 +70,7 @@ async function TungStage1(){ } //This function rolls the motors at a heading of 0, with a motor speed of output, for 0.2 seconds. - await roll(0,output,0.2); + await roll(90,output,0.2); if(error < 2.0){ successTimer += 0.1; @@ -89,7 +89,7 @@ async function TungStage1(){ } -async function EMWStage2(){ +async function TungStage2(){ //Turn to a heading of 180 degrees. @@ -100,10 +100,9 @@ await roll(180,-50,0.1) } -async function EMWStage3(){ +async function TungStage3(){ - //Travel to (240,-60) at a heading of 90 degrees - //Make sure to change the heading at line 150! + //Travel to (240,-60) at a heading of 180 degrees let setpoint = -60; let k = 2.0; @@ -142,7 +141,7 @@ async function EMWStage3(){ } //We want all of this to be happening at a heading of 90 degrees - await roll(90,output,0.2); + await roll(180,output,0.2); if(error < 2.0){ successTimer += 0.1;