Basic Experiment | External Communication of PX4 Controller

External communication of PX4 controller

01

Experiment name and purpose

External communication of the PX4 controller: When performing hardware-in-the-loop simulation, we often need to send data (sensor data, fault triggers, control instructions, parameter adjustments, etc.) to the designed Simulink controller, and receive some interesting data at the same time. The Simulink controller design function of the RflySim platform provides the uORB message rfly_ctrl to receive external data (UDP sends the specified structure to the 30100 series port of CopterSim), and provides the uORB message rfly_px4 to send data to the outside (to the 40100 series port to send specific data). This routine uses the rfly_ctrl data sent externally as the input of the remote control, and at the same time sends the received data to rfly_px4 and sends it back to the external program.

02

Experimental effect

Simulink directly controls the aircraft in a hardware-in-the-loop simulation.

03

operating environment

picture

①: Please refer to the recommended configuration: https://doc.rflysim.com/1.1InstallMethod.html

②: Make sure that the compilation command when installing the platform is: droneyee_zyfc-h7_default, and the firmware version is: 1.12.1. For other supporting flight controllers, please refer to: http://doc.rflysim.com/hardware.html.

 

04

Experimental procedure

Step 1:

Open the MATLAB software, run the Init_control.m file, and the PX4ExtMsgReceiver.slx file will be opened at the same time. In Simulink, click the compile command.

 

Step 2:

Click the View diagnostics command at the bottom of Simulink, and a diagnostic dialog box will pop up to view the compilation process. If Build process completed successfully pops up in the diagnostic box, it means that the compilation is successful. The left picture shows the generated compilation report.

picture

Step 3:

Use the USB data cable to link the flight controller and the computer. Enter: PX4Upload in the MATLAB command line window and run it or click PX4 PSP: Upload code to Px4FMU, a CMD dialog box will pop up, showing that the firmware is being uploaded to the flight controller, waiting for the upload to succeed.

picture

 

picture

Step 4:

Open the QGroundControl software. Confirm that the drone rack is set up as follows:

picture

 

Step 5:

After the upload is successful, double-click to open the "*\Desktop\RflyTools\HITLRun.lnk" or "*\PX4PSP\RflySimAPIs\HITLRun.bat" file, enter the inserted flight control Com port number in the pop-up CMD dialog box, and the Start RflySim3D, CopterSim, QGroundControl software, wait for the status box of CopterSim to display: PX4: GPS 3D fixed & EKF initialization finished.

picture

Step 6:

Run the PX4ExtMsgSender.slx file in MATLAB. During the operation, slide the Slider module of CH5 to the maximum value of 1900, which means the aircraft is unlocked. Slide the Slider module of CH3 to simulate the throttle of the aircraft and realize the take-off action of the aircraft, which can be observed in RflySim3D take off.

picture

picture

  

At the same time, in the PX4ExtMsgSender.slx model, some state quantities of the aircraft can also be seen, and the specific definitions are as follows:

 

picture

 

Guess you like

Origin blog.csdn.net/FEISILAB_2022/article/details/132063780