11package org .usfirst .frc .team199 .Robot2018 .commands ;
22
3+ import org .usfirst .frc .team199 .Robot2018 .Robot ;
34import org .usfirst .frc .team199 .Robot2018 .SmartDashboardInterface ;
45import org .usfirst .frc .team199 .Robot2018 .autonomous .AutoUtils ;
56import org .usfirst .frc .team199 .Robot2018 .subsystems .DrivetrainInterface ;
@@ -23,18 +24,53 @@ public AutoMoveTo(String[] args, DrivetrainInterface dt, SmartDashboardInterface
2324 for (String arg : args ) {
2425 if (AutoUtils .isDouble (arg )) {
2526 rotation = Double .valueOf (arg );
26- addSequential (new PIDTurn (rotation - AutoUtils .position .getRot (), dt , sd , pidMoveSrc ));
27+ double relrotation = rotation - AutoUtils .position .getRot ();
28+ addSequential (new PIDTurn (relrotation , dt , sd , pidMoveSrc ));
2729 AutoUtils .position .setRot (rotation );
2830 } else if (AutoUtils .isPoint (arg )) {
2931 point = AutoUtils .parsePoint (arg );
30- addSequential (new PIDTurn (Math .toDegrees (
31- Math .atan ((point [0 ] - AutoUtils .position .getX ()) / (point [1 ] - AutoUtils .position .getY ()))
32- - AutoUtils .position .getRot ()),
33- dt , sd , pidMoveSrc ));
34- addSequential (new PIDMove (
35- Math .sqrt (((point [0 ] - AutoUtils .position .getX ()) * (point [0 ] - AutoUtils .position .getX ())
36- + ((point [1 ] - AutoUtils .position .getY ()) * (point [1 ] - AutoUtils .position .getY ())))),
37- dt , sd , pidMoveSrc ));
32+ double deltaX = point [0 ] - AutoUtils .position .getX ();
33+ double deltaY = point [1 ] - AutoUtils .position .getY ();
34+ double atan = Math .toDegrees (Math .atan (deltaX / deltaY ));
35+ double relrotation = atan - AutoUtils .position .getRot ();
36+ addSequential (new PIDTurn (relrotation , dt , sd , pidMoveSrc ));
37+ double dX2 = deltaX * deltaX ;
38+ double dY2 = deltaY * deltaY ;
39+ double distance = Math .sqrt (dX2 + dY2 );
40+ addSequential (new PIDMove (distance , dt , sd , pidMoveSrc ));
41+ double x = AutoUtils .position .getX ();
42+ double y = AutoUtils .position .getY ();
43+ AutoUtils .position .setX (point [0 ]);
44+ AutoUtils .position .setY (point [1 ]);
45+ AutoUtils .position .setRot (Math .toDegrees (Math .atan ((point [0 ] - x ) / (point [1 ] - y ))));
46+ } else {
47+ throw new IllegalArgumentException ();
48+ }
49+ }
50+ }
51+
52+ public AutoMoveTo (String [] args ) {
53+ // requires(Drivetrain);
54+ double rotation ;
55+ double [] point = { 0 , 0 };
56+ for (String arg : args ) {
57+ if (AutoUtils .isDouble (arg )) {
58+ rotation = Double .valueOf (arg );
59+ double relrotation = rotation - AutoUtils .position .getRot ();
60+ addSequential (new PIDTurn (relrotation , Robot .dt , Robot .sd , Robot .dt .getDistEncAvg ()));
61+ AutoUtils .position .setRot (rotation );
62+ } else if (AutoUtils .isPoint (arg )) {
63+ point = AutoUtils .parsePoint (arg );
64+ double deltaX = point [0 ] - AutoUtils .position .getX ();
65+ double deltaY = point [1 ] - AutoUtils .position .getY ();
66+ double atan = Math .toDegrees (Math .atan (deltaX / deltaY ));
67+ double relrotation = atan - AutoUtils .position .getRot ();
68+ addSequential (new PIDTurn (relrotation , Robot .dt , Robot .sd , Robot .dt .getDistEncAvg ()));
69+
70+ double dX2 = deltaX * deltaX ;
71+ double dY2 = deltaY * deltaY ;
72+ double distance = Math .sqrt (dX2 + dY2 );
73+ addSequential (new PIDMove (distance , Robot .dt , Robot .sd , Robot .dt .getDistEncAvg ()));
3874 double x = AutoUtils .position .getX ();
3975 double y = AutoUtils .position .getY ();
4076 AutoUtils .position .setX (point [0 ]);
0 commit comments