-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.ts
210 lines (196 loc) · 5.06 KB
/
action.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import { UUID } from "crypto";
import { Position } from "./coordinates.js";
export namespace BaseAction {
export type Params = object;
}
/**
* @interface Action an action that can be performed by the robot
* @template P specifies parameters that must be passed to the action
* @member params specifies parameters that will be passed to the action
*/
export interface BaseAction<P extends BaseAction.Params> {
readonly type: string;
/**
* specifies parameters that will be passed to the action
*/
readonly params: P;
/**
* used to identify when an action is being modified
*/
readonly uuid: UUID;
}
export namespace SetPose {
export type Params = Position & { radians?: boolean };
}
export interface SetPose
extends BaseAction<SetPose.Params & BaseAction.Params> {
readonly type: "set_pose";
}
export namespace MoveTo {
export interface Params extends BaseAction.Params {
readonly x: number;
readonly y: number;
readonly timeout: number;
readonly maxSpeed?: number;
readonly log?: boolean;
}
}
export interface MoveTo extends BaseAction<MoveTo.Params> {
readonly type: "move_to";
}
export namespace TurnTo {
export interface Params extends BaseAction.Params {
readonly x: number;
readonly y: number;
readonly timeout: number;
readonly reversed?: boolean;
readonly maxSpeed?: number;
readonly log?: boolean;
}
}
export interface TurnTo extends BaseAction<TurnTo.Params> {
readonly type: "turn_to";
}
export namespace Follow {
export interface Params extends BaseAction.Params {
readonly filePath: string;
readonly timeout: number;
readonly lookahead: number;
readonly reverse?: boolean;
readonly maxSpeed?: number;
readonly log?: boolean;
}
}
export interface Follow extends BaseAction<Follow.Params> {
readonly type: "follow";
}
export interface Roller extends BaseAction<BaseAction.Params> {
readonly type: "roller";
}
export interface Expand extends BaseAction<BaseAction.Params> {
readonly type: "expand";
}
export interface Shoot extends BaseAction<BaseAction.Params> {
readonly type: "shoot";
}
export interface PistonShoot extends BaseAction<BaseAction.Params> {
readonly type: "piston_shoot";
}
export interface Intake extends BaseAction<BaseAction.Params> {
readonly type: "intake";
}
export interface StopIntake extends BaseAction<BaseAction.Params> {
readonly type: "stop_intake";
}
export namespace Wait {
export interface Params extends BaseAction.Params {
readonly milliseconds: number;
}
}
export interface Wait extends BaseAction<Wait.Params> {
readonly type: "wait";
}
export namespace ActionTypeGuards {
export function isBaseAction(obj: any): obj is BaseAction<BaseAction.Params> {
return ["params", "type"].every((e) => e in obj);
}
/**
* @warn does not check params!
*/
export function isWait(obj: unknown): obj is Wait {
return isBaseAction(obj) && obj.type === "wait";
}
/**
* @warn does not check params!
*/
export function isStopIntake(obj: unknown): obj is StopIntake {
return isBaseAction(obj) && obj.type === "stop_intake";
}
/**
* @warn does not check params!
*/
export function isIntake(obj: unknown): obj is Intake {
return isBaseAction(obj) && obj.type === "intake";
}
/**
* @warn does not check params!
*/
export function isPistonShoot(obj: unknown): obj is PistonShoot {
return isBaseAction(obj) && obj.type === "piston_shoot";
}
/**
* @warn does not check params!
*/
export function isShoot(obj: unknown): obj is Shoot {
return isBaseAction(obj) && obj.type === "shoot";
}
/**
* @warn does not check params!
*/
export function isExpand(obj: unknown): obj is Expand {
return isBaseAction(obj) && obj.type === "expand";
}
/**
* @warn does not check params!
*/
export function isRoller(obj: unknown): obj is Roller {
return isBaseAction(obj) && obj.type === "roller";
}
/**
* @warn does not check params!
*/
export function isFollow(obj: unknown): obj is Follow {
return isBaseAction(obj) && obj.type === "follow";
}
/**
* @warn does not check params!
*/
export function isTurnTo(obj: unknown): obj is TurnTo {
return isBaseAction(obj) && obj.type === "turn_to";
}
/**
* @warn does not check params!
*/
export function isGoTo(obj: unknown): obj is MoveTo {
return isBaseAction(obj) && obj.type === "move_to";
}
/**
* @warn does not check params!
*/
export function isSetPose(obj: unknown): obj is SetPose {
return isBaseAction(obj) && obj.type === "set_pose";
}
/**
* @warn does not check params!
*/
export function isAction(obj: unknown): obj is Action {
return (
isBaseAction(obj) &&
[
"wait",
"stop_intake",
"intake",
"piston_shoot",
"shoot",
"expand",
"roller",
"follow",
"turn_to",
"move_to",
"set_pose",
].includes(obj.type)
);
}
}
export type Action =
| SetPose
| MoveTo
| TurnTo
| Follow
| Roller
| Expand
| Shoot
| PistonShoot
| Intake
| StopIntake
| Wait;