/
action.go
502 lines (346 loc) · 10.7 KB
/
action.go
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
package action
import (
"context"
//"fmt"
//"io"
)
type ServiceImpl struct {
Client ActionServiceClient
}
/*
Send command to arm the drone.
Arming a drone normally causes motors to spin at idle.
Before arming take all safety precautions and stand clear of the drone!
*/
func (s *ServiceImpl) Arm(ctx context.Context) (*ArmResponse, error) {
request := &ArmRequest{}
response, err := s.Client.Arm(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to disarm the drone.
This will disarm a drone that considers itself landed. If flying, the drone should
reject the disarm command. Disarming means that all motors will stop.
*/
func (s *ServiceImpl) Disarm(ctx context.Context) (*DisarmResponse, error) {
request := &DisarmRequest{}
response, err := s.Client.Disarm(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to take off and hover.
This switches the drone into position control mode and commands
it to take off and hover at the takeoff altitude.
Note that the vehicle must be armed before it can take off.
*/
func (s *ServiceImpl) Takeoff(ctx context.Context) (*TakeoffResponse, error) {
request := &TakeoffRequest{}
response, err := s.Client.Takeoff(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to land at the current position.
This switches the drone to 'Land' flight mode.
*/
func (s *ServiceImpl) Land(ctx context.Context) (*LandResponse, error) {
request := &LandRequest{}
response, err := s.Client.Land(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to reboot the drone components.
This will reboot the autopilot, companion computer, camera and gimbal.
*/
func (s *ServiceImpl) Reboot(ctx context.Context) (*RebootResponse, error) {
request := &RebootRequest{}
response, err := s.Client.Reboot(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to shut down the drone components.
This will shut down the autopilot, onboard computer, camera and gimbal.
This command should only be used when the autopilot is disarmed and autopilots commonly
reject it if they are not already ready to shut down.
*/
func (s *ServiceImpl) Shutdown(ctx context.Context) (*ShutdownResponse, error) {
request := &ShutdownRequest{}
response, err := s.Client.Shutdown(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to terminate the drone.
This will run the terminate routine as configured on the drone (e.g. disarm and open the parachute).
*/
func (s *ServiceImpl) Terminate(ctx context.Context) (*TerminateResponse, error) {
request := &TerminateRequest{}
response, err := s.Client.Terminate(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to kill the drone.
This will disarm a drone irrespective of whether it is landed or flying.
Note that the drone will fall out of the sky if this command is used while flying.
*/
func (s *ServiceImpl) Kill(ctx context.Context) (*KillResponse, error) {
request := &KillRequest{}
response, err := s.Client.Kill(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to return to the launch (takeoff) position and land.
This switches the drone into [Return mode](https://docs.px4.io/master/en/flight_modes/return.html) which
generally means it will rise up to a certain altitude to clear any obstacles before heading
back to the launch (takeoff) position and land there.
*/
func (s *ServiceImpl) ReturnToLaunch(ctx context.Context) (*ReturnToLaunchResponse, error) {
request := &ReturnToLaunchRequest{}
response, err := s.Client.ReturnToLaunch(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to move the vehicle to a specific global position.
The latitude and longitude are given in degrees (WGS84 frame) and the altitude
in meters AMSL (above mean sea level).
The yaw angle is in degrees (frame is NED, 0 is North, positive is clockwise).
Parameters
----------
latitudeDeg float64
longitudeDeg float64
absoluteAltitudeM float32
yawDeg float32
*/
func (s *ServiceImpl) GotoLocation(ctx context.Context, latitudeDeg float64, longitudeDeg float64, absoluteAltitudeM float32, yawDeg float32) (*GotoLocationResponse, error) {
request := &GotoLocationRequest{}
request.LatitudeDeg = latitudeDeg
request.LongitudeDeg = longitudeDeg
request.AbsoluteAltitudeM = absoluteAltitudeM
request.YawDeg = yawDeg
response, err := s.Client.GotoLocation(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command do orbit to the drone.
This will run the orbit routine with the given parameters.
Parameters
----------
radiusM float32
velocityMs float32
yawBehavior *OrbitYawBehavior
latitudeDeg float64
longitudeDeg float64
absoluteAltitudeM float64
*/
func (s *ServiceImpl) DoOrbit(ctx context.Context, radiusM float32, velocityMs float32, yawBehavior *OrbitYawBehavior, latitudeDeg float64, longitudeDeg float64, absoluteAltitudeM float64) (*DoOrbitResponse, error) {
request := &DoOrbitRequest{}
request.RadiusM = radiusM
request.VelocityMs = velocityMs
request.YawBehavior = *yawBehavior
request.LatitudeDeg = latitudeDeg
request.LongitudeDeg = longitudeDeg
request.AbsoluteAltitudeM = absoluteAltitudeM
response, err := s.Client.DoOrbit(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to hold position (a.k.a. "Loiter").
Sends a command to drone to change to Hold flight mode, causing the
vehicle to stop and maintain its current GPS position and altitude.
Note: this command is specific to the PX4 Autopilot flight stack as
it implies a change to a PX4-specific mode.
*/
func (s *ServiceImpl) Hold(ctx context.Context) (*HoldResponse, error) {
request := &HoldRequest{}
response, err := s.Client.Hold(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to set the value of an actuator.
Parameters
----------
index int32
value float32
*/
func (s *ServiceImpl) SetActuator(ctx context.Context, index int32, value float32) (*SetActuatorResponse, error) {
request := &SetActuatorRequest{}
request.Index = index
request.Value = value
response, err := s.Client.SetActuator(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to transition the drone to fixedwing.
The associated action will only be executed for VTOL vehicles (on other vehicle types the
command will fail). The command will succeed if called when the vehicle
is already in fixedwing mode.
*/
func (s *ServiceImpl) TransitionToFixedwing(ctx context.Context) (*TransitionToFixedwingResponse, error) {
request := &TransitionToFixedwingRequest{}
response, err := s.Client.TransitionToFixedwing(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Send command to transition the drone to multicopter.
The associated action will only be executed for VTOL vehicles (on other vehicle types the
command will fail). The command will succeed if called when the vehicle
is already in multicopter mode.
*/
func (s *ServiceImpl) TransitionToMulticopter(ctx context.Context) (*TransitionToMulticopterResponse, error) {
request := &TransitionToMulticopterRequest{}
response, err := s.Client.TransitionToMulticopter(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Get the takeoff altitude (in meters above ground).
Returns
-------
False
Altitude : float32
Takeoff altitude relative to ground/takeoff location (in meters)
*/
func (s *ServiceImpl) GetTakeoffAltitude(ctx context.Context) (*GetTakeoffAltitudeResponse, error) {
request := &GetTakeoffAltitudeRequest{}
response, err := s.Client.GetTakeoffAltitude(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Set takeoff altitude (in meters above ground).
Parameters
----------
altitude float32
*/
func (s *ServiceImpl) SetTakeoffAltitude(ctx context.Context, altitude float32) (*SetTakeoffAltitudeResponse, error) {
request := &SetTakeoffAltitudeRequest{}
request.Altitude = altitude
response, err := s.Client.SetTakeoffAltitude(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Get the vehicle maximum speed (in metres/second).
Returns
-------
False
Speed : float32
Maximum speed (in metres/second)
*/
func (s *ServiceImpl) GetMaximumSpeed(ctx context.Context) (*GetMaximumSpeedResponse, error) {
request := &GetMaximumSpeedRequest{}
response, err := s.Client.GetMaximumSpeed(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Set vehicle maximum speed (in metres/second).
Parameters
----------
speed float32
*/
func (s *ServiceImpl) SetMaximumSpeed(ctx context.Context, speed float32) (*SetMaximumSpeedResponse, error) {
request := &SetMaximumSpeedRequest{}
request.Speed = speed
response, err := s.Client.SetMaximumSpeed(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Get the return to launch minimum return altitude (in meters).
Returns
-------
False
RelativeAltitudeM : float32
Return altitude relative to takeoff location (in meters)
*/
func (s *ServiceImpl) GetReturnToLaunchAltitude(ctx context.Context) (*GetReturnToLaunchAltitudeResponse, error) {
request := &GetReturnToLaunchAltitudeRequest{}
response, err := s.Client.GetReturnToLaunchAltitude(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Set the return to launch minimum return altitude (in meters).
Parameters
----------
relativeAltitudeM float32
*/
func (s *ServiceImpl) SetReturnToLaunchAltitude(ctx context.Context, relativeAltitudeM float32) (*SetReturnToLaunchAltitudeResponse, error) {
request := &SetReturnToLaunchAltitudeRequest{}
request.RelativeAltitudeM = relativeAltitudeM
response, err := s.Client.SetReturnToLaunchAltitude(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}
/*
Set current speed.
This will set the speed during a mission, reposition, and similar.
It is ephemeral, so not stored on the drone and does not survive a reboot.
Parameters
----------
speedMS float32
*/
func (s *ServiceImpl) SetCurrentSpeed(ctx context.Context, speedMS float32) (*SetCurrentSpeedResponse, error) {
request := &SetCurrentSpeedRequest{}
request.SpeedMS = speedMS
response, err := s.Client.SetCurrentSpeed(ctx, request)
if err != nil {
return nil, err
}
return response, nil
}