Intelligent vehicle competition 3D simulation control system
Through the intelligent car competition 3D simulation control system, the Unity 3D module, WinForm module and simulation module are used, combined with ray detection and TCP communication, the complexity and difference problems of the existing technology are solved, and efficient intelligent car simulation and control are realized, reducing the Learning and development costs improve simulation accuracy and practicality.
Patent Information
- Application Number
- CN202410965659.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2024-11-12
AI Technical Summary
The existing smart car competition simulation platform is complex in installation and configuration, and is very different from the actual competition environment, which increases the cost of learning and participation and limits the popularization and innovation of smart car technology.
A smart car racing 3D simulation control system was designed, including Unity 3D module, WinForm module and simulation module. Through ray detection, TCP communication and multiple sensor simulations, it provides highly realistic 3D environment and physical simulation, and supports C language programming. It lowers the user threshold and realizes real-time monitoring and control of smart car data.
The system provides highly realistic 3D environment and physical simulation, lowers the threshold for users, supports multiple vehicle models to simulate, improves the accuracy and practicality of simulation, simplifies the learning and development process of smart car technology, and reduces costs and risks. .
Smart Images

Figure CN118940486A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of computer simulation, in particular to a 3D simulation control system for intelligent car competition. Background Art
[0002] With the continuous development of science and technology, smart cars with cameras have been widely used in many fields. However, for beginners and competition participants, building and maintaining a real smart car hardware system and the corresponding competition environment not only requires high costs, but also involves complex hardware assembly and software debugging processes. This has limited the popularization and promotion of smart car technology to a certain extent, especially in a learning environment with limited resources.
[0003] At present, although existing technologies have built virtual simulation platforms for smart cars by combining kinematic simulation models such as CoppeliaSim with mathematical modeling software MATLAB, these solutions still face some challenges in practical applications. First, the installation and configuration process of these platforms is relatively complicated, requiring users to have certain professional knowledge and skills. Second, although these platforms can simulate images, they mainly use the Lua scripting language to process simulation modules, which is different from the C language embedded development environment commonly used by contestants in actual competitions.
[0004] Therefore, although the existing simulation solutions can verify the effectiveness of certain algorithms to a certain extent, it is still difficult for contestants to transplant the simulated code to the actual competition car and to build the simulation environment itself. These challenges not only increase the cost of learning and participation, but also affect the rapid iteration and innovation of smart car technology. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide a 3D simulation control system for intelligent car competition, which is convenient for novices to get started and use without any threshold.
[0006] In order to solve the above technical problems, the technical solution of the present invention is as follows:
[0007] A 3D simulation control system for intelligent car competition, comprising:
[0008] Unity 3D module, used to obtain car data and detect collision objects through raycast;
[0009] WinForm module, used to receive and display car data and receive user control instructions;
[0010] The simulation module is used to obtain the car data through TCP communication, and execute the code to process the car data to obtain the running results. The running results are transmitted back to the Unity 3D module through the WinForm module, and the car is controlled according to the running results.
[0011] Furthermore, the car data is obtained and the collision objects are detected by raycasting, including:
[0012] Get the car camera image;
[0013] Receive the output data of the simulated gyroscope sensor and obtain the position coordinates of the car in the world coordinate system;
[0014] Acquire the real-time rotation speed data of the wheel model of the trolley from the simulation encoder;
[0015] The car data is obtained through the car camera image, the car world coordinates and the rotation speed of the car wheel model;
[0016] The car is taken as the center point in the car's world coordinate system, and a laser ranging sensor is used to emit a ray in front of the car to determine the distance between the object and the sensor and detect the collision object.
[0017] Furthermore, the output data of the simulated gyroscope sensor is received to obtain the position coordinates of the car in the world coordinate system, including:
[0018] Determine the parameters of the gyroscope sensor, including measurement range, accuracy, and sampling frequency;
[0019] According to the sampling frequency, the measurement data is periodically extracted from the gyroscope sensor;
[0020] Convert the angular velocity data in the measurement data into the attitude and position changes of the car;
[0021] Based on the initial car position and direction information, calculate the position coordinates of the car in the world coordinate system.
[0022] Further, according to Calculate the position coordinates of the car in the world coordinate system;
[0023] Among them, x0, y0, and z0 represent the x, y, and z coordinates of the initial position of the car in the world coordinate system respectively; n ,y n 、z n They represent the x, y, and z coordinates of the car in the world coordinate system after n samplings respectively; d x ,d y ,d z Respectively represent the unit vector components of the initial direction of the car in the x, y, and z directions; ω irepresents the angular velocity obtained by the i-th sampling; Δt represents the sampling time interval; n represents the number of sampling times.
[0024] Furthermore, the real-time rotation speed data of the wheel model of the trolley is obtained from the simulation encoder, including:
[0025] Determine the type and resolution parameters of the simulation encoder to match the characteristics of the trolley wheel model;
[0026] Establish the connection between the simulation encoder and the monitoring system and determine the sampling frequency to collect the encoder value;
[0027] The angle that the wheel rotates per unit time is converted into a standard angle according to the encoder value and the preset coefficient;
[0028] Calculate the rotation speed of the wheel model using the standard angle and wheel radius.
[0029] Furthermore, the rotation speed calculation formula of the small wheel model is:
[0030]
[0031] Among them, v represents the rotation speed of the small wheel model; R represents the radius of the small wheel; π represents pi; θ represents the angle rotated by the wheel; t represents time.
[0032] Furthermore, the car is set as the center point of the world coordinate system, the laser ranging sensor is enabled, and a ray is emitted directly in front of the car. By measuring the time or signal change of the reflected return, the distance between the object and the sensor is calculated, so as to detect and determine the position and distance of the collision object, including:
[0033] Install the laser distance sensor on the trolley;
[0034] The laser distance measuring sensor emits laser rays in front of the car at a predetermined frequency, and controls the emission angle and direction of the rays to ensure that the rays are directed straight toward the front of the car;
[0035] When the rays hit an object and reflect back, the laser range sensor measures the return time of the pulse;
[0036] Calculate the distance between the object and the sensor based on the return time of the pulse and the propagation speed of the laser;
[0037] The collision object is detected based on the distance between the object and the sensor.
[0038] Furthermore, the distance calculation formula between the object and the sensor is:
[0039]
[0040] Among them, d represents the distance between the object and the laser ranging sensor; c represents the speed of light in a vacuum; and t represents the time from the emission to the reception of the laser pulse.
[0041] Furthermore, receiving and displaying the car data and receiving user control instructions include:
[0042] Receive the car data of the Unity 3D module through the UnityWebPlayer plug-in interface, including camera image data, position, speed and car sensor values;
[0043] The PictureBox control and Label control are used to display the camera image data and the car sensor value respectively, and the user sets the car through buttons to receive user control instructions.
[0044] Furthermore, the car data is received and the code is executed to process the car data to obtain the operation results, including:
[0045] Get the data sent by the WinForm module from the TCP connection and parse it according to the predetermined data format to obtain the parsed data;
[0046] Extract the parsed data, write the corresponding processing logic code, and read the car data in the buffer;
[0047] In the processing code, logical judgment, mathematical operations and data conversion are performed to obtain the results of the car's state and behavior;
[0048] According to the status and behavior results of the car, determine the result data of the car's operation and state changes;
[0049] The operation results are obtained based on the result data of the car's operation status and state changes.
[0050] The above solution of the present invention includes at least the following beneficial effects:
[0051] Through the rendering and physics engine capabilities of the Unity 3D module, the system can provide highly realistic 3D environments and physical simulations, including friction, inertia, collision, etc., making the simulation results closer to the real situation. The system supports image simulation and simulation of multiple sensors such as encoders, gyroscopes, and laser ranging, providing developers with a comprehensive testing environment that helps verify the perception and control capabilities of smart cars in complex environments.
[0052] By providing an open interface, the system allows users to use C language to write and run simulation code, read various data of the simulation car and control the operation of the car. At the same time, it is compatible with mature IDEs and provides runnable templates, which lowers the threshold for users to get started with simulation. In addition, the open communication interface also supports simulation in languages such as Python to meet the needs of different users.
[0053] Users can freely change the track, modify the lighting conditions, adjust the camera angle and other parameters to make the simulation environment closer to the actual competition scene, thereby improving the accuracy and practicality of the simulation. The system supports the simulation of a variety of models such as three-wheeled smart cars (differential steering) and four-wheeled smart cars (differential steering and steering gear angle), meeting the development and testing needs of different models. By encapsulating the project into an executable exe file, the system can be run directly on the Windows platform without additional configuration and installation steps, which reduces the threshold for novices. The WinForm module receives and displays the car data in real time, and can quickly respond to user control instructions. Combined with TCP communication technology, efficient transmission between the car data and the user simulation module is achieved. In addition, the running results of the simulation module can be fed back to the Unity 3D module in real time through the WinForm module to achieve real-time monitoring and control adjustment of the car status. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 The present invention provides a flow chart of a 3D simulation control system for a smart car competition.
[0055] Figure 2 The present invention provides a flow chart of obtaining car data and detecting collision objects through rays in a 3D simulation control system for intelligent car competition provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0056] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0057] like Figure 1 and Figure 2 As shown, an embodiment of the present invention provides a 3D simulation control system for smart car competition, comprising:
[0058] Unity 3D module 11, used to obtain car data and detect collision objects through ray;
[0059] WinForm module 12, used for receiving and displaying car data and receiving user control instructions;
[0060] The simulation module 13 is used to obtain the car data through TCP communication, and execute the code to process the car data to obtain the operation result, transmit the operation result back to the Unity 3D module through the WinForm module, and realize the control of the car according to the operation result.
[0061] In an embodiment of the present invention, the Unity 3D module acquires the car data in real time and detects collision objects through ray detection to achieve accurate environmental perception and obstacle detection. The WinForm module is responsible for receiving and displaying this data, providing users with an intuitive view of the car status and environment. The WinForm module not only displays data, but also receives user control instructions, allowing users to intervene and adjust the car behavior in real time. This interactivity enhances the user experience and enables users to adjust and control the car as needed. The simulation module acquires the car data through TCP communication and executes code processing to simulate the car's behavior and environmental response. This simulation capability allows testing and development without an actual car, reducing costs and risks. The three modules (Unity 3D, WinForms, and simulation module) work together to form a complete car control and processing system. This integration improves the overall efficiency and response speed of the system and ensures the accuracy and real-time nature of the data. The system design allows modules to be added or modified to adapt to different needs and scenarios.
[0062] For example, the Unity 3D module can be extended to support more complex environment simulations, or the simulation module can be modified to handle more advanced car behavior algorithms. With the simulation module, developers can quickly test and adjust the car behavior in a virtual environment without actually deploying the car. This significantly shortens the development cycle and reduces testing costs. The system is extensively tested in a simulation environment, which can detect and fix potential problems before actual deployment. This helps ensure the safety and reliability of the car in actual operation.
[0063] In a preferred embodiment of the present invention, obtaining the vehicle data and detecting the collision object by ray detection includes:
[0064] Get the car camera image;
[0065] Receive the output data of the simulated gyroscope sensor and obtain the position coordinates of the car in the world coordinate system;
[0066] Acquire the real-time rotation speed data of the wheel model of the trolley from the simulation encoder;
[0067] The car data is obtained through the car camera image, the car world coordinates and the rotation speed of the car wheel model;
[0068] The car is taken as the center point in the car's world coordinate system, and a laser ranging sensor is used to emit a ray in front of the car to determine the distance between the object and the sensor and detect the collision object.
[0069] In an embodiment of the present invention, a virtual camera is equipped on the car model in the Unity 3D module. The camera simulates the function of a real camera, captures the field of view in front of the car, and generates corresponding image data. The output data of the simulated gyroscope sensor is received to obtain the position coordinates of the car in the world coordinate system. The virtual gyroscope sensor is integrated in the simulation system, which can output the precise position coordinates of the car in the three-dimensional world coordinate system constructed by the Unity 3D module in real time. The wheel model of the car is equipped with a simulated encoder, which can monitor and record the rotation speed of the wheel in real time. These data reflect the motion state of the car. The car data is obtained by the car camera image, the car world coordinates and the rotation speed of the wheel model of the car. The step integrates the various data (camera image, position coordinates, wheel speed) obtained above to form a data set that fully reflects the current state of the car. In the Unity 3D module, with the car as the center, the working mode of the laser range finder sensor is simulated to emit rays to the front of the car. When the ray intersects with other objects in the scene, the distance between the object and the sensor can be determined, thereby detecting potential collision objects.
[0070] It provides visual perception capabilities, enabling the car to identify paths and obstacles based on camera images, providing basic data for intelligent navigation and obstacle avoidance. Position coordinate data helps the car to accurately locate in space and is key information for path planning and tracking. Real-time monitoring of wheel rotation speed provides important feedback for the control algorithm, helping to adjust the car's motion strategy and speed control. The integration of multiple sensor data provides comprehensive and accurate input information for the smart car's decision-making system, improving the smart car's environmental perception and decision-making accuracy. The simulation of the laser rangefinder sensor realizes the rapid detection and distance measurement of the object in front, provides important obstacle avoidance information for the smart car, and enhances the safety and navigation accuracy of the smart car.
[0071] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0072] In Unity 3D, make sure there is a camera component attached to the game object representing the car. This camera is used to simulate the car's vision system. Set a render texture for the camera so that the camera's output is not displayed directly on the screen, but rendered to this texture. This allows the camera's image data to be accessed in Unity's scripts. In Unity's scripts, get the car's camera image by accessing the camera's render texture. It involves reading the pixel data of the render texture. Although it is more complicated to operate the pixel data directly, the image can be used indirectly by using the render texture as part of the material. In the simulation environment, simulate the output data of the gyroscope, which includes angular velocity information, indicating the rotation speed of the car around each axis. Combined with the initial position and direction of the car, to get the complete position and direction information of the car at the current moment. Output the car's position coordinates to the required location, such as a variable in Unity or a script for ray detection. Configure the simulated encoder in the simulation environment, setting parameters such as resolution and sampling frequency. Read the output data of the simulated encoder at regular intervals, which represents the relative position or increment of the wheel rotation.
[0073] Calculate the real-time rotation speed of the wheel model of the trolley according to the encoder data and the preset time interval. It involves converting the position change output by the encoder into an angle change, and further converting it into a speed unit. Pack the camera image, position coordinates, and rotation speed data into a data structure or class instance. Perform necessary preprocessing or analysis on these data, such as image recognition, position correction, or speed filtering. In Unity, the laser range sensor component is not directly provided, and its function can be simulated through ray detection. First, determine a point representing the sensor position (usually the front center of the trolley). A ray is emitted from the sensor position point to the front of the trolley. The ray is emitted in the scene in the specified direction until it encounters a collision body. If the ray intersects with a collision body, the Physics.Raycast method returns the information of the intersection point (such as distance and collision body). Based on the information of the ray intersection point, calculate the distance between the object and the sensor. This distance is the result of the laser range sensor measurement. According to the results of the ray detection, determine whether the trolley collides with the object in front, and perform corresponding logical processing, such as deceleration, obstacle avoidance, or alarm.
[0074] In a preferred embodiment of the present invention, receiving output data of the simulated gyroscope sensor and obtaining the position coordinates of the vehicle in the world coordinate system includes:
[0075] Determine the parameters of the gyroscope sensor, including measurement range, accuracy, and sampling frequency;
[0076] According to the sampling frequency, the measurement data is periodically extracted from the gyroscope sensor;
[0077] Convert the angular velocity data in the measurement data into the attitude and position changes of the car;
[0078] Based on the initial car position and direction information, calculate the position coordinates of the car in the world coordinate system.
[0079] In an embodiment of the present invention, before simulation, key parameters of the gyroscope sensor are set first, and these parameters determine the performance and measurement accuracy of the sensor. The measurement range defines the maximum and minimum values that the sensor can detect, indicating the accuracy of the sensor measurement, and the sampling frequency determines the speed at which the sensor obtains data. According to the preset sampling frequency, the system will regularly obtain measurement data from the gyroscope sensor. These data mainly include angular velocity and acceleration, etc. The angular velocity data output by the gyroscope sensor is converted into the attitude change information of the car through a specific algorithm (such as quaternion), including pitch angle, yaw angle and roll angle, etc., and then the position change of the car can be inferred. Combined with the initial car position and direction information, as well as the attitude and position changes obtained by gyroscope data conversion, the real-time position coordinates of the car in the simulation environment can be calculated.
[0080] By setting the parameters of the gyroscope sensor, it can be ensured that the data measurement in the simulation process meets the actual needs and ensures the accuracy and reliability of the measurement. Timed sampling ensures the real-time and continuity of the data, and accurate angular velocity data conversion enables the posture changes of the car to be accurately reflected in the actual simulation environment, improving the realism and credibility of the simulation. Accurately calculating the position coordinates of the car in the world coordinate system is the basis for realizing advanced functions such as intelligent vehicle path planning, navigation and obstacle avoidance, and also provides accurate position feedback for verifying the effectiveness of the control algorithm.
[0081] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0082] Set the measurement accuracy of the gyroscope sensor, that is, the accuracy of the sensor's measurement results. The higher the accuracy, the closer the measurement results are to the true value. Determine the frequency at which the gyroscope sensor acquires data, that is, how many times per second the data is collected. The higher the sampling frequency, the denser the acquired data is, and the more accurately the attitude changes of the car can be reflected. According to the preset sampling frequency, the measurement data is regularly acquired from the gyroscope sensor. Involves writing a loop or timer to read the sensor output at fixed time intervals. Convert the angular velocity data output by the gyroscope sensor into attitude change information of the car through a specific algorithm (such as the quaternion algorithm). This includes calculating attitude parameters such as pitch, yaw, and roll. Use the converted attitude parameters to update the current attitude of the car in the simulation environment, which involves applying the attitude parameters to the 3D model or simulation representation of the car to reflect its actual attitude. Set the initial position coordinates and orientation of the car in the simulation environment. This is a fixed value used to represent the position and orientation of the car at the beginning of the simulation. Based on the attitude changes obtained by gyroscope data conversion, the attitude changes (such as angular velocity) are converted into position changes (such as linear velocity or displacement). Combined with the initial position and orientation information, as well as the attitude and position changes obtained by gyroscope data conversion, the position coordinates of the car in the simulation environment are calculated in real time. The calculated car position coordinates are applied to the car model or simulation representation in the simulation environment. Verify the accuracy and reliability of the calculation results to ensure that the behavior of the car in the simulation environment is consistent with expectations. Use the calculated position coordinates as input for advanced functions such as intelligent car path planning, navigation, and obstacle avoidance. Verify the effectiveness of the control algorithm and evaluate the algorithm performance by comparing the car position output by the algorithm with the car position in the actual simulation environment.
[0083] In a preferred embodiment of the present invention, according to Calculate the position coordinates of the car in the world coordinate system;
[0084] Among them, x0, y0, and z0 represent the x, y, and z coordinates of the initial position of the car in the world coordinate system respectively; n ,y n 、z n They represent the x, y, and z coordinates of the car in the world coordinate system after n samplings respectively; d x ,d y ,d z Respectively represent the unit vector components of the initial direction of the car in the x, y, and z directions; ω i represents the angular velocity obtained by the i-th sampling; Δt represents the sampling time interval; n represents the number of sampling times.
[0085] In the embodiment of the present invention, x0, y0, and z0 respectively represent the initial positions of the car in the world coordinate system, which are the starting points of the car's movement.x ,d y ,d z Represents the unit vector components of the initial motion direction of the car in the x, y, and z directions. These components reflect the direction of the car at the start. Each sampling will obtain the current angular velocity ω i , represents the rotation speed of the car at the i-th sampling. The sampling time interval Δt is fixed and represents the time difference between two samplings. According to the angular velocity ω obtained at each sampling i , combined with the direction vector component and the sampling time interval, the displacement of the car in each direction is calculated. This displacement is the product of the angular velocity and the time interval, and then multiplied by the direction vector component to obtain the movement distance in the x, y, and z directions. By accumulating the displacement calculated for each sampling, the total displacement of the car from the initial position to the current sampling moment is obtained. Adding this total displacement to the initial position, the current position x of the car in the world coordinate system is obtained. n ,y n 、z n .
[0086] Accurately track the position changes of the car in the world coordinate system, taking into account the influence of angular velocity on the position, making the position update more accurate. By sampling the angular velocity in real time, the direction changes of the car during movement can be captured, so as to flexibly adjust the position coordinates of the car. Due to the use of periodic sampling, the position of the car can be updated in real time, which is suitable for application scenarios that require fast response. Applicable to three-dimensional space, it can fully reflect the position changes of the car in the three directions of x, y, and z. Not only suitable for linear motion, but also can handle complex motion trajectories of the car in three-dimensional space, such as turning, climbing or diving.
[0087] In a preferred embodiment of the present invention, obtaining real-time rotation speed data of the wheel model of the trolley from the simulation encoder includes:
[0088] Determine the type and resolution parameters of the simulation encoder to match the characteristics of the trolley wheel model;
[0089] Establish the connection between the simulation encoder and the monitoring system and determine the sampling frequency to collect the encoder value;
[0090] The angle that the wheel rotates per unit time is converted into a standard angle according to the encoder value and the preset coefficient;
[0091] The rotation speed of the trolley wheel model is calculated by the standard angle and the wheel radius of the trolley; the rotation speed calculation formula of the trolley wheel model is:
[0092]
[0093] Among them, v represents the rotation speed of the small wheel model; R represents the radius of the small wheel; π represents pi; θ represents the angle rotated by the wheel; t represents time.
[0094] In an embodiment of the present invention, in a simulation environment, the corresponding encoder type (such as absolute type) and the set resolution are selected according to the characteristics of the trolley wheel model to ensure that the slight rotation of the wheel can be accurately captured. A connection between the simulation encoder and the monitoring system is established to ensure that data can be transmitted in real time. The sampling frequency is determined, that is, how often the encoder value is collected to ensure the continuity and accuracy of the data. The encoder will output a series of values representing the relative or absolute position of the wheel rotation. According to the encoder value and the preset coefficient, these values are converted into standard angle representations for subsequent calculations. The standard angle and the radius of the trolley wheel are substituted to calculate the rotation speed of the trolley wheel model. Each speed represents the distance the wheel rotates in a unit time, which is an important parameter for evaluating the motion state of the wheel.
[0095] By simulating the encoder, the real-time rotation speed of the trolley wheel model can be accurately monitored, providing accurate data for subsequent control and analysis. Accurate rotation speed data helps improve the accuracy of the entire simulation system and makes the simulation results closer to the actual situation. Real-time rotation speed data provides a basis for optimizing the trolley control strategy. The control parameters can be adjusted according to the speed feedback to achieve more precise control. Rotation speed monitoring and control strategy testing in the simulation environment do not require the actual deployment of the trolley, reducing testing costs and risks. The simulation environment allows easy modification of encoder type, resolution and other parameters to adapt to different trolley wheel models and monitoring requirements, enhancing the flexibility of the system.
[0096] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0097] Select the corresponding encoder type, such as an absolute encoder, according to the characteristics of the wheel model of the trolley (such as size, speed range, etc.). Absolute encoders can provide absolute position information of the wheel and are suitable for applications that require precise position control. According to the requirements of simulation accuracy, set the resolution of the encoder, that is, the minimum position change that the encoder can distinguish. The higher the resolution, the finer the data output by the encoder, and the more accurately it can capture the slight rotation of the wheel. Design the data interface between the simulation encoder and the monitoring system to ensure that the data can be transmitted in real time and accurately. The interface is based on the API provided by the simulation software or a custom data communication protocol. Ensure that the data output by the encoder can be transmitted to the monitoring system in real time for subsequent calculation and analysis. Real-time data transmission is achieved through the real-time data exchange function in the simulation software. According to the requirements of simulation accuracy and computing resources, set a suitable sampling period, that is, how often the encoder value is collected. The higher the sampling frequency, the denser the data obtained, which can more accurately reflect the rotation of the wheel. Ensure that the sampling frequency is high enough to ensure the continuity and accuracy of the data. According to the output characteristics of the encoder and the preset coefficients, convert the value output by the encoder into a standard angle representation. Substitute the standard angle and the radius of the wheel into the speed calculation formula to calculate the rotation speed of the wheel model. The rotation speed can be expressed as the distance the wheel rotates per unit time (such as meters per second).
[0098] In a preferred embodiment of the present invention, the car is set as the center point of the world coordinate system, the laser ranging sensor is enabled, and a ray is emitted to the front of the car. By measuring the time or signal change of the reflected return, the distance between the object and the sensor is calculated, so as to detect and determine the position and distance of the collision object, including:
[0099] Install the laser distance sensor on the trolley;
[0100] The laser distance measuring sensor emits laser rays in front of the car at a predetermined frequency, and controls the emission angle and direction of the rays to ensure that the rays are directed straight toward the front of the car;
[0101] When the rays hit an object and reflect back, the laser range sensor measures the return time of the pulse;
[0102] Calculate the distance between the object and the sensor based on the return time of the pulse and the propagation speed of the laser;
[0103] The collision object is detected based on the distance between the object and the sensor.
[0104] In an embodiment of the present invention, the laser ranging sensor is stably mounted on the trolley to ensure that the sensor will not be affected by vibration or displacement during the movement of the vehicle. The laser ranging sensor emits laser rays in front of the trolley at a predetermined frequency. The setting of this frequency needs to balance the ranging accuracy and system resource consumption. By accurately controlling the emission angle and direction of the laser ray, it is ensured that the laser ray can be emitted straight along the direction of travel of the trolley, thereby effectively detecting the object in front. When the laser ray encounters an object, it will be reflected back to the sensor. The laser ranging sensor can capture the reflected pulse and accurately measure the time required for the pulse to be emitted and returned. The time difference is the key data for calculating the distance of the object. The distance between the object and the sensor is calculated using the measured pulse return time and the known laser propagation speed (close to the speed of light). The calculation process requires a high-precision clock and a stable laser transmitting and receiving system to ensure the accuracy of the ranging. According to the calculated distance between the object and the sensor, combined with the speed and direction of the trolley, it can be determined whether there is a risk of collision. If the detected distance is less than the preset safety distance, it means there is a risk of collision. At this time, the car needs to take corresponding obstacle avoidance measures, such as slowing down, turning or stopping.
[0105] By using a laser rangefinder to measure the distance of objects in front in real time, the car can instantly obtain information about the surrounding environment and provide a basis for quick decision-making. The laser rangefinder has high-precision ranging capabilities and can accurately measure the distance between the object and the sensor, thereby improving the accuracy of the car's perception of the environment. By timely detecting objects in front and judging the risk of collision, the car can take obstacle avoidance measures when necessary to reduce the occurrence of collision accidents and improve driving safety. As an important means for the car to perceive the environment, the laser rangefinder sensor helps to improve the car's autonomous navigation and obstacle avoidance capabilities, and better adapt to complex and changing environments. The laser rangefinder sensor can flexibly adjust the emission frequency and angle to adapt to different scenarios and needs, and improve the adaptability and flexibility of the car.
[0106] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0107] Choose a mounting location on the car to ensure that the sensor can be stably fixed and the accuracy of the distance measurement will not be affected by vibration or displacement during the movement of the vehicle. Use appropriate fixtures and fasteners to firmly mount the laser distance sensor on the car to ensure that it will not loosen or shake. Accurately adjust the direction of the sensor to ensure that the laser beam can be emitted straight along the direction of the car's travel so that the object in front can be effectively detected. Setting the emission frequency of the laser beam requires a balance between the distance measurement accuracy and system resource consumption. Higher frequencies can improve the distance measurement accuracy, but also increase the consumption of system resources. According to actual needs, configure the relevant parameters of the sensor, such as emission power, pulse width, etc., to ensure that the laser beam can be effectively emitted and received. The laser distance sensor emits a laser beam at a predetermined frequency to the front of the car to detect objects in front. When the laser beam encounters an object, it is reflected back to the sensor. The sensor can capture the reflected pulse signal. Accurately measure the time difference required for the pulse to be emitted and returned, which is the key data for calculating the distance of the object. Using the measured pulse return time and the known laser propagation speed (close to the speed of light), the distance between the object and the sensor is calculated by a calculation formula. Process and optimize the measured data, such as filtering out noise and smoothing data, to improve the accuracy of the distance measurement. Combine the calculated distance between the object and the sensor with the speed and direction of the car to determine whether there is a risk of collision. Set a preset safety distance threshold. If the detected distance is less than this threshold, it means there is a risk of collision. Once the risk of collision is detected, the car needs to take corresponding obstacle avoidance measures, such as slowing down, turning or stopping, to avoid collision with the object in front. Test the car in a real environment to verify the accuracy of the laser ranging sensor and the effectiveness of the obstacle avoidance function. Optimize and adjust the system according to the test results, such as adjusting the sensor's installation position, transmission frequency and other parameters to improve the overall performance and stability of the system.
[0108] In a preferred embodiment of the present invention, the distance between the object and the sensor is calculated as follows:
[0109]
[0110] Among them, d represents the distance between the object and the laser ranging sensor; c represents the speed of light in a vacuum; and t represents the time from the emission to the reception of the laser pulse.
[0111] In the embodiment of the present invention, d represents the distance between the object and the laser ranging sensor, that is, the result to be measured. c is the propagation speed of light in a vacuum (or in air, since the refractive index of air is close to 1, the speed of light in a vacuum can be used approximately), which is a constant. t represents the total time from the emission of the laser pulse to its reflection by the object and reception by the sensor.
[0112] Specifically, the laser ranging sensor emits a laser pulse and starts a high-precision timer. When the laser pulse encounters an object and is reflected back and received by the sensor, the timer stops. This time t is the time it takes for the laser pulse to go back and forth between the object and the sensor. Since the laser pulse needs to go back and forth once, when calculating the one-way distance, the total time t needs to be divided by 2. Finally, by multiplying the speed of light c by the half-way time, the distance d between the object and the sensor can be obtained.
[0113] By using the constant and extremely fast speed of light and a timer, the round-trip time of the laser pulse can be measured to calculate the distance between the object and the sensor. Laser ranging provides a non-contact measurement method that can obtain distance information without physical contact with the object being measured, which is beneficial for measuring objects that are difficult to touch or move. Due to the extremely fast speed of light, laser ranging sensors can complete distance measurements in a very short time and are suitable for application scenarios that require fast response. Laser ranging technology is widely used in various fields, such as autonomous driving, robot navigation, terrain mapping, security monitoring, etc., providing these fields with reliable and accurate distance measurement methods. Laser ranging sensors can control the system, realize automated and intelligent distance measurement and monitoring, and improve work efficiency and safety.
[0114] In a preferred embodiment of the present invention, the WinForm module receives and displays the car data and receives the user control instructions, including:
[0115] Receive the car data of the Unity 3D module through the UnityWebPlayer plug-in interface, including camera image data, position, speed and car sensor values;
[0116] The PictureBox control and Label control are used to display the camera image data and the car sensor value respectively, and the user sets the car through buttons to receive user control instructions.
[0117] In an embodiment of the present invention, the WinForm module interacts with the Unity3D module environment through the UnityWebPlayer plug-in interface. The Unity 3D module is a widely used game development and virtual reality development platform that can simulate the operating environment of the car and provide realistic visual effects. The WinForm module application requests relevant data of the car by calling the UnityWebPlayer API. These data include camera image data (scene images captured by the virtual camera on the car), the position coordinates of the car in the virtual environment, the current speed, and the readings of the car's sensors (such as the distance data of the laser ranging sensor, etc.). The WinForm module uses a PictureBox control to display the camera image data received from the Unity 3D module. This control can directly display images, allowing users to see the field of view of the car in the virtual environment in real time. At the same time, a Label control is used to display the values of the car's sensors, such as the distance measured by the laser ranging sensor, etc. In addition, the user can set and control the car through the buttons on the WinForm module. These buttons include forward, backward, turn left, turn right, accelerate, decelerate, etc., and the user sends control instructions to the car through these buttons. The WinForm module application will forward these instructions to the Unity 3D module environment through the UnityWebPlayer plug-in interface, thereby realizing remote control of the car.
[0118] The WinForm module can receive and display the car data in the Unity 3D module in real time, including camera images and sensor readings, to provide users with instant feedback. By displaying the camera image through the PictureBox control, users can intuitively see the real-time field of view of the car in the virtual environment, enhancing the user's immersion and operating experience. Users can directly control the car through the buttons on the WinForm module. This interactive method is simple and intuitive, which improves user participation and ease of operation. By displaying the sensor values through the Label control, users can clearly understand the various status indicators of the car, which helps users make more accurate control decisions. As an independent application, the WinForm module implements complex control and data analysis functions.
[0119] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0120] Use the Unity 3D platform to create a scene that includes a car and a virtual environment. Add a virtual camera to the car to capture scene images. Integrate sensor models such as laser range finders and set up corresponding data outputs. Export the Unity3D scene to a format supported by UnityWebPlayer so that it can run in a web environment. Deploy the UnityWebPlayer plug-in to the computer where the WinForm application is located. Use tools such as Visual Studio to create a new WinForm application. Add a PictureBox control to the WinForm interface to display the camera image. Add a Label control to display the sensor values of the car. Add a Button control as a button to control the car (forward, backward, turn left, turn right, speed up, slow down, etc.). Write code to initialize the UnityWebPlayer plug-in and establish a connection with the Unity 3D environment. Implement the image update logic of the PictureBox control to periodically obtain the camera image from the Unity 3D environment and display it. Implement the text update logic of the Label control to periodically obtain the sensor values from the Unity 3D environment and display them. Write event handling code for the Button control. When the user clicks the button, the corresponding control command is sent to the Unity 3D environment. The WinForm module requests relevant data of the car (camera image, position coordinates, speed, sensor readings, etc.) by calling the UnityWebPlayer API. After receiving the request, the Unity 3D module processes and returns the corresponding data to the WinForm module. After receiving the data, the WinForm module updates the PictureBox control to display the latest camera image. At the same time, the Label control is updated to show the latest sensor value. When the user sends control commands through the buttons on the WinForm module, the WinForm module forwards these commands to the Unity 3D module environment through the UnityWebPlayer plug-in interface. After receiving the command, the Unity3D module performs the corresponding operations to control the car (such as moving forward, backward, turning, etc.)
[0121] In a preferred embodiment of the present invention, sending the car data to the user simulation module through TCP communication may include:
[0122] The WinForm module acts as a client to establish a TCP connection with the User Simulation Module as a server. Specify the server's IP address and port number so that the client can accurately find and connect to the server. Once the TCP connection is established, the Unity 3D module will package the car data (including position, speed, camera image data, sensor values, etc.) into a specific data format through the WinForm module.
[0123] These data are usually serialized into byte streams for transmission over the network. The packaged data is sent to the user simulation module through the established TCP connection. The TCP protocol ensures the reliable transmission of data and ensures that the data will not be lost or damaged through mechanisms such as confirmation and retransmission. As a server, the user simulation module will listen to the specified port, wait for and receive data from the client. After receiving the data, the user simulation module will parse it and restore the byte stream to the original car data.
[0124] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0125] In the WinForm module, specify the IP address and port number of the user simulation module. For example, the IP address can be 192.168.1.100 and the port number can be 12345. The WinForm module, as a client, uses the specified IP address and port number to try to establish a TCP connection with the user simulation module (server). If the connection is successful, a reliable TCP connection is established between the WinForm module and the user simulation module, which can be used for data transmission. The Unity 3D module generates car data, including position, speed, camera image data, sensor values, etc. This data needs to be packaged into a specific data format, usually a structure or class that contains all the data fields that need to be transmitted. The packaged data is serialized into a byte stream for transmission over the network. Serialization can use various methods, such as .NET's BinaryFormatter, Protocol Buffers, JSON, etc. The serialized byte stream is sent to the user simulation module through the established TCP connection. When sending data, use the .NET Socket class or its encapsulation class, such as TcpClient, to write the data to the network stream. The user simulation module acts as a server, listening to the specified port, waiting for and receiving data from the WinForm module.
[0126] After receiving the data, the user simulation module parses it according to the predefined data format and restores the byte stream to the original car data. The parsed data can use the deserialization method corresponding to the serialization. The user simulation module performs simulation processing based on the received car data, which may include physical simulation, behavior prediction, etc. After the processing is completed, the user simulation module may need to send response data to the WinForm module, such as simulation results, control instruction confirmation, etc. The WinForm module and the user simulation module are both responsible for monitoring the status of the TCP connection. If the connection is disconnected or abnormal, both parties need to perform corresponding exception handling, such as retrying the connection, recording logs, etc. When the data transmission is completed or the connection is no longer needed, both parties should close the TCP connection to release resources.
[0127] In a preferred embodiment of the present invention, the simulation module receives the car data and executes the code to process the car data to obtain the operation result, including:
[0128] Get the data sent by the WinForm module from the TCP connection and parse it according to the predetermined data format to obtain the parsed data;
[0129] Extract the parsed data, write the corresponding processing logic code, and read the car data in the buffer;
[0130] In the processing code, logical judgment, mathematical operations and data conversion are performed to obtain the results of the car's state and behavior;
[0131] According to the status and behavior results of the car, determine the result data of the car's operation and state changes;
[0132] The operation results are obtained based on the result data of the car's operation status and state changes.
[0133] In an embodiment of the present invention, the simulation module first receives the data sent by the WinForm module through the established TCP connection. These data are packaged and transmitted in a specific data format, so the simulation module needs to parse them according to the predetermined data format. The parsing process includes splitting, converting and verifying the data packets to ensure the correctness and integrity of the data, thereby obtaining the parsed data. The parsed data contains various information of the car, such as position, speed, sensor readings, etc. The simulation module needs to extract key information from these data and write corresponding processing logic codes to read and process these data. These data are temporarily stored in the buffer so that the subsequent processing code can smoothly access and use them. In the processing code, the simulation module will perform logical judgment, mathematical operations and data conversion on the extracted car data. These operations are to analyze and predict the state and behavior of the car, such as judging whether the car is about to collide with an obstacle, calculating the driving trajectory of the car, etc. Through these processes, the simulation module can derive the current state of the car and possible behavior results. Based on the processing results, the simulation module will further determine the operation and state changes of the car. This includes the speed change, position movement, and sensor reading changes of the car. These result data are the comprehensive judgment and analysis of the car's behavior by the simulation module, reflecting the actual operation status of the car in the virtual environment. Finally, the simulation module will obtain the final operation result based on the result data of the car's operation and state changes.
[0134] By strictly parsing and processing according to the predetermined data format, the accuracy and consistency of the received data are ensured, providing a reliable basis for subsequent logical judgment and mathematical operations. The real-time nature of TCP communication ensures the timely transmission and processing of data, enabling the simulation module to quickly respond to changes in the car in the virtual environment and make corresponding processing decisions. Writing the corresponding processing logic code enables the simulation module to perform customized data processing and analysis according to different needs and scenarios, improving the flexibility and adaptability of the system. Through processing methods such as logical judgment, mathematical operations and data conversion, the simulation module can predict the behavior of the car and provide decision support for it, which helps to improve the car's autonomous navigation and obstacle avoidance capabilities in the virtual environment. The final operation result is a comprehensive evaluation report or control instruction set, which provides users with a comprehensive and intuitive analysis of the car's operating status and behavior, helping users to better understand and control the car's behavior.
[0135] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0136] The simulation module first receives the data sent by the WinForm module through the established TCP connection. The data is packaged and transmitted in a specific data format to ensure the structure and consistency of the data. The simulation module needs to parse the received data packets according to the predetermined data format. The parsing process includes splitting, type conversion and verification of the data packets to ensure the correctness and integrity of the data. The parsed data contains various information about the car, such as position, speed, sensor readings, etc. The simulation module extracts key information from the parsed data. Write the corresponding processing logic code to read and process the data, such as logical judgment, mathematical operations and data conversion.
[0137] These operations are to analyze and predict the state and behavior of the car. The extracted car data is temporarily stored in the buffer. The simulation module performs in-depth analysis and prediction on the extracted car data. For example, it determines whether the car is about to collide with an obstacle, calculates the car's driving trajectory, etc. Based on the processing results, the simulation module further determines the operation status and state changes of the car. This includes the car's speed change, position movement, changes in sensor readings, etc. The simulation module obtains the final operation results based on the result data of the car's operation status and state changes. These result data reflect the actual operation status of the car in the virtual environment and can be used for further simulation or control.
[0138] In a preferred embodiment of the present invention, the operation result is transmitted back to the Unity 3D module through the WinForm module, and the control of the car is realized according to the operation result, including:
[0139] After the simulation module completes the processing of the car data and obtains the running results, it will package these results and send them back to the WinForm module through the previously established TCP connection. This ensures the timely return of data and the closed-loop control of the system. As an intermediate bridge, the WinForm module is responsible for receiving the running results sent back by the simulation module. These data may include adjustment instructions, status updates or other related information of the car. The WinForm module displays this information on the user interface for users to view and monitor, enhancing the interactivity and visualization of the system. The WinForm module uses the UnityWebPlayer plug-in interface to pass the received running results to the Unity 3D module environment. This interface allows two-way communication between the WinForm module and the Unity 3D module. After receiving the running results passed by the WinForm module, the Unity 3D module adjusts the behavior or state of the car according to these results. This includes changing the driving direction of the car, the steering angle and the wheel speed. In this way, the Unity 3D module can dynamically adjust the simulation behavior of the car in real time according to the running results of the simulation module.
[0140] Through TCP communication and the UnityWebPlayer plug-in interface, real-time data feedback and control from the simulation module to the Unity 3D module are achieved, ensuring the rapid response and accuracy of the system. As a data display platform, the WinForm module provides users with an intuitive display of operating results, which is convenient for users to monitor and adjust the system status in real time. Through the intermediary role of the WinForm module, the close integration and efficient interaction between the Unity 3D module and the user simulation module are achieved, improving the overall performance of the system and user experience. For example, any part of the simulation module, WinForm module, or Unity 3D module environment can be easily replaced or upgraded without making large-scale changes to the entire system.
[0141] In another preferred embodiment of the present invention, when applied specifically, the above steps specifically include:
[0142] Through the previously established TCP connection, the simulation module sends the packaged running results back to the WinForm module, ensuring the timely return of data. The WinForm module serves as an intermediate bridge and is responsible for receiving the running results sent back by the simulation module.
[0143] This data contains the car's adjustment instructions, status updates, or other related information. The WinForm module displays this information on the user interface, allowing users to view and monitor the real-time status of the car, thereby enhancing the interactivity and visualization of the system. The WinForm module uses the UnityWebPlayer plug-in interface to pass the received operation results to the Unity 3D module environment. This interface supports two-way communication between the WinForm module and the Unity 3D module. After the Unity 3D module receives the operation results passed by the WinForm module, it will adjust the behavior or status of the car in real time based on these results. This includes changing the car's driving direction, servo angle, and wheel speed.
[0144] In this way, the Unity 3D module can dynamically adjust the simulation behavior of the car according to the running results of the simulation module, thereby achieving a more realistic simulation effect.
[0145] The above is a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A 3D simulation control system for intelligent car competition, characterized in that: The system comprises: Unity 3D module, used to obtain car data and detect collision objects through raycast; WinForm module, used to receive and display car data and receive user control instructions; The simulation module is used to obtain the car data through TCP communication, and execute the code to process the car data to obtain the running results. The running results are transmitted back to the Unity 3D module through the WinForm module, and the car is controlled according to the running results.
2. The intelligent car competition 3D simulation control system according to claim 1 is characterized in that: Get the car data and detect collision objects through raycast, including: Capture image data from the car's camera; Receive the output data of the simulated gyroscope sensor and obtain the position coordinates of the car in the world coordinate system; Acquire the real-time rotation speed data of the wheel model of the trolley from the simulation encoder; Comprehensively process the camera image of the trolley, the position of the trolley in the world coordinate system, and the rotation speed of the wheel model of the trolley to obtain complete trolley operation status data; Set the car as the center point of the world coordinate system, enable the laser ranging sensor, emit rays directly in front of the car, and calculate the distance between the object and the sensor by measuring the time or signal change of the reflection back, so as to detect and determine the position and distance of the collision object.
3. The intelligent car competition 3D simulation control system according to claim 2 is characterized in that: Receive the output data of the simulated gyroscope sensor and obtain the position coordinates of the car in the world coordinate system, including: Determine the parameters of the gyroscope sensor, including measurement range, accuracy, and sampling frequency; According to the sampling frequency, the measurement data is periodically extracted from the gyroscope sensor; Convert the angular velocity data in the measurement data into the attitude and position changes of the car; Based on the initial car position and direction information, calculate the position coordinates of the car in the world coordinate system.
4. The intelligent car competition 3D simulation control system according to claim 3 is characterized in that: according to Calculate the position coordinates of the car in the world coordinate system; Among them, x0, y0, and z0 represent the x, y, and z coordinates of the initial position of the car in the world coordinate system respectively; n ,y n 、z n They represent the x, y, and z coordinates of the car in the world coordinate system after n samplings respectively; d x ,d y ,d z Respectively represent the unit vector components of the initial direction of the car in the x, y, and z directions; ω i represents the angular velocity obtained by the i-th sampling; Δt represents the sampling time interval; n represents the number of sampling times.
5. The intelligent car competition 3D simulation control system according to claim 4, characterized in that: Get the real-time rotation speed data of the wheel model from the simulation encoder, including: Determine the type and resolution parameters of the simulation encoder to match the characteristics of the trolley wheel model; Establish the connection between the simulation encoder and the monitoring system and determine the sampling frequency to collect the encoder value; The angle that the wheel rotates per unit time is converted into a standard angle according to the encoder value and the preset coefficient; Calculate the rotation speed of the trolley wheel model using the angle and the radius of the trolley wheel.
6. The intelligent car competition 3D simulation control system according to claim 5, characterized in that: The formula for calculating the rotation speed of the small wheel model is: Among them, v represents the rotation speed of the small wheel model; R represents the radius of the small wheel; π represents pi; θ represents the angle rotated by the wheel; t represents time.
7. The intelligent car competition 3D simulation control system according to claim 6, characterized in that: Set the car as the center point of the world coordinate system, enable the laser ranging sensor, emit rays directly in front of the car, and calculate the distance between the object and the sensor by measuring the time or signal change of the reflection back, so as to detect and determine the position and distance of the collision object, including: Install the laser distance sensor on the trolley; The laser distance measuring sensor emits laser rays in front of the car at a predetermined frequency, and controls the emission angle and direction of the rays so that the rays are directed toward the front of the car; When the rays hit an object and reflect back, the laser range sensor measures the return time of the pulse; Calculate the distance between the object and the sensor based on the return time of the pulse and the propagation speed of the laser; The collision object is detected based on the distance between the object and the sensor.
8. The intelligent car competition 3D simulation control system according to claim 7, characterized in that: The distance between the object and the sensor is calculated as: Among them, d represents the distance between the object and the laser ranging sensor; c represents the speed of light in a vacuum; and t represents the time from the emission to the reception of the laser pulse.
9. The intelligent car competition 3D simulation control system according to claim 8, characterized in that: Receive and display the car data, and receive user control instructions, including: Receive the car data of the Unity 3D module through the UnityWebPlayer plug-in interface, including camera image data, position, speed and car sensor values; The PictureBox control and Label control are used to display the camera image data and the car sensor value respectively, and the user sets the car through buttons to receive user control instructions.
10. The intelligent car competition 3D simulation control system according to claim 9, characterized in that: Receive the car data and execute the code to process the car data to get the running results, including: Get the data sent by the WinForm module from the TCP connection and parse it according to the predetermined data format to obtain the parsed data; Extract the parsed data, write the corresponding processing logic code, and read the car data in the buffer; In the processing code, logical judgment, mathematical operations and data conversion are performed to obtain the results of the car's state and behavior; According to the status and behavior results of the car, determine the result data of the car's operation and state changes; The operation results are obtained based on the result data of the car's operation status and state changes.
