Host Package documentation
AeroPrint GUI
- class host.aeroprint_gui.AeroPrintGUI
Bases:
object
AeroPrintGUI is a class that creates a GUI application using PyQt5. It initializes the application, sets up a menu bar, and provides functionality to open a settings dialog. The class also creates custom widgets and adds them to a ScrollContainer.
- app
The main application instance.
- Type:
QApplication
- sc
The main scroll container for the GUI.
- Type:
ScrollContainer
- settings_utility
Utility for accessing settings.
- Type:
SettingsUtility
- resource_path
Path to the resources file.
- Type:
str
Initializes the menu bar for the AeroPrint GUI. This method creates a menu bar and adds an “AeroPrint” menu to it. It also adds a “Settings” action to the “AeroPrint” menu, which triggers the open_settings method when selected.
- open_settings()
Opens the settings dialog. This method creates and displays a modal dialog window with the title “Settings”. The dialog contains a SettingsWidget and has a fixed size of 800x900 pixels.
- run()
Runs the main application logic. This method creates custom widgets, adds them to a ScrollContainer, and sets up navigation buttons. It initializes and displays the GUI, then starts the application’s event loop.
Custom Widgets:
MyWidget: A custom widget with a text box and a centered button.
MLUI: A widget initialized with specific parameters.
FlightWidget: A widget initialized with resource path and other parameters.
Navigation:
Adds a “Next” button to the first custom widget.
Adds a “Previous” button to the second custom widget.
ScrollContainer:
Adds the custom widgets to the ScrollContainer.
Creates page buttons for navigation.
Displays the ScrollContainer.
Exits:
Terminates the application when the event loop ends.
- host.aeroprint_gui.main(args=None)
Settings Wdget
- class host.gui.gui_pages.settings.settings_widget.SettingWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
A widget for displaying and editing a setting.
- setting
A dictionary containing the setting details.
- Type:
dict
- display_name
The display name of the setting.
- Type:
str
- description
The description of the setting.
- Type:
str
- default_value
The default value of the setting.
- Type:
any
- value
The current value of the setting.
- Type:
any
- type
The type of the setting (e.g., “text”, “number”, “boolean”, “file_path”).
- Type:
str
- layout
The layout of the widget.
- Type:
QVBoxLayout
- name_widget
The label displaying the setting’s name.
- Type:
QLabel
- edit_widget
The widget for editing the setting’s value.
- Type:
QWidget
- description_widget
The label displaying the setting’s description.
- Type:
QLabel
- class FilePickerWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
A custom widget that allows the user to select a folder from the file system.
- layout
The horizontal box layout for the widget.
- Type:
QHBoxLayout
- file_path_widget
The line edit widget to display the selected folder path.
- Type:
QLineEdit
- file_picker_button
The button to open the file dialog for folder selection.
- Type:
QPushButton
- open_file_dialog()
Opens a file dialog for the user to select a folder. If a folder is selected, the file path is set to the text of the file_path_widget.
- Returns:
None
- set_text(text)
Sets the text of the file_path_widget.
- Parameters:
text (str) – The text to set in the file_path_widget.
- text()
Retrieve the text from the file path widget.
- Returns:
The text from the file path widget.
- Return type:
str
- create_edit_widget()
Creates and returns a widget for editing based on the type of the setting.
- Returns:
A widget appropriate for the type of the setting.
QLineEdit: If the type is “text” or “number”.
QCheckBox: If the type is “boolean”.
FilePickerWidget: If the type is “file_path”.
- Return type:
QWidget
- get_setting()
Retrieve the current setting.
- Returns:
The current setting.
- save_value()
Save the value from the edit widget to the setting dictionary based on the type. The method updates the ‘value’ key in the ‘setting’ dictionary with the current value from the ‘edit_widget’. The type of the value is determined by the ‘type’ attribute.
Supported types:
“text”: Saves the text from the edit widget.
“number”: Converts the text from the edit widget to an integer and saves it.
“boolean”: Saves the checked state of the edit widget.
“file_path”: Saves the text from the edit widget as a file path.
- class host.gui.gui_pages.settings.settings_widget.SettingsWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
A widget for displaying and managing application settings.
- layout
The main layout of the widget.
- Type:
QVBoxLayout
- settings
A dictionary to store the settings loaded from a JSON file.
- Type:
dict
- json_path
The path to the settings JSON file.
- Type:
str
- load_settings()
Load settings from a JSON file located in the ‘aeroprint’ directory. This method constructs the path to the ‘settings.json’ file by finding the ‘aeroprint’ directory in the current file’s path. It then attempts to load the settings from this JSON file and assigns them to the ‘settings’ attribute.
- Raises:
ValueError – If the ‘aeroprint’ directory is not found in the path.
FileNotFoundError – If the ‘settings.json’ file is not found.
Displays:
QMessageBox.warning: If the ‘settings.json’ file is not found.
- save_settings()
Save the current settings to a JSON file. This method iterates through all widgets in the layout, checks if they are instances of SettingWidget, and calls their save_value method. It then attempts to write the settings to a file named ‘settings.json’. If the operation is successful, a success message is displayed. If an error occurs, an error message is shown.
- Raises:
Exception – If there is an error while saving the settings to the file.
- update_setting(key, value)
Update the setting with the given key to the specified value.
- Parameters:
key (str) – The key of the setting to update.
value (Any) – The new value for the setting.
aeroprint_gui.py: PyQt GUI with ROS node for initiating scans. UDRI DTC AEROPRINT
Flight Widget
- class host.gui.gui_pages.flight.flight_widget.CircleWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
A custom QWidget that displays a colored circle with text centered inside it. .. attribute:: text
The text to be displayed in the center of the circle.
- type:
str
- color
The color of the circle.
- Type:
QColor
- initUI()
- paintEvent(event)
- set_color(color)
- set_size(width, height)
- set_text(text)
- class host.gui.gui_pages.flight.flight_widget.FlightWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
A widget for the AEROPRINT application that integrates various components such as image exporting, parameter configuration, and ROS communication.
- resources_path
Path to the resources directory.
- Type:
str
- scroll_container
The scroll container widget.
- Type:
QWidget
- mlui
An instance of the MLUI class.
- Type:
object
- splash_path
Path to the splash image.
- Type:
str
- image_exporter
An instance of the ImageExporter class.
- Type:
- layout
The layout manager for the widget.
- Type:
QGridLayout
- qvio_widget
The QVIO widget for visual odometry.
- Type:
- parameter_widget
The widget for parameter configuration.
- Type:
- splash
The splash screen widget.
- Type:
QSplashScreen
- flashSplash()
Displays a splash screen for a specified duration. This method creates a QSplashScreen using the image specified by self.splash_path, shows it, and then closes it after a predefined amount of time (SPLASH_TIME).
- self.splash_path
Path to the splash screen image.
- Type:
str
- SPLASH_TIME
Duration in milliseconds for which the splash screen is displayed.
- Type:
int
- show()
Displays the widget. If the splash screen is enabled, it shows the splash screen for a specified duration before displaying the main widget. If the splash screen is not enabled, it directly displays the main widget.
- start_ros_thread(args=None)
Starts a new thread to update from ROS (Robot Operating System). This method initializes a new thread that runs the update_from_ros method. Optionally, it can take arguments to initialize the ROS client library.
- Parameters:
args (list, optional) – A list of command-line arguments to initialize the ROS client library. Defaults to None.
- update_from_ros()
Spins the ROS node to process incoming messages, then destroys the node and shuts down the ROS client library.
This method performs the following steps:
Spins the ROS node to process incoming messages.
Destroys the ROS node.
Shuts down the ROS client library.
Note
This method blocks until the node is destroyed.
- class host.gui.gui_pages.flight.flight_widget.GUItoROS(*args: Any, **kwargs: Any)
Bases:
Node
A ROS2 node that interfaces with a GUI to publish and subscribe to various topics. .. attribute:: qvio_widget
The widget for visual odometry.
- type:
QWidget
- image_exporter
The object responsible for exporting images.
- scroll_container
The container for scrolling through UI elements.
- mlui
The machine learning UI component.
- flight_radius_pub
Publisher for flight radius.
- Type:
Publisher
- object_height_pub
Publisher for object height.
- Type:
Publisher
- start_height_pub
Publisher for start height.
- Type:
Publisher
- scan_title_pub
Publisher for scan title.
- Type:
Publisher
- scan_ds_pub
Publisher for scan dataset.
- Type:
Publisher
- ready_pub
Publisher for ready status.
- Type:
Publisher
- kill_pub
Publisher for kill signal.
- Type:
Publisher
- will_print_pub
Publisher for print status.
- Type:
Publisher
- scan_start_sub
Subscription for scan start signal.
- Type:
Subscription
- scan_stop_sub
Subscription for scan stop signal.
- Type:
Subscription
- qos_profile
Quality of Service profile for subscriptions.
- Type:
QoSProfile
- camera_thread
Thread for updating the camera stream.
- Type:
Thread
- format
Image format for QVIO callback.
- qimage
QImage object for QVIO callback.
- pixmap
QPixmap object for QVIO callback.
- create_bool(val)
- create_float32(val)
- create_string(val)
- info(text)
- publish_flight_radius(rad)
- publish_kill(kill)
- publish_object_height(height)
- publish_ready(ready)
- publish_scan_ds(ds)
- publish_scan_title(title)
- publish_start_height(height)
- publish_will_print(val)
- qvio_callback(image_msg: sensor_msgs.msg.Image)
- scan_start_callback(msg)
- scan_stop_callback(msg)
- start_camera_thread()
- update_stream()
- class host.gui.gui_pages.flight.flight_widget.HeightGraphic(*args: Any, **kwargs: Any)
Bases:
QWidget
- paintEvent(e)
- set_line_endpoints(start_point, end_point)
- start_ros()
- class host.gui.gui_pages.flight.flight_widget.ImageExporter(resources_path)
Bases:
object
A class to handle exporting images to a specified directory structure. .. attribute:: resources_path
The base path where resources are stored.
- type:
str
- dataset
The name of the dataset to which images belong.
- Type:
str
- class_name
The name of the class within the dataset.
- Type:
str
- img_num
The current image number to be exported.
- Type:
int
- gap
The gap between image exports.
- Type:
int
- ready_to_dump
A flag indicating whether the exporter is ready to dump images.
- Type:
bool
- image_dump_path
The path where images will be dumped.
- Type:
str
- export_image(image)
- get_class()
- get_dataset()
- get_dump_status()
- set_dump_status(status, dataset=None, class_name=None)
- update_class(name)
- update_dataset(name)
- update_export_dir()
- class host.gui.gui_pages.flight.flight_widget.ParameterWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
A widget for configuring and managing flight parameters for a scanning operation. This widget allows the user to select a dataset, input scan details such as title, radius, height, and starting height, and control the readiness and landing state of the operation. It also provides visual feedback and updates to the user through various UI elements.
- g2r
An object responsible for communication with the flight controller.
- image_exporter
An object responsible for exporting images.
- resources_path
The path to the resources directory.
- dataset_dropdown
A dropdown menu for selecting datasets.
- dataset_name_textbox
A textbox for entering a custom dataset name.
- scan_name_textbox
A textbox for entering the scan title.
- ready_button
A button to indicate readiness for the scan.
- land_button
A button to land the flight.
- radius_spin_box
A spin box for setting the scan radius.
- height_spin_box
A spin box for setting the object height.
- start_height_spin_box
A spin box for setting the starting height of the object.
- start_description
A label displaying the start description of the scan.
- scan_title
The title of the scan.
- radius
The radius of the scan.
- height
The height of the object being scanned.
- start_height
The starting height of the object above the ground.
- dataset_selection_changed(index)
Handles the event when the dataset selection is changed in the dropdown.
- Parameters:
index (int) – The index of the selected item in the dataset dropdown.
Behavior:
If the selected index is the last item in the dropdown, the dropdown is disabled, the current index is set to 0, and the dataset name textbox is shown.
Otherwise, updates the dataset name based on the currently selected text in the dropdown.
- get_height()
Returns the height of the flight widget.
- Returns:
The height of the flight widget.
- Return type:
int
- get_radius()
Returns the radius value.
- Returns:
The radius value.
- Return type:
float
- get_scan_title()
Retrieve the title of the scan.
- Returns:
The title of the scan.
- Return type:
str
- get_start_height()
Retrieve the starting height.
- Returns:
The starting height.
- Return type:
float
- init_vals()
Initialize the default values for the flight widget. This method sets the initial state of various parameters by publishing default values to the corresponding topics.
Flight radius is set to 0.0.
Kill switch is set to False.
Object height is set to 0.0.
Ready state is set to False.
Scan title is set to an empty string.
Start height is set to 0.0.
Will print flag is set to False.
- land()
Prepares the system for landing by publishing a ‘not ready’ status and disabling the image exporter’s dump status.
This method performs the following actions:
Publishes a ‘not ready’ status to the g2r topic.
Sets the image exporter’s dump status to False.
- print_check(val)
Publishes a message indicating whether printing will occur.
- Parameters:
val (bool) – A boolean value indicating whether printing will occur.
- ready()
Publishes various flight parameters and sets the system to ready state.
This method publishes the following parameters to the g2r (ground to rover) communication system:
Flight radius
Object height
Start height
Scan title
After publishing these parameters, it sets the system to a ready state by publishing a ready signal.
- update_dataset_name(name)
Updates the dataset name in the GUI and notifies relevant components.
- Parameters:
name (str) – The new name of the dataset.
This method updates the dataset name in the image exporter and publishes the new dataset name to the scan dataset publisher.
- update_height(value)
Updates the height attribute and publishes the new height value.
- Parameters:
value (float) – The new height value to be set.
- update_radius(value)
Update the flight radius and publish the new value. This method updates the radius attribute with the given value, publishes the new flight radius to the g2r object, and updates the start description accordingly.
- Parameters:
value (float) – The new radius value to be set.
- update_scan_title(value)
Updates the scan title with the given value and performs related updates.
- Parameters:
value (str) – The new scan title to be set.
This method updates the scan title, publishes the new title, updates the start description, and updates the class of the image exporter with the new title.
- update_start_description()
Updates the start description text with formatted values for radius, height, and start height.
The description text is set to:
“Start scan at {r:.1f}m for an object that is approximately {h:.2f}m tall, starting at {s:.2f}m above the ground.”
The values are formatted as follows: - r: radius (formatted to 1 decimal place) - h: height (formatted to 2 decimal places) - s: start height (formatted to 2 decimal places)
- update_start_height(value)
Updates the start height value and publishes it.
- Parameters:
value (float) – The new start height value.
This method sets the start height to the given value, publishes the new start height using the g2r object, and updates the start description accordingly.
- class host.gui.gui_pages.flight.flight_widget.QVIOWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
QVIOWidget is a custom QWidget that displays video frames from a video source.
- image_exporter
An object responsible for exporting images.
- image_label
A QLabel widget to display the video frames.
- left
The left position of the widget.
- top
The top position of the widget.
- width
The width of the widget.
- height
The height of the widget.
- cap
A cv2.VideoCapture object to capture video frames.
- dump_images
A boolean indicating whether to dump images.
- img_num
An integer to keep track of the number of images.
- start_image_dump()
Enables the dumping of images by setting the dump_images attribute to True. This method is used to start the process of dumping images, which can be useful for debugging or logging purposes.
- stop_image_dump()
Stops the image dumping process by setting the dump_images flag to False.
- update_frame()
Capture a frame from the video stream, process it, and update the GUI with the new frame.
This method performs the following steps:
Captures a frame from the video stream.
If image export is enabled, exports the captured frame.
Converts the frame from BGR to RGB format.
Converts the RGB image to a QImage.
Converts the QImage to a QPixmap.
Scales the QPixmap to fit the widget’s dimensions while maintaining the aspect ratio.
Updates the image label with the new QPixmap.
- Returns:
None
- update_image_display(image_data)
Updates the image display with the provided image data.
- Parameters:
image_data (QPixmap) – The image data to be displayed on the QLabel.
- host.gui.gui_pages.flight.flight_widget.main(args=None) None
TensorFlow Widget
- class host.gui.gui_pages.tensor_flow.ml_ui.ImageScrollWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
- load_images()
- class host.gui.gui_pages.tensor_flow.ml_ui.LoadingPopup(*args: Any, **kwargs: Any)
Bases:
QWidget
- close_popup()
- show_popup()
- update_progress()
- class host.gui.gui_pages.tensor_flow.ml_ui.MLUI(*args: Any, **kwargs: Any)
Bases:
QWidget
- image_select(image_path)
- load_ui()
- load_ui_assets()
- model_exists()
- new_mit()
- on_load_ui_assets()
- present_ui_loader()
- renew()
- set_classes_directory()
- set_dataset(dataset)
- set_image_directory()
- set_model_directory()
- set_model_name(model_name)
- update_object_scan(scan_directory)
- with_new(dataset, model_name)
- class host.gui.gui_pages.tensor_flow.ml_ui.ModelInteractionToolkit(classes_directory, images_directory, model_tester, prediction_signal, model_directory)
Bases:
object
- assign_model_tester(model_tester)
- get_best_match()
- model_exists()
- class host.gui.gui_pages.tensor_flow.ml_ui.ModelInteractionWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
- load_model_popup()
- on_selector_changed(index)
- present_prediction_loader()
- set_mit(mit)
- set_next_button(next_button)
- set_prediction(prediction)
- show_model_prediction(prediction, certainty, model_exists)
- show_training_complete_popup()
- show_training_popup()
- train_model(selection, custom_text, predicted_name)
- class host.gui.gui_pages.tensor_flow.ml_ui.ScanOutputWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
- class host.gui.gui_pages.tensor_flow.ml_ui.SplashWidget(*args: Any, **kwargs: Any)
Bases:
QWidget
mesher.py: ROS node meshing output point cloud. UDRI DTC AEROPRINT
Mesher
- class host.mesher.Mesher(*args: Any, **kwargs: Any)
Bases:
Node
Mesher class responsible for processing point cloud data into a mesh and exporting it.
- dump_directory_callback(msg)
Callback function to handle directory dump messages. This function sets the directory and point cloud file location based on the incoming message data. :param msg: The message containing the directory path data. :type msg: Message
- export_complete_callback(msg)
Callback function that is triggered when the export process is complete. :param msg: The message object containing the export status. :type msg: Message
- Logs:
“Export complete callback: <msg.data>” to indicate the callback has been triggered.
“Meshing…” if the export was successful.
- Actions:
Calls the save() method if the export was successful.
- process()
Processes a point cloud file to generate a smoothed and filtered 3D mesh. Steps:
Reads the point cloud from the specified file location.
Estimates normals for the point cloud.
Creates a triangle mesh from the point cloud using alpha shapes.
Smooths the mesh using Laplacian smoothing.
Clusters connected triangles and removes small clusters.
Computes vertex normals for the final mesh.
Exports the final mesh to an STL file.
- self.pc_file_location
The file location of the point cloud.
- Type:
str
- self.directory
The directory where the output STL file will be saved.
- Type:
str
Returns: None
- save()
Processes the mesh and saves the output to a file. This method processes the mesh, constructs the output file path, logs the output path, publishes the file directory, and logs the completion of the mesh processing.
- host.mesher.main(args=None)