Designing a GUI display for a real-time eye surgeon robot
For this project, we require a real-time graphical user interface (GUI) capable of receiving and displaying data via User Datagram Protocol (UDP). The GUI will showcase crucial information about the robot, including its position and timestamp. To achieve this, we'll need to implement a suitable framework that can handle the real-time data processing efficiently.
To install Qt Creator on your system, follow these steps:
Step 1: Download Qt Creator
Visit the official Qt website and download the Qt Creator installer for your operating system.
Step 2: Download Cmake and Qt5.15.2
after installing qt creator should install Cmake and qt5.15.2 for kits to then open the kits setting and choose Compiler GCC
Step 3: Launch Qt Creator
Once the installation is complete, you can launch Qt Creator from your system's application menu or by running the qtcreator
command in the terminal.
when creating a new project in qt creator:
you should choose:
1.in Projets chooose Application(Qt) then Qt Widgets Applicattion
2. write the name of the Project
3. choose in the build system: qmake and use default mode
Step 4: Install QCustomPlot Library
Download the QCustomPlot library from the official website or clone the repository from GitHub.
For Windows:
- If you downloaded the library, extract the archive to a convenient location.
- If you cloned the repository, navigate to the cloned directory.
For macOS and Linux:
- Clone the repository to a convenient location.
Step 5: Integrate QCustomPlot with Qt Creator
In Qt Creator, open your project.
For qmake Projects:
- Copy the
qcustomplot.h
andqcustomplot.cpp
files into your project directory. - Add these files to your
.pro
file:
In your Qt project's .pro
file, add the following lines to ensure support for GUI, core, widgets, and printing functionalities, and include QCustomPlot:
QT += core gui widgets printsupport
TARGET = YourProjectName
TEMPLATE = app
after adding all Libraries can build and run the app:
The udp::run() function in the provided code implements a UDP server that listens on a specific port (UDP_PORT) for incoming data packets. Upon receiving a packet, it processes the data and performs calculations to derive various parameters such as x, y, z coordinates, phi, psi angles, and d distance. These parameters are then logged into arrays (log_data1 and log_data2) based on a global flag (global_log). Additionally, the server updates vectors (qv_counter, qv_xValues, qv_yValues, etc.) and lists (existingVectors, existingVectors2, loglist, loglist2) used for plotting and logging data.
Instructions To set up and run the UDP server:
Clone this repository to your local machine. Ensure you have the necessary dependencies installed, including Qt. Compile and build the code using your preferred development environment. Run the compiled program to start the UDP server. The server will start listening on the specified port for incoming UDP packets.
This repository contains code for implementing UDP communication in a Qt application using threads. The udp_bridge.h header file defines a class UdpBridge responsible for handling UDP communication. The class includes a method setValue() to set values received from the UDP server. Additionally, the code snippet demonstrates how to connect the signal valueChanged emitted by the UdpBridge object to a slot receiverGuiSlot in the MainWindow class using the QObject::connect() function.
The UdpBridge class provides a bridge for UDP communication within a Qt application. It encapsulates functionality related to receiving data from a UDP server and emitting signals to notify other parts of the application about the received data. The setValue() method is used to set the received values, which can then be processed or displayed in the user interface. This repository houses code for real-time data reception via UDP (User Datagram Protocol) and subsequent processing to derive precise coordinates using inverse kinematics. To efficiently manage the received data and ensure its simultaneous usage and storage, a ping-pong structure is employed. This structure consists of two synchronized storage blocks, facilitating seamless data logging without loss.
The UDP module of this application continuously receives information in real-time. Upon receiving the data, the code executes inverse kinematics calculations to extract precise coordinates. However, handling real-time data presents a challenge when it comes to simultaneous storage and usage. To address this challenge, a ping-pong structure is implemented.
Ping-Pong Structure: The ping-pong structure ensures that data is never lost during the logging process. It comprises two synchronized storage blocks that alternate between being used for data logging and data processing. While one block is actively used for data logging, the other remains available for data processing. This seamless switching mechanism guarantees uninterrupted data flow, enabling both storage and usage of information simultaneously.
Data Logging: The application utilizes the ping-pong structure for efficient data logging. As data is received in real-time, it is immediately logged into one of the storage blocks. Meanwhile, the other block remains accessible for data processing or visualization. This approach ensures that no data is lost while maintaining the ability to analyze or visualize the received information.
Chart Drawing: To visualize the data on a chart, a rotating presentation approach is adopted. This method ensures that only a specific number of the latest data points are displayed on the chart at any given time. By continuously rotating through the stored data, the chart remains up-to-date with the latest information, providing real-time insights into the system's behavior.
Set up the UDP module to receive real-time data.
Configure the inverse kinematics calculations to derive precise coordinates from the received data.
Implement the ping-pong structure for efficient data logging and usage.
Use the rotating presentation approach to visualize the data on a chart, ensuring real-time insights.
At its core, QObject::connect() facilitates communication between different parts of a Qt application by establishing relationships between signals and slots. In this specific case, &(UDP.packet_recieve_handler) represents the sender object, which is an instance of the UdpBridge class encapsulating UDP communication functionality. This object emits a signal named valueChanged when new data is received from the UDP server.
The receiver object, &main_screen, represents an instance of the MainWindow class, which likely serves as the main window of the application. The receiverGuiSlot is a slot member function within this object, designated to handle incoming data and update the GUI accordingly.
Through the QObject::connect() function, the connection between the sender's valueChanged signal and the receiver's receiverGuiSlot slot is established. Consequently, whenever the UdpBridge object (UDP.packet_recieve_handler) emits the valueChanged signal, the receiverGuiSlot slot within the MainWindow object (main_screen) will be invoked automatically. This mechanism ensures real-time synchronization of data received via UDP with the graphical elements displayed in the application's user interface, enhancing user experience and interactivity.
QObject::connect(&(UDP.packet_recieve_handler), &UdpBridge::valueChanged, &main_screen, &MainWindow::receiverGuiSlot);
The object UDP is presumably an instance of a class responsible for handling UDP communication. In networked applications, UDP (User Datagram Protocol) is commonly used for transmitting data over a network with minimal overhead. By instantiating the UDP object, the application likely aims to establish communication with other devices or servers via UDP. This object would encapsulate functionalities such as creating sockets, sending and receiving data packets, and handling network-related operations. Utilizing the UDP object enables the application to implement UDP communication seamlessly, facilitating the exchange of data with remote endpoints.
On the other hand, the loggingThread object suggests the involvement of a separate thread dedicated to logging operations within the application. In multi-threaded programming, segregating tasks into distinct threads can enhance performance, responsiveness, and maintainability. By creating a dedicated loggingThread, the application can offload time-consuming logging operations to a separate execution context, preventing potential delays or blocking in the main thread. This approach ensures that the application remains responsive to user interactions while simultaneously logging relevant information in the background. Additionally, employing a separate logging thread can help organize and streamline the codebase, separating concerns related to data processing and logging. In summary, the instantiation of UDP and loggingThread objects signifies the modular design and functionality of the application. By encapsulating UDP communication and logging operations within dedicated objects or threads, the application can achieve efficient, responsive, and maintainable behavior, enhancing overall performance and user experience.
// Creating instances of main window, UDP, and logging thread
MainWindow main_screen;
udp UDP;
LoggingThread loggingThread;
// Starting UDP and logging threads
UDP.start();
loggingThread.start();
- Qt: 5.15.2
- QCustomPlot 1.3.2
- QMake: 3.1
- CMake: 3.18.4