3
3
import static org .firstinspires .ftc .teamcode .Params .aem ;
4
4
import static org .firstinspires .ftc .teamcode .Params .pem ;
5
5
import static org .firstinspires .ftc .teamcode .Params .timeOutProtectionMills ;
6
- import static org .firstinspires .ftc .teamcode .utils .clients .DashboardClient .Blue ;
7
6
8
7
import androidx .annotation .NonNull ;
9
8
10
9
import com .acmerobotics .dashboard .canvas .Canvas ;
11
10
import com .acmerobotics .dashboard .telemetry .TelemetryPacket ;
12
11
import com .acmerobotics .roadrunner .Action ;
13
- import com .acmerobotics .roadrunner .Pose2d ;
14
- import com .acmerobotics .roadrunner .Vector2d ;
15
12
import com .acmerobotics .roadrunner .ftc .Actions ;
16
13
17
14
import org .firstinspires .ftc .teamcode .Global ;
29
26
import org .firstinspires .ftc .teamcode .utils .Functions ;
30
27
import org .firstinspires .ftc .teamcode .utils .PID .PidContent ;
31
28
import org .firstinspires .ftc .teamcode .utils .PID .PidProcessor ;
29
+ import org .firstinspires .ftc .teamcode .utils .Position2d ;
32
30
import org .firstinspires .ftc .teamcode .utils .Timer ;
31
+ import org .firstinspires .ftc .teamcode .utils .Vector2d ;
33
32
import org .firstinspires .ftc .teamcode .utils .annotations .DrivingPrograms ;
34
33
import org .firstinspires .ftc .teamcode .utils .clients .Client ;
35
34
import org .firstinspires .ftc .teamcode .utils .clients .DashboardClient ;
@@ -45,15 +44,15 @@ public class MecanumDrive implements DriverProgram {
45
44
private final PidProcessor pidProcessor ;
46
45
private final String [] ContentTags ;
47
46
48
- public final LinkedList <Pose2d > poseHistory = new LinkedList <>();
49
- public Pose2d RobotPosition ;
47
+ public final LinkedList <Position2d > poseHistory = new LinkedList <>();
48
+ public Position2d RobotPosition ;
50
49
public double BufPower =1f ;
51
50
52
51
public final Localizer localizer ;
53
52
54
53
public RobotState robotState ;
55
54
56
- public MecanumDrive (Pose2d RobotPosition ){
55
+ public MecanumDrive (Position2d RobotPosition ){
57
56
this .client =Global .client ;
58
57
this .pidProcessor =Global .robot .pidProcessor ;
59
58
this .robotState = Robot .robotState ;
@@ -79,7 +78,7 @@ public void update() {
79
78
RobotPosition = localizer .getCurrentPose ();
80
79
81
80
client .dashboard .deletePacketByTag ("RobotPosition" );
82
- client .dashboard .DrawRobot (RobotPosition , Blue , "RobotPosition" );
81
+ client .dashboard .DrawRobot (RobotPosition , DashboardClient . Blue , "RobotPosition" );
83
82
84
83
poseHistory .add (RobotPosition );
85
84
}
@@ -101,11 +100,11 @@ public void runOrderPackage(@NonNull LinkedList<DriveOrder> orders) {
101
100
102
101
Vector2d [] PoseList ;
103
102
PoseList =new Vector2d [commandLists .length +1 ];
104
- PoseList [0 ]=commandLists [0 ].pose .position ;
103
+ PoseList [0 ]=commandLists [0 ].pose .asVector () ;
105
104
Timer timer = new Timer ();
106
105
107
106
for (int i =0 ;i <commandLists .length ;++i ){
108
- PoseList [i +1 ]=commandLists [i ].NEXT ().position ;
107
+ PoseList [i +1 ]=commandLists [i ].NEXT ().asVector () ;
109
108
}
110
109
111
110
Actions .runBlocking (new Action () {
@@ -115,11 +114,11 @@ public boolean run(@NonNull TelemetryPacket telemetryPacket) {
115
114
DriveAction singleAction =commandLists [ID ];
116
115
singleAction .RUN ();
117
116
update ();
118
- motors .updateDriveOptions (RobotPosition .heading . toDouble () );
117
+ motors .updateDriveOptions (RobotPosition .heading );
119
118
120
119
BufPower = singleAction .BufPower ;
121
- double dY = singleAction .getDeltaTrajectory ().position . y ;
122
- double dX = singleAction .getDeltaTrajectory ().position . x ;
120
+ double dY = singleAction .getDeltaTrajectory ().y ;
121
+ double dX = singleAction .getDeltaTrajectory ().x ;
123
122
final double distance =Math .sqrt (dX * dX + dY * dY );
124
123
final double estimatedTime =distance /(Params .secPowerPerInch *BufPower );
125
124
client .changeData ("distance" ,distance );
@@ -128,12 +127,12 @@ public boolean run(@NonNull TelemetryPacket telemetryPacket) {
128
127
client .changeData ("DELTA" , singleAction .getDeltaTrajectory ().toString ());
129
128
130
129
timer .restart ();
131
- while ((Math .abs (RobotPosition .position . x -PoseList [ID +1 ].x )> pem )
132
- && (Math .abs (RobotPosition .position . y -PoseList [ID +1 ].y )> pem )
133
- && (Math .abs (RobotPosition .heading . toDouble () -singleAction .NEXT ().heading . toDouble () )> aem )){
130
+ while ((Math .abs (RobotPosition .x -PoseList [ID +1 ].x )> pem )
131
+ && (Math .abs (RobotPosition .y -PoseList [ID +1 ].y )> pem )
132
+ && (Math .abs (RobotPosition .heading -singleAction .NEXT ().heading )> aem )){
134
133
double progress =(timer .stopAndGetDeltaTime () / 1000.0 ) / estimatedTime * 100 ;
135
134
client .changeData ("progress" , progress +"%" );
136
- Pose2d aim = Functions .getAimPositionThroughTrajectory (singleAction ,RobotPosition ,progress );
135
+ Position2d aim = Functions .getAimPositionThroughTrajectory (singleAction ,RobotPosition ,progress );
137
136
138
137
if (timer .getDeltaTime ()>estimatedTime + timeOutProtectionMills && Params .Configs .useOutTimeProtection ){//保护机制
139
138
robotState = RobotState .BrakeDown ;
@@ -142,14 +141,14 @@ public boolean run(@NonNull TelemetryPacket telemetryPacket) {
142
141
}
143
142
144
143
if (Params .Configs .usePIDInAutonomous ){
145
- if (Math .abs (aim .position . x - RobotPosition . position .x )> pem
146
- || Math .abs (aim .position . y - RobotPosition . position .y )> pem
147
- || Math .abs (aim .heading . toDouble () - RobotPosition .heading . toDouble () )> aem
144
+ if (Math .abs (aim .x - RobotPosition .x )> pem
145
+ || Math .abs (aim .y - RobotPosition .y )> pem
146
+ || Math .abs (aim .heading - RobotPosition .heading )> aem
148
147
|| Params .Configs .alwaysRunPIDInAutonomous ){
149
148
//间断地调用pid可能会导致pid的效果不佳
150
- pidProcessor .registerInaccuracies (ContentTags [0 ], aim .position . x - RobotPosition . position .x );
151
- pidProcessor .registerInaccuracies (ContentTags [1 ], aim .position . y - RobotPosition . position .y );
152
- pidProcessor .registerInaccuracies (ContentTags [2 ], aim .heading . toDouble () - RobotPosition .heading . toDouble () );
149
+ pidProcessor .registerInaccuracies (ContentTags [0 ], aim .x - RobotPosition .x );
150
+ pidProcessor .registerInaccuracies (ContentTags [1 ], aim .y - RobotPosition .y );
151
+ pidProcessor .registerInaccuracies (ContentTags [2 ], aim .heading - RobotPosition .heading );
153
152
154
153
pidProcessor .update ();
155
154
@@ -158,13 +157,13 @@ public boolean run(@NonNull TelemetryPacket telemetryPacket) {
158
157
motors .headingPower +=pidProcessor .getFulfillment (ContentTags [2 ]);
159
158
}
160
159
}else {
161
- if (Math .abs (aim .position . x - RobotPosition . position .x )> pem
162
- || Math .abs (aim .position . y - RobotPosition . position .y )> pem
163
- || Math .abs (aim .heading . toDouble () - RobotPosition .heading . toDouble () )> aem ){
160
+ if (Math .abs (aim .x - RobotPosition .x )> pem
161
+ || Math .abs (aim .y - RobotPosition .y )> pem
162
+ || Math .abs (aim .heading - RobotPosition .heading )> aem ){
164
163
double [] fulfillment =new double []{
165
- (aim .position . x - RobotPosition . position .x )*(Params .secPowerPerInch )*BufPower /2 ,
166
- (aim .position . y - RobotPosition . position .y )*(Params .secPowerPerInch )*BufPower /2 ,
167
- (aim .heading . toDouble () > RobotPosition .heading . toDouble () ? BufPower /2 :-BufPower /2 )
164
+ (aim .x - RobotPosition .x )*(Params .secPowerPerInch )*BufPower /2 ,
165
+ (aim .y - RobotPosition .y )*(Params .secPowerPerInch )*BufPower /2 ,
166
+ (aim .heading > RobotPosition .heading ? BufPower /2 :-BufPower /2 )
168
167
};
169
168
170
169
motors .xAxisPower +=fulfillment [0 ];
@@ -173,7 +172,7 @@ public boolean run(@NonNull TelemetryPacket telemetryPacket) {
173
172
}
174
173
}
175
174
176
- motors .updateDriveOptions (RobotPosition .heading . toDouble () );
175
+ motors .updateDriveOptions (RobotPosition .heading );
177
176
}
178
177
179
178
if (ID !=commandLists .length -1 ){
@@ -207,7 +206,7 @@ public Chassis getClassic() {
207
206
}
208
207
209
208
@ Override
210
- public Pose2d getCurrentPose () {
209
+ public Position2d getCurrentPose () {
211
210
return RobotPosition ;
212
211
}
213
212
0 commit comments