|
6 | 6 | from enum import Enum
|
7 | 7 |
|
8 | 8 |
|
| 9 | +class OrbitYawBehavior(Enum): |
| 10 | + """ |
| 11 | + Yaw behaviour during orbit flight. |
| 12 | +
|
| 13 | + Values |
| 14 | + ------ |
| 15 | + HOLD_FRONT_TO_CIRCLE_CENTER |
| 16 | + Vehicle front points to the center (default) |
| 17 | +
|
| 18 | + HOLD_INITIAL_HEADING |
| 19 | + Vehicle front holds heading when message received |
| 20 | +
|
| 21 | + UNCONTROLLED |
| 22 | + Yaw uncontrolled |
| 23 | +
|
| 24 | + HOLD_FRONT_TANGENT_TO_CIRCLE |
| 25 | + Vehicle front follows flight path (tangential to circle) |
| 26 | +
|
| 27 | + RC_CONTROLLED |
| 28 | + Yaw controlled by RC input |
| 29 | +
|
| 30 | + """ |
| 31 | + |
| 32 | + |
| 33 | + HOLD_FRONT_TO_CIRCLE_CENTER = 0 |
| 34 | + HOLD_INITIAL_HEADING = 1 |
| 35 | + UNCONTROLLED = 2 |
| 36 | + HOLD_FRONT_TANGENT_TO_CIRCLE = 3 |
| 37 | + RC_CONTROLLED = 4 |
| 38 | + |
| 39 | + def translate_to_rpc(self): |
| 40 | + if self == OrbitYawBehavior.HOLD_FRONT_TO_CIRCLE_CENTER: |
| 41 | + return action_pb2.ORBIT_YAW_BEHAVIOR_HOLD_FRONT_TO_CIRCLE_CENTER |
| 42 | + if self == OrbitYawBehavior.HOLD_INITIAL_HEADING: |
| 43 | + return action_pb2.ORBIT_YAW_BEHAVIOR_HOLD_INITIAL_HEADING |
| 44 | + if self == OrbitYawBehavior.UNCONTROLLED: |
| 45 | + return action_pb2.ORBIT_YAW_BEHAVIOR_UNCONTROLLED |
| 46 | + if self == OrbitYawBehavior.HOLD_FRONT_TANGENT_TO_CIRCLE: |
| 47 | + return action_pb2.ORBIT_YAW_BEHAVIOR_HOLD_FRONT_TANGENT_TO_CIRCLE |
| 48 | + if self == OrbitYawBehavior.RC_CONTROLLED: |
| 49 | + return action_pb2.ORBIT_YAW_BEHAVIOR_RC_CONTROLLED |
| 50 | + |
| 51 | + @staticmethod |
| 52 | + def translate_from_rpc(rpc_enum_value): |
| 53 | + """ Parses a gRPC response """ |
| 54 | + if rpc_enum_value == action_pb2.ORBIT_YAW_BEHAVIOR_HOLD_FRONT_TO_CIRCLE_CENTER: |
| 55 | + return OrbitYawBehavior.HOLD_FRONT_TO_CIRCLE_CENTER |
| 56 | + if rpc_enum_value == action_pb2.ORBIT_YAW_BEHAVIOR_HOLD_INITIAL_HEADING: |
| 57 | + return OrbitYawBehavior.HOLD_INITIAL_HEADING |
| 58 | + if rpc_enum_value == action_pb2.ORBIT_YAW_BEHAVIOR_UNCONTROLLED: |
| 59 | + return OrbitYawBehavior.UNCONTROLLED |
| 60 | + if rpc_enum_value == action_pb2.ORBIT_YAW_BEHAVIOR_HOLD_FRONT_TANGENT_TO_CIRCLE: |
| 61 | + return OrbitYawBehavior.HOLD_FRONT_TANGENT_TO_CIRCLE |
| 62 | + if rpc_enum_value == action_pb2.ORBIT_YAW_BEHAVIOR_RC_CONTROLLED: |
| 63 | + return OrbitYawBehavior.RC_CONTROLLED |
| 64 | + |
| 65 | + def __str__(self): |
| 66 | + return self.name |
| 67 | + |
| 68 | + |
9 | 69 | class ActionResult:
|
10 | 70 | """
|
11 | 71 | Result type.
|
@@ -480,6 +540,57 @@ async def goto_location(self, latitude_deg, longitude_deg, absolute_altitude_m,
|
480 | 540 | raise ActionError(result, "goto_location()", latitude_deg, longitude_deg, absolute_altitude_m, yaw_deg)
|
481 | 541 |
|
482 | 542 |
|
| 543 | + async def do_orbit(self, radius_m, velocity_ms, yaw_behavior, latitude_deg, longitude_deg, absolute_altitude_m): |
| 544 | + """ |
| 545 | + Send command do orbit to the drone. |
| 546 | +
|
| 547 | + This will run the orbit routine with the given parameters. |
| 548 | +
|
| 549 | + Parameters |
| 550 | + ---------- |
| 551 | + radius_m : float |
| 552 | + Radius of circle (in meters) |
| 553 | +
|
| 554 | + velocity_ms : float |
| 555 | + Tangential velocity (in m/s) |
| 556 | +
|
| 557 | + yaw_behavior : OrbitYawBehavior |
| 558 | + Yaw behavior of vehicle (ORBIT_YAW_BEHAVIOUR) |
| 559 | +
|
| 560 | + latitude_deg : double |
| 561 | + Center point latitude in degrees. NAN: use current latitude for center |
| 562 | +
|
| 563 | + longitude_deg : double |
| 564 | + Center point longitude in degrees. NAN: use current longitude for center |
| 565 | +
|
| 566 | + absolute_altitude_m : double |
| 567 | + Center point altitude in meters. NAN: use current altitude for center |
| 568 | +
|
| 569 | + Raises |
| 570 | + ------ |
| 571 | + ActionError |
| 572 | + If the request fails. The error contains the reason for the failure. |
| 573 | + """ |
| 574 | + |
| 575 | + request = action_pb2.DoOrbitRequest() |
| 576 | + request.radius_m = radius_m |
| 577 | + request.velocity_ms = velocity_ms |
| 578 | + |
| 579 | + request.yaw_behavior = yaw_behavior.translate_to_rpc() |
| 580 | + |
| 581 | + |
| 582 | + request.latitude_deg = latitude_deg |
| 583 | + request.longitude_deg = longitude_deg |
| 584 | + request.absolute_altitude_m = absolute_altitude_m |
| 585 | + response = await self._stub.DoOrbit(request) |
| 586 | + |
| 587 | + |
| 588 | + result = self._extract_result(response) |
| 589 | + |
| 590 | + if result.result is not ActionResult.Result.SUCCESS: |
| 591 | + raise ActionError(result, "do_orbit()", radius_m, velocity_ms, yaw_behavior, latitude_deg, longitude_deg, absolute_altitude_m) |
| 592 | + |
| 593 | + |
483 | 594 | async def transition_to_fixedwing(self):
|
484 | 595 | """
|
485 | 596 | Send command to transition the drone to fixedwing.
|
|
0 commit comments