From 95cdac514d23104dfd42673e1260f1953dd597be Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Mon, 15 Feb 2016 21:11:45 -0500 Subject: [PATCH 01/10] whitespace bad! --- Robot2016/src/Robot.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index 3813ab6..1873305 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -61,7 +61,6 @@ private: left_drive.SetInverted(true); right_drive.SetInverted(true); inverting = false; - } From e0265bb516108e26e2218804f14cd8ab681e996d Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Wed, 17 Feb 2016 15:22:32 -0500 Subject: [PATCH 02/10] It now only twists when the thumb button is pressed and I added the beginnings of an UpdateDrive method. --- Robot2016/src/Robot.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index 1873305..70fb409 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -1,5 +1,6 @@ #include "WPILib.h" #include "Shooter.h" +#include #ifndef BUTTON_LAYOUT #define BUTTON_LAYOUT @@ -41,6 +42,8 @@ private: // instance variables bool pickupRunning; // don't want to spam the Talon with set messages. Toggle the pickup when a button is pressed or released. bool inverting; + float theta; + float old_theta; LiveWindow *lw = LiveWindow::GetInstance(); SendableChooser *chooser; @@ -106,9 +109,16 @@ private: void TeleopPeriodic() { - drive.ArcadeDrive(&driver_stick, true); + if (driver_stick.GetRawButton(THUMB)) + { + left_drive.Set(driver_stick.GetThrottle() * driver_stick.GetTwist); + right_drive.Set(-1 * driver_stick.GetThrottle() * driver_stick.GetTwist); + } + else + { + UpdateDrive(); + } - // This is shit code for testing. Replace it with real code. if(operator_stick.GetRawButton(RAMP_RAISE)) { ramp.Set(1); @@ -152,6 +162,33 @@ private: { lw->Run(); } + + void UpdateDrive() + { + //regenerating theta + float x = driver_stick.GetX(); + float y = driver_stick.GetY(); + if (x < 0) + { + theta = atan(y / x) * -1; + } + else + { + theta = atan(y / x); + } + theta = theta / 6.283185307; // TODO: This math is optimized for humans. Fix it after initial debugging. + theta = theta + 1; // I know this is a lot of steps, but I want it to be really readable, because there are at least two stupid mistakes I've yet to find. + if (theta != old_theta) + { + //actually update motors + old_theta = theta; + if (theta < 0.125) + { + left_drive.Set(1); + right_drive.Set() + } + } + } }; START_ROBOT_CLASS(Robot) From b65b7e5cc85854057016f92970a5f64a4abdaa85 Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Wed, 17 Feb 2016 16:39:08 -0500 Subject: [PATCH 03/10] Well, ... it's a rough draft, but it SHOULD match the behavior requested. --- Robot2016/src/Robot.cpp | 43 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index 70fb409..ed81880 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -111,8 +111,8 @@ private: { if (driver_stick.GetRawButton(THUMB)) { - left_drive.Set(driver_stick.GetThrottle() * driver_stick.GetTwist); - right_drive.Set(-1 * driver_stick.GetThrottle() * driver_stick.GetTwist); + left_drive.Set(driver_stick.GetThrottle() * driver_stick.GetTwist()); + right_drive.Set(-1 * driver_stick.GetThrottle() * driver_stick.GetTwist()); } else { @@ -184,8 +184,43 @@ private: old_theta = theta; if (theta < 0.125) { - left_drive.Set(1); - right_drive.Set() + left_drive.Set(1 * driver_stick.GetThrottle()); + right_drive.Set((0.25 + 0.25 * 8 * theta) * driver_stick.GetThrottle()); + } + else if (theta < 0.25) + { + left_drive.Set(1 * driver_stick.GetThrottle()); + right_drive.Set((0.5 + 0.5 * 8 * (theta - 0.125)) * driver_stick.GetThrottle()); + } + else if (theta < .375) + { + left_drive.Set((1 - 0.5 * 8 * (theta - 0.25)) * driver_stick.GetThrottle()); + right_drive.Set(1 * driver_stick.GetThrottle()); + } + else if (theta < 0.5) + { + left_drive.Set((0.5 - 0.25 * 8 * (theta - 0.375)) * driver_stick.GetThrottle()); + right_drive.Set(1 * driver_stick.GetThrottle()); + } + else if (theta < 0.625) + { + left_drive.Set((0.25 - 0.25 * 8 * (theta - 0.5)) * driver_stick.GetThrottle()); + right_drive.Set((1 - 8 * (theta - 0.5)) * driver_stick.GetThrottle()); + } + else if (theta < 0.75) + { + left_drive.Set(-8 * (theta - 0.625) * driver_stick.GetThrottle()); + right_drive.Set(-8 * (theta - 0.625) * driver_stick.GetThrottle()); + } + else if (theta < 0.875) + { + left_drive.Set((8 * (theta - 0.75) - 1) * driver_stick.GetThrottle()); + right_drive.Set((8 * (theta - 0.75) - 1) * driver_stick.GetThrottle()); + } + else + { + left_drive.Set(8 * (theta - 0.75) * driver_stick.GetThrottle()); + right_drive.Set(0.25 * 8 * (theta - 0.75) * driver_stick.GetThrottle()); } } } From bfea1eb3edcf3849c7224f08908fc191d48a37e3 Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Fri, 19 Feb 2016 15:47:52 -0500 Subject: [PATCH 04/10] Updated for simpler picewise function. --- Robot2016/src/Robot.cpp | 60 ++++++----------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index ed81880..9828e3e 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -1,6 +1,5 @@ #include "WPILib.h" #include "Shooter.h" -#include #ifndef BUTTON_LAYOUT #define BUTTON_LAYOUT @@ -42,8 +41,7 @@ private: // instance variables bool pickupRunning; // don't want to spam the Talon with set messages. Toggle the pickup when a button is pressed or released. bool inverting; - float theta; - float old_theta; + float oldXY; LiveWindow *lw = LiveWindow::GetInstance(); SendableChooser *chooser; @@ -165,62 +163,20 @@ private: void UpdateDrive() { - //regenerating theta float x = driver_stick.GetX(); float y = driver_stick.GetY(); - if (x < 0) + if ((x + y) != oldXY) { - theta = atan(y / x) * -1; - } - else - { - theta = atan(y / x); - } - theta = theta / 6.283185307; // TODO: This math is optimized for humans. Fix it after initial debugging. - theta = theta + 1; // I know this is a lot of steps, but I want it to be really readable, because there are at least two stupid mistakes I've yet to find. - if (theta != old_theta) - { - //actually update motors - old_theta = theta; - if (theta < 0.125) + oldXY = x + y; + if (x > 0) { - left_drive.Set(1 * driver_stick.GetThrottle()); - right_drive.Set((0.25 + 0.25 * 8 * theta) * driver_stick.GetThrottle()); - } - else if (theta < 0.25) - { - left_drive.Set(1 * driver_stick.GetThrottle()); - right_drive.Set((0.5 + 0.5 * 8 * (theta - 0.125)) * driver_stick.GetThrottle()); - } - else if (theta < .375) - { - left_drive.Set((1 - 0.5 * 8 * (theta - 0.25)) * driver_stick.GetThrottle()); - right_drive.Set(1 * driver_stick.GetThrottle()); - } - else if (theta < 0.5) - { - left_drive.Set((0.5 - 0.25 * 8 * (theta - 0.375)) * driver_stick.GetThrottle()); - right_drive.Set(1 * driver_stick.GetThrottle()); - } - else if (theta < 0.625) - { - left_drive.Set((0.25 - 0.25 * 8 * (theta - 0.5)) * driver_stick.GetThrottle()); - right_drive.Set((1 - 8 * (theta - 0.5)) * driver_stick.GetThrottle()); - } - else if (theta < 0.75) - { - left_drive.Set(-8 * (theta - 0.625) * driver_stick.GetThrottle()); - right_drive.Set(-8 * (theta - 0.625) * driver_stick.GetThrottle()); - } - else if (theta < 0.875) - { - left_drive.Set((8 * (theta - 0.75) - 1) * driver_stick.GetThrottle()); - right_drive.Set((8 * (theta - 0.75) - 1) * driver_stick.GetThrottle()); + left_drive.Set(y * driver_stick.GetThrottle()); + right_drive.Set((1-x)*y * driver_stick.GetThrottle()); } else { - left_drive.Set(8 * (theta - 0.75) * driver_stick.GetThrottle()); - right_drive.Set(0.25 * 8 * (theta - 0.75) * driver_stick.GetThrottle()); + right_drive.Set(y * driver_stick.GetThrottle()); + left_drive.Set((1+x)*y * driver_stick.GetThrottle()); } } } From c32e95768cf02b62c8ff74ecda76028b9144faaf Mon Sep 17 00:00:00 2001 From: dkbug Date: Sat, 20 Feb 2016 16:22:05 -0500 Subject: [PATCH 05/10] Driving is more sane now. --- Robot2016/src/Robot.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index 1bbb859..ce3e84e 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -254,13 +254,15 @@ private: oldXY = x + y; if (x > 0) { - left_drive.Set(y * driver_stick.GetThrottle()); - right_drive.Set((1-x)*y * driver_stick.GetThrottle()); + float left = y * driver_stick.GetThrottle(); + float right = (1-x)*y * driver_stick.GetThrottle(); + drive.TankDrive(left, right); } else { - right_drive.Set(y * driver_stick.GetThrottle()); - left_drive.Set((1+x)*y * driver_stick.GetThrottle()); + float left = y * driver_stick.GetThrottle(); + float right = (1+x)*y * driver_stick.GetThrottle(); + drive.TankDrive(left, right); } } } From 4044f448d7de78ecb37065305bd8b3795824e422 Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Sat, 20 Feb 2016 16:47:00 -0500 Subject: [PATCH 06/10] Actually sane now. Really, I mean it. ...although the turning circle is somewhat ... elephantine ... --- Robot2016/src/Robot.cpp | 43 +++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index ce3e84e..ac53015 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -44,7 +44,6 @@ private: // instance variables bool pickupRunning; // don't want to spam the Talon with set messages. Toggle the pickup when a button is pressed or released. bool inverting; - float oldXY; bool ramping; bool shooting; bool unjamming; @@ -117,8 +116,10 @@ private: { if (driver_stick.GetRawButton(THUMB)) { - left_drive.Set(driver_stick.GetThrottle() * driver_stick.GetTwist()); - right_drive.Set(-1 * driver_stick.GetThrottle() * driver_stick.GetTwist()); + float left = driver_stick.GetTwist(); + float right = -driver_stick.GetTwist(); + + drive.TankDrive(left, right); } else { @@ -187,25 +188,25 @@ private: /* * The 'inverting' variable is used to make sure that the drive train isn't getting - * inverted every itteration of the TeleopPeriodic method while the button is held down. + * inverted every iteration of the TeleopPeriodic method while the button is held down. * This is important because the TeleopPeriodic method executes something like once every 10ms. * Thus, this if-else if pair make the button a toggle. */ - if(driver_stick.GetRawButton(THUMB) && !inverting) + if(driver_stick.GetRawButton(TRIGGER) && !inverting) { std::cout << "Inverting Drive Train."; left_drive.SetInverted(!left_drive.GetInverted()); right_drive.SetInverted(!right_drive.GetInverted()); inverting = true; } - else if(!driver_stick.GetRawButton(THUMB)) + else if(!driver_stick.GetRawButton(TRIGGER)) { inverting = false; } /* - * Unlike the previous actions, this method does need to be called every itteration of + * Unlike the previous actions, this method does need to be called every iteration of * TeleopPeriodic. This is because the logic running this operation needs to be checked * Every time the method is called. This cannot be a loop in the Shoot method because * that would lock the robot every time the trigger is hit. @@ -247,23 +248,19 @@ private: void UpdateDrive() { - float x = driver_stick.GetX(); - float y = driver_stick.GetY(); - if ((x + y) != oldXY) + float x = -driver_stick.GetX(); + float y = -driver_stick.GetY(); + if (x > 0) { - oldXY = x + y; - if (x > 0) - { - float left = y * driver_stick.GetThrottle(); - float right = (1-x)*y * driver_stick.GetThrottle(); - drive.TankDrive(left, right); - } - else - { - float left = y * driver_stick.GetThrottle(); - float right = (1+x)*y * driver_stick.GetThrottle(); - drive.TankDrive(left, right); - } + float right = y * SaneThrottle(driver_stick.GetThrottle()); + float left = (1-x)*y * SaneThrottle(driver_stick.GetThrottle()); + drive.TankDrive(left, right); + } + else + { + float left = y * SaneThrottle(driver_stick.GetThrottle()); + float right = (1+x)*y * SaneThrottle(driver_stick.GetThrottle()); + drive.TankDrive(left, right); } } }; From 5153aaa161ebf407abf7fff7ef63b07e080d09c2 Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Sun, 21 Feb 2016 20:50:24 -0500 Subject: [PATCH 07/10] Added a defined TURN_FACTOR for easily testing variations of the SimpleDrive method --- Robot2016/src/Robot.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index ac53015..e656fd4 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -10,10 +10,15 @@ #define RAMP_LOWER 4 // Button 4 to lower ramp. #define UNJAM 11 -#define DEADZONE_RADIUS 0.01 // Deadzone Radius prevents tiny twitches in the joystick's value from +#define DEADZONE_RADIUS 0.05 // Deadzone Radius prevents tiny twitches in the joystick's value from // affecting the robot. Use this for cleaning up drive train and shooter. // Also used for detecting changes in an axis' value. +#define TURN_FACTOR 1.5 // Left(x,y) = y*(1 + TF*x) : x < 0 + // = y : x >= 0 + // Right(x,y) = y : x < 0 + // = y*(1 - TF*x) : x >= 0 + #endif // BUTTON_LAYOUT class Robot: public IterativeRobot @@ -246,6 +251,27 @@ private: lw->Run(); } + void SimpleDrive() + { + float x = -driver_stick.GetX(); + float y = -driver_stick.GetY(); + float left = 0; + float right = 0; + + if (x > 0) + { + right = y; + left = (1- x*TURN_FACTOR)*y ; + } + else + { + left = y; + right = (1+x*TURN_FACTOR)*y; + } + + drive.TankDrive(left, right); + } + void UpdateDrive() { float x = -driver_stick.GetX(); From 2f010032da695f31973a97257f8011d819ac951d Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Mon, 22 Feb 2016 21:19:51 -0500 Subject: [PATCH 08/10] untested tweaks: different TURN_FACTOR, buttons toggle between piecewise and arcade drive --- Robot2016/src/Robot.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index e656fd4..0fb82ac 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -14,7 +14,7 @@ // affecting the robot. Use this for cleaning up drive train and shooter. // Also used for detecting changes in an axis' value. -#define TURN_FACTOR 1.5 // Left(x,y) = y*(1 + TF*x) : x < 0 +#define TURN_FACTOR 0.5 // Left(x,y) = y*(1 + TF*x) : x < 0 // = y : x >= 0 // Right(x,y) = y : x < 0 // = y*(1 - TF*x) : x >= 0 @@ -52,6 +52,7 @@ private: bool ramping; bool shooting; bool unjamming; + bool arcade; float shooter_power; LiveWindow *lw = LiveWindow::GetInstance(); @@ -119,16 +120,31 @@ private: void TeleopPeriodic() { - if (driver_stick.GetRawButton(THUMB)) + if(driver_stick.GetRawButton(7)) { - float left = driver_stick.GetTwist(); - float right = -driver_stick.GetTwist(); - - drive.TankDrive(left, right); + arcade = true; + } + if(driver_stick.GetRawButton(8)) + { + arcade = false; + } + if (arcade) + { + drive.ArcadeDrive(driver_stick); } else { - UpdateDrive(); + if (driver_stick.GetRawButton(THUMB)) + { + float left = driver_stick.GetTwist(); + float right = -driver_stick.GetTwist(); + + drive.TankDrive(left, right); + } + else + { + UpdateDrive(); + } } //bool rampDoing = false; // This is shit code for testing. Replace it with real code. From fa5ed360256fd7cbdafc02706e061a3e6dfb5d44 Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Mon, 22 Feb 2016 21:26:11 -0500 Subject: [PATCH 09/10] Forgot to initialize arcade --- Robot2016/src/Robot.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index 0fb82ac..4876175 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -78,6 +78,7 @@ private: shooting = false; unjamming = false; shooter_power = 0; + arcade = false; } From 5e26cc78ae6f2a3b5b254ad46b73557d721288fa Mon Sep 17 00:00:00 2001 From: Aidan Ferguson Date: Fri, 26 Feb 2016 17:06:28 -0500 Subject: [PATCH 10/10] Cox wanted TURN_FACTOR upped. He gets what he wants. --- Robot2016/src/Robot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Robot2016/src/Robot.cpp b/Robot2016/src/Robot.cpp index f5a3e93..0a0ac59 100644 --- a/Robot2016/src/Robot.cpp +++ b/Robot2016/src/Robot.cpp @@ -15,7 +15,7 @@ // affecting the robot. Use this for cleaning up drive train and shooter. // Also used for detecting changes in an axis' value. -#define TURN_FACTOR 0.5 // Left(x,y) = y*(1 + TF*x) : x < 0 +#define TURN_FACTOR 1.5 // Left(x,y) = y*(1 + TF*x) : x < 0 // = y : x >= 0 // Right(x,y) = y : x < 0 // = y*(1 - TF*x) : x >= 0