Skip to content

Commit

Permalink
Merge pull request #113 from ad101-lab/ad-awp-states
Browse files Browse the repository at this point in the history
Working on getting AWP working, lots of intake problems with too many rings
  • Loading branch information
alexDickhans authored Mar 6, 2022
2 parents 60163c3 + c8e7703 commit d9b8eb2
Show file tree
Hide file tree
Showing 7 changed files with 584 additions and 230 deletions.
156 changes: 98 additions & 58 deletions include/autoPaths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace Pronounce {
int farHomeZoneToEnterFarHomeZone2Index = -1;
int farPlatformToGoalDropOff2Index = -1;
int farLeftAllianceGoalToRightAllianceGoalIndex = -1;
int farLeftAllianceToPlatformIndex = -1;

// Right steal right
int rightHomeZoneToRightNeutralIndex = -1;
Expand All @@ -55,6 +56,10 @@ namespace Pronounce {
int leftNeutralToLeftAllianceGoalIndex = -1;
int leftAllianceGoalToMidRingsIndex = -1;
int leftAllianceToRightHomeZoneIndex = -1;
int leftNeutralToEnterLeftHomeZoneIndex = -1;
int enterLeftHomeZoneToMidGoalIndex = -1;
int midGoalToEnterLeftHomeZoneIndex = -1;
int midRingsToRightHomeZoneIndex = -1;

// Legacy
int forwardIndex = -1;
Expand All @@ -78,34 +83,6 @@ namespace Pronounce {

// !SECTION

// SECTION Left AWP

QuadraticSplinePath leftAllianceToRightAlliance("Left alliance to right home zone");

leftAllianceToRightAlliance.addPoint(SplinePoint(Point(30.0, 11.4), Vector(20, M_PI_2)));
leftAllianceToRightAlliance.addPoint(SplinePoint(Point(30, 46.4), Vector(20, -M_PI_2)));
leftAllianceToRightAlliance.addPoint(SplinePoint(Point(46.4, 46.4), Vector(15, -M_PI_2)));
leftAllianceToRightAlliance.addPoint(SplinePoint(Point(80, 46.4), Vector(0, -M_PI_2)));
leftAllianceToRightAlliance.addPoint(SplinePoint(Point(123.0, 35), Vector(15.0, -M_PI_2)));

leftAllianceToRightAllianceIndex = purePursuit->addPath(leftAllianceToRightAlliance.getPath(0.1));

QuadraticSplinePath rightAllianceToRightRings("Right alliance to right rings");

rightAllianceToRightRings.addPoint(SplinePoint(Point(125, 35), Vector(5, M_PI_4)));
rightAllianceToRightRings.addPoint(SplinePoint(Point(117.5, 70), Vector(35, 0)));

rightAllianceToRightRingsIndex = purePursuit->addPath(rightAllianceToRightRings.getPath(0.1));

QuadraticSplinePath rightRingsToRightHomeZone2("Right rings to right home zone");

rightRingsToRightHomeZone2.addPoint(SplinePoint(Point(117.5, 70.3), Vector(15.0, M_PI)));
rightRingsToRightHomeZone2.addPoint(SplinePoint(Point(117.5, 35), Vector(15.0, M_PI)));

rightRingsToRightHomeZone2Index = purePursuit->addPath(rightRingsToRightHomeZone2.getPath(0.1));

// !SECTION

//SECTION Skills

// Left home zone to left neutral goal
Expand Down Expand Up @@ -136,43 +113,43 @@ namespace Pronounce {
Path farHomeZoneToMidNeutralGoal("Far Home Zone to Mid Neutral Goal");

farHomeZoneToMidNeutralGoal.addPoint(60.3, 117);
farHomeZoneToMidNeutralGoal.addPoint(70.3, 78);
farHomeZoneToMidNeutralGoal.addPoint(70, 78);

farHomeZoneToMidNeutralGoalIndex = purePursuit->addPath(farHomeZoneToMidNeutralGoal);

QuadraticSplinePath midNeutralGoalToPlatform("Mid Neutral Goal to Platform");

midNeutralGoalToPlatform.addPoint(SplinePoint(Point(70, 75), Vector(30, 0)));
midNeutralGoalToPlatform.addPoint(SplinePoint(Point(80, 110), Vector(30, 0)));
midNeutralGoalToPlatform.addPoint(SplinePoint(Point(73, 115), Vector(30, 0)));

midNeutralGoalToPlatformIndex = purePursuit->addPath(midNeutralGoalToPlatform.getPath(0.1));

QuadraticSplinePath farPlatformToDropOffGoal("Far Platform to Drop Off Goal");

farPlatformToDropOffGoal.addPoint(SplinePoint(Point(80, 110), Vector(20, M_PI)));
farPlatformToDropOffGoal.addPoint(SplinePoint(Point(40, 100), Vector(15, M_PI_2)));
farPlatformToDropOffGoal.addPoint(SplinePoint(Point(80, 113), Vector(20, M_PI)));
farPlatformToDropOffGoal.addPoint(SplinePoint(Point(40, 97), Vector(15, M_PI_2)));

farPlatformToDropOffGoalIndex = purePursuit->addPath(farPlatformToDropOffGoal.getPath(0.05));

QuadraticSplinePath dropOffGoalToRightAlliance("Drop Off Goal to Right Alliance");

dropOffGoalToRightAlliance.addPoint(SplinePoint(Point(40, 100), Vector(15, -M_PI_2)));
dropOffGoalToRightAlliance.addPoint(SplinePoint(Point(70, 70), Vector(15, M_PI)));
dropOffGoalToRightAlliance.addPoint(SplinePoint(Point(120, 35), Vector(40, -M_PI_2 * 0.9)));
dropOffGoalToRightAlliance.addPoint(SplinePoint(Point(127, 35), Vector(40, -M_PI_2)));

dropOffGoalToRightAllianceIndex = purePursuit->addPath(dropOffGoalToRightAlliance.getPath(0.05));

QuadraticSplinePath rightAllianceToRightNeutral("Right Alliance to Right Neutral");

rightAllianceToRightNeutral.addPoint(SplinePoint(Point(125, 35), Vector(20, M_PI_4)));
rightAllianceToRightNeutral.addPoint(SplinePoint(Point(107, 65), Vector(20, 0)));
rightAllianceToRightNeutral.addPoint(SplinePoint(Point(125, 35), Vector(30, M_PI_4)));
rightAllianceToRightNeutral.addPoint(SplinePoint(Point(101, 70), Vector(20, 0)));

rightAllianceToRightNeutralIndex = purePursuit->addPath(rightAllianceToRightNeutral.getPath(0.05));

QuadraticSplinePath rightNeutralToFarPlatform("Right Neutral Goal to Far Platform");

rightNeutralToFarPlatform.addPoint(SplinePoint(Point(105.7, 65), Vector(30, 0)));
rightNeutralToFarPlatform.addPoint(SplinePoint(Point(85, 110), Vector(20, 0)));
rightNeutralToFarPlatform.addPoint(SplinePoint(Point(70, 113), Vector(20, 0)));

rightNeutralToFarPlatformIndex = purePursuit->addPath(rightNeutralToFarPlatform.getPath(0.1));

Expand All @@ -186,28 +163,28 @@ namespace Pronounce {
QuadraticSplinePath goalDropOffToFarPlatform("Goal drop off 1 to far platform");

goalDropOffToFarPlatform.addPoint(SplinePoint(Point(50, 95), Vector(15, -M_PI_4)));
goalDropOffToFarPlatform.addPoint(SplinePoint(Point(65, 110), Vector(15, 0)));
goalDropOffToFarPlatform.addPoint(SplinePoint(Point(65, 113), Vector(15, 0)));

goalDropOffToFarPlatformIndex = purePursuit->addPath(goalDropOffToFarPlatform.getPath(0.1));

QuadraticSplinePath farPlatformToGoalDropOff2("Far platform to goal drop off 2");

farPlatformToGoalDropOff2.addPoint(SplinePoint(Point(65, 113), Vector(15, M_PI)));
farPlatformToGoalDropOff2.addPoint(SplinePoint(Point(65, 110), Vector(15, M_PI)));
farPlatformToGoalDropOff2.addPoint(SplinePoint(Point(65, 100), Vector(15, M_PI)));

farPlatformToGoalDropOff2Index = purePursuit->addPath(farPlatformToGoalDropOff2.getPath(0.1));

QuadraticSplinePath goalDropOffToFarLeftAlliance("Goal Drop Off to Far Left Alliance");

goalDropOffToFarLeftAlliance.addPoint(SplinePoint(Point(60, 105.7), Vector(20, M_PI_2)));
goalDropOffToFarLeftAlliance.addPoint(SplinePoint(Point(22, 105.7), Vector(20, M_PI_2)));
goalDropOffToFarLeftAlliance.addPoint(SplinePoint(Point(18, 105.7), Vector(20, M_PI_2)));

goalDropOffToFarLeftAllianceIndex = purePursuit->addPath(goalDropOffToFarLeftAlliance.getPath(0.1));

QuadraticSplinePath farLeftAllianceGoalToRightAllianceGoal("Far Left Alliance Goal to Right Alliance Goal");

farLeftAllianceGoalToRightAllianceGoal.addPoint(SplinePoint(Point(18, 105.7), Vector(10, -M_PI_2)));
farLeftAllianceGoalToRightAllianceGoal.addPoint(SplinePoint(Point(90, 105.7), Vector(30, -M_PI_2)));
farLeftAllianceGoalToRightAllianceGoal.addPoint(SplinePoint(Point(95, 105.7), Vector(40, -M_PI_2)));
farLeftAllianceGoalToRightAllianceGoal.addPoint(SplinePoint(Point(105, 123), Vector(10, M_PI_4)));

farLeftAllianceGoalToRightAllianceGoalIndex = purePursuit->addPath(farLeftAllianceGoalToRightAllianceGoal.getPath(0.05));
Expand Down Expand Up @@ -277,61 +254,118 @@ namespace Pronounce {

farHomeZoneToEnterFarHomeZone2Index = purePursuit->addPath(farHomeZoneToEnterFarHomeZone2);

//!SECTION
QuadraticSplinePath farLeftAllianceToPlatform("Far platform to goal drop off 2");

farLeftAllianceToPlatform.addPoint(SplinePoint(Point(24, 105.7), Vector(15, M_PI_2)));
farLeftAllianceToPlatform.addPoint(SplinePoint(Point(11.4, 70.3), Vector(30, M_PI)));
farLeftAllianceToPlatform.addPoint(SplinePoint(Point(35, 14.4), Vector(30, -M_PI_2)));

farLeftAllianceToPlatformIndex = purePursuit->addPath(farLeftAllianceToPlatform.getPath(0.05));

// !SECTION

// SECTION Left AWP

QuadraticSplinePath leftAllianceToRightAlliance("Left alliance to right home zone");

leftAllianceToRightAlliance.addPoint(SplinePoint(Point(28.0, 11.4), Vector(20, M_PI_2)));
leftAllianceToRightAlliance.addPoint(SplinePoint(Point(30, 43), Vector(20, -M_PI_2)));
leftAllianceToRightAlliance.addPoint(SplinePoint(Point(80, 43), Vector(15, -M_PI_2)));
leftAllianceToRightAlliance.addPoint(SplinePoint(Point(125.0, 35), Vector(15.0, -M_PI_2)));

leftAllianceToRightAllianceIndex = purePursuit->addPath(leftAllianceToRightAlliance.getPath(0.1));

QuadraticSplinePath rightAllianceToRightRings("Right alliance to right rings");

rightAllianceToRightRings.addPoint(SplinePoint(Point(125, 35), Vector(5, M_PI_4)));
rightAllianceToRightRings.addPoint(SplinePoint(Point(120, 73), Vector(35, 0)));

rightAllianceToRightRingsIndex = purePursuit->addPath(rightAllianceToRightRings.getPath(0.1));

QuadraticSplinePath rightRingsToRightHomeZone2("Right rings to right home zone");

rightRingsToRightHomeZone2.addPoint(SplinePoint(Point(117.5, 70.3), Vector(15.0, M_PI)));
rightRingsToRightHomeZone2.addPoint(SplinePoint(Point(117.5, 35), Vector(15.0, M_PI)));

rightRingsToRightHomeZone2Index = purePursuit->addPath(rightRingsToRightHomeZone2.getPath(0.1));

// !SECTION

// SECTION Right Steal Right

Path rightHomeZoneToRightNeutral("Right Home Zone to Right Neutral");
QuadraticSplinePath rightHomeZoneToRightNeutral("Right Home Zone to Right Neutral");

rightHomeZoneToRightNeutral.addPoint(105.7, 16);
rightHomeZoneToRightNeutral.addPoint(105.7, 55);
rightHomeZoneToRightNeutral.addPoint(SplinePoint(Point(105.7, 16.5), Vector(10, 0)));
rightHomeZoneToRightNeutral.addPoint(SplinePoint(Point(105.7, 55), Vector(10, 0)));

rightHomeZoneToRightNeutralIndex = purePursuit->addPath(rightHomeZoneToRightNeutral);
rightHomeZoneToRightNeutralIndex = purePursuit->addPath(rightHomeZoneToRightNeutral.getPath(0.1));

QuadraticSplinePath rightNeutralToRightAllianceGoal;

rightNeutralToRightAllianceGoal.addPoint(SplinePoint(Point(105.7, 58), Vector(20, 0)));
rightNeutralToRightAllianceGoal.addPoint(SplinePoint(Point(122, 37), Vector(15, -M_PI_4)));
rightNeutralToRightAllianceGoal.addPoint(SplinePoint(Point(100, 58), Vector(5, -M_PI*0.9)));
rightNeutralToRightAllianceGoal.addPoint(SplinePoint(Point(127.0, 41), Vector(35, -M_PI_2*0.9)));

rightNeutralToRightAllianceGoalIndex = purePursuit->addPath(rightNeutralToRightAllianceGoal.getPath(0.05));

SplinePath rightAllianceGoalToRightRings;

rightAllianceGoalToRightRings.addPoint(125, 37);
rightAllianceGoalToRightRings.addPoint(123.0, 35);
rightAllianceGoalToRightRings.addPoint(117.5, 46.8);
rightAllianceGoalToRightRings.addPoint(117.5, 70);
rightAllianceGoalToRightRings.addPoint(117.5, 73);
rightAllianceGoalToRightRings.addPoint(135, 67);

rightAllianceGoalToRightRingsIndex = purePursuit->addPath(rightAllianceGoalToRightRings.getPath(0.05));

Path rightRingsToRightHomeZone;

rightRingsToRightHomeZone.addPoint(117.5, 70);
rightRingsToRightHomeZone.addPoint(117.5, 40);
rightRingsToRightHomeZone.addPoint(135, 67);
rightRingsToRightHomeZone.addPoint(117.5, 35);

rightRingsToRightHomeZoneIndex = purePursuit->addPath(rightRingsToRightHomeZone);

//!SECTION

// SECTION Left Steal Left

Path leftHomeZoneToLeftNeutral("Left Home Zone to Left Neutral");
QuadraticSplinePath leftHomeZoneToLeftNeutral("Left Home Zone to Left Neutral");

leftHomeZoneToLeftNeutral.addPoint(SplinePoint(Point(25, 16), Vector(0.0, 0.0)));
leftHomeZoneToLeftNeutral.addPoint(SplinePoint(Point(34, 57), Vector(0.0, 0.0)));

leftHomeZoneToLeftNeutralIndex = purePursuit->addPath(leftHomeZoneToLeftNeutral.getPath(0.1));

QuadraticSplinePath leftNeutralToEnterLeftHomeZone("Left alliance to enter left home zone");

leftNeutralToEnterLeftHomeZone.addPoint(SplinePoint(Point(34, 57), Vector(0.0, 0.0)));
leftNeutralToEnterLeftHomeZone.addPoint(SplinePoint(Point(30, 40), Vector(0.0, 0.0)));

leftNeutralToEnterLeftHomeZoneIndex = purePursuit->addPath(leftNeutralToEnterLeftHomeZone.getPath(0.1));

QuadraticSplinePath enterLeftHomeZoneToMidGoal("Enter Right Home Zone to Mid Goal");

enterLeftHomeZoneToMidGoal.addPoint(SplinePoint(Point(30, 40), Vector(10, -M_PI_4)));
enterLeftHomeZoneToMidGoal.addPoint(SplinePoint(Point(65, 65), Vector(0.0, 0.0)));

leftHomeZoneToLeftNeutral.addPoint(25, 16);
leftHomeZoneToLeftNeutral.addPoint(33, 57);
enterLeftHomeZoneToMidGoalIndex = purePursuit->addPath(enterLeftHomeZoneToMidGoal.getPath(0.1));

leftHomeZoneToLeftNeutralIndex = purePursuit->addPath(leftHomeZoneToLeftNeutral);
QuadraticSplinePath midGoalToEnterLeftHomeZone("Mid Goal to Enter Left Home Zone");

midGoalToEnterLeftHomeZone.addPoint(SplinePoint(Point(30, 40), Vector(0.0, 0.0)));
midGoalToEnterLeftHomeZone.addPoint(SplinePoint(Point(65, 65), Vector(0.0, 0.0)));

midGoalToEnterLeftHomeZoneIndex = purePursuit->addPath(midGoalToEnterLeftHomeZone.getPath(0.1));

SplinePath leftNeutralToLeftAllianceGoal;

leftNeutralToLeftAllianceGoal.addPoint(30, 58);
leftNeutralToLeftAllianceGoal.addPoint(10, 14);
leftNeutralToLeftAllianceGoal.addPoint(34, 12);
leftNeutralToLeftAllianceGoal.addPoint(6, 17);
leftNeutralToLeftAllianceGoal.addPoint(34, 19);

leftNeutralToLeftAllianceGoalIndex = purePursuit->addPath(leftNeutralToLeftAllianceGoal.getPath(0.01));

QuadraticSplinePath leftAllianceToRightHomeZone;

leftAllianceToRightHomeZone.addPoint(SplinePoint(Point(30.0, 11.4), Vector(20, M_PI_2)));
leftAllianceToRightHomeZone.addPoint(SplinePoint(Point(30.0, 11.4), Vector(15, M_PI_2)));
leftAllianceToRightHomeZone.addPoint(SplinePoint(Point(30, 46.4), Vector(20, -M_PI_2)));
leftAllianceToRightHomeZone.addPoint(SplinePoint(Point(46.4, 46.4), Vector(15, -M_PI_2)));
leftAllianceToRightHomeZone.addPoint(SplinePoint(Point(80, 46.4), Vector(0, -M_PI_2)));
Expand All @@ -347,6 +381,12 @@ namespace Pronounce {

leftAllianceGoalToMidRingsIndex = purePursuit->addPath(leftAllianceGoalToMidRings.getPath(0.01));

// SECTION Mid steal


// !SECTION


Path forward;

forward.addPoint(0, 16);
Expand Down
2 changes: 1 addition & 1 deletion include/chassis/tankDrive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Pronounce {
TankDrivetrain(pros::Motor* frontLeft, pros::Motor* frontRight, pros::Motor* midLeft, pros::Motor* midRight, pros::Motor* backLeft, pros::Motor* backRight, pros::Imu* imu, double trackWidth);

double getSpeed() override {
return (this->getLeftMotors().get_target_velocity() + this->getRightMotors().get_target_velocity()) / 2;
return (this->getLeftMotors().get_actual_velocity() + this->getRightMotors().get_actual_velocity()) / 2;
}

void skidSteerVelocity(double speed, double turn) {
Expand Down
87 changes: 87 additions & 0 deletions include/odometry/gpsOdometry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once

#include "odometry/odometry.hpp"
#include "api.h"

namespace Pronounce {
class GpsOdometry : public Odometry {
private:
pros::Gps* gps;

pros::c::gps_status_s_t lastPos;
bool goodFixBool = false;
int32_t lastGoodFix = -10000;
int32_t lastUpdate = 0;

double gpsX = 0;
double gpsY = 0;
double gpsOrientation = 0;

double convertToLocal(double x) {
return (x - 1.8) * 39.37;
}

double convertToGlobal(double x) {
return (x / 39.37) + 1.8;
}
public:
GpsOdometry();
GpsOdometry(pros::Gps* gps);

void update();
void update(Position* position);

void reset(Position* position) {
this->setPosition(position);
this->setResetPosition(position);
gps->initialize_full(convertToGlobal(position->getX()), convertToGlobal(position->getY()), toDegrees(position->getTheta()) + gpsOrientation, gpsX, gpsY);
}

pros::Gps* getGps() {
return gps;
}

void setGps(pros::Gps* gps) {
this->gps = gps;
}

bool goodFix() {

pros::c::gps_status_s_t currentPos = gps->get_status();

if (pros::millis() - lastUpdate < 50) {
if (goodFixBool && pros::millis() - lastGoodFix > 2000) {
return true;
}
return false;
}

// If our position is 0 we invalidate it
if (sqrt(pow(currentPos.x, 2) + pow(currentPos.y, 2)) == 0.0) {
goodFixBool = false;
return false;
}

// If the robot isn't moving too far start the timer
if (sqrt(pow(currentPos.x - lastPos.x, 2) + pow(currentPos.y - lastPos.y, 2)) < (2.0 / (1000.0 / (double)(pros::millis() - lastUpdate))) && !goodFixBool) {
if (!goodFixBool) {
lastGoodFix = pros::millis();
}
goodFixBool = true;
}
else {
goodFixBool = false;
return false;
}

// Wait to return a good fix until we know that it is good for a while
if (goodFixBool && pros::millis() - lastGoodFix > 2000) {
return true;
}

return false;
}

~GpsOdometry();
};
} // namespace Pronounce
Loading

0 comments on commit d9b8eb2

Please sign in to comment.