-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mocks for siyi sdk and script to test perception class. (#230)
- Loading branch information
1 parent
c6cb9c9
commit b85ca78
Showing
7 changed files
with
218 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import rclpy | ||
from rclpy.node import Node | ||
from uavf_2024.imaging import Perception, PoseProvider | ||
from concurrent.futures import as_completed | ||
import traceback | ||
|
||
class PerceptionMinimalNode(Node): | ||
''' Receives input from every ongoing process. | ||
Output to PX4 Interface Node. | ||
''' | ||
|
||
def __init__(self) -> None: | ||
super().__init__('perception_test_node') | ||
self.perception = Perception(PoseProvider(self)) | ||
self.timer_period = 1.0 # seconds | ||
self.create_timer(self.timer_period, self.timer_cb) | ||
self.perception_futures = [] | ||
self.time_alive = 0 | ||
|
||
def log(self, msg): | ||
self.get_logger().info(msg) | ||
|
||
def timer_cb(self): | ||
self.perception_futures.append(self.perception.get_image_down_async()) | ||
self.time_alive += 1 | ||
if self.time_alive > 10: | ||
self.log('Shutting down...') | ||
self.log(f"results: {self.collect_results()}") | ||
self.destroy_node() | ||
rclpy.shutdown() | ||
|
||
def collect_results(self): | ||
detections = [] | ||
timeout = 2.0 | ||
try: | ||
for future in as_completed(self.perception_futures, timeout=timeout): | ||
detections.extend(future.result()) | ||
|
||
self.log(f"Successfully retrieved imaging detections: {detections}") | ||
except TimeoutError: | ||
self.log("Timed out waiting for imaging detections.") | ||
|
||
self.perception_futures = [] | ||
|
||
return detections | ||
|
||
|
||
|
||
def main(args=None) -> None: | ||
print('Starting commander node...') | ||
rclpy.init(args=args) | ||
node = PerceptionMinimalNode() | ||
rclpy.spin(node) | ||
node.destroy_node() | ||
rclpy.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
main() | ||
except Exception as e: | ||
traceback.print_exc() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .siyi_sdk import SIYISDK | ||
from .siyi_stream import SIYISTREAM | ||
from .siyi_stream import SIYISTREAM | ||
from .mocks import MockSIYISDK, MockSIYISTREAM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import numpy as np | ||
|
||
class MockSIYISTREAM: | ||
def __init__(self, server_ip : str = "192.168.144.25", port : int = 8554, name : str = "main.264", debug : bool = False): | ||
""" | ||
Params | ||
-- | ||
- server_ip [str] IP address of the camera | ||
- port: [int] UDP port of the camera | ||
- name: [str] name of the stream | ||
""" | ||
pass | ||
|
||
def connect(self): | ||
return True | ||
|
||
def disconnect(self): | ||
return | ||
|
||
def get_frame(self) -> np.ndarray | None: | ||
return np.random.randint(0,255, (1080, 1920, 3)).astype(np.float32) | ||
|
||
class MockSIYISDK: | ||
def __init__(self, server_ip="192.168.144.25", port=37260, debug=False): | ||
self.zoom = 1 | ||
self.attitude = (0,0,0) | ||
|
||
def resetVars(self): | ||
return True | ||
|
||
def connect(self, maxWaitTime=3.0): | ||
return True | ||
|
||
def disconnect(self): | ||
pass | ||
|
||
def checkConnection(self): | ||
pass | ||
|
||
def connectionLoop(self, t): | ||
pass | ||
|
||
def isConnected(self): | ||
return True | ||
|
||
def requestFirmwareVersion(self): | ||
return True | ||
|
||
def requestHardwareID(self): | ||
return True | ||
|
||
def requestGimbalAttitude(self): | ||
return True | ||
|
||
def requestGimbalInfo(self): | ||
return True | ||
|
||
def requestFunctionFeedback(self): | ||
return True | ||
|
||
def requestAutoFocus(self): | ||
return True | ||
|
||
def requestAbsoluteZoom(self, level, msg=None): | ||
return True | ||
|
||
def requestAbsolutePosition(self, yaw, pitch): | ||
self.attitude = (yaw, pitch, 0) | ||
|
||
def requestZoomIn(self): | ||
return True | ||
|
||
def requestZoomOut(self): | ||
return True | ||
|
||
def requestZoomHold(self): | ||
return True | ||
|
||
def requestLongFocus(self): | ||
return True | ||
|
||
def requestCloseFocus(self): | ||
return True | ||
|
||
def requestFocusHold(self): | ||
return True | ||
|
||
def requestCenterGimbal(self): | ||
return True | ||
|
||
def requestGimbalSpeed(self, yaw_speed:int, pitch_speed:int): | ||
return True | ||
|
||
def requestPhoto(self): | ||
return True | ||
|
||
def requestRecording(self): | ||
return True | ||
|
||
def requestFPVMode(self): | ||
return True | ||
|
||
def requestLockMode(self): | ||
return True | ||
|
||
def requestFollowMode(self): | ||
return True | ||
|
||
def getAttitude(self): | ||
return self.attitude | ||
|
||
def getAttitudeSpeed(self): | ||
return (0,0,0) | ||
|
||
def getFirmwareVersion(self): | ||
return (0,0,0) | ||
|
||
def getHardwareID(self): | ||
return 0 | ||
|
||
def getRecordingState(self): | ||
return 0 | ||
|
||
def getMotionMode(self): | ||
return 0 | ||
|
||
def getMountingDirection(self): | ||
return 0 | ||
|
||
def getFunctionFeedback(self): | ||
return 0 | ||
|
||
def getZoomLevel(self): | ||
return self.zoom | ||
|
||
def setAbsoluteZoom(self, level : float) -> bool: | ||
self.zoom = level | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters