Supplementary chapter of motor PID control - Introduction to the serial port protocol of the Wildfire host computer[Copy link]
0 Introduction
The series of articles on motor PID control introduced earlier ( Advanced Motor Control 3 - PID Cascade Control ) have attracted the attention of many electronics enthusiasts, but also received some feedback on serial communication. The previous series of articles did not focus on the details of serial port software usage and the specific format of the communication protocol. This article will supplement the serial port protocol of the Wildfire PID Debugging Assistant.
The user interface of the Wildfire PID Debug Assistant is as follows. It is related to the serial communication protocol and is mainly divided into three parts:
Parameter area: including data channel selection, PID parameter setting and display, target value, cycle value setting and display
Start/Stop Zone: Controls the start and stop of the motor and the reset of the program
Data curve area: Receives data sent by the board and draws speed curves or position curves, etc.
Before introducing the serial port protocol, it is recommended to install a virtual serial port driver software to virtualize two serial ports on your computer to facilitate the analysis of serial port data.
For example, we generate two virtual serial ports on the computer. These two serial ports can be regarded as connected by a line . For example, we use WildFire PID Assistant and another serial port assistant software to connect these two virtual serial ports respectively . When WildFire PID Assistant sends data (such as pressing the start button), the serial port assistant software on the other end can receive and display the data sent by WildFire PID Assistant. In this way, we can analyze the data format of the data sent by WildFire PID Assistant.
Serial port data is sent in packets, and the data format of each packet is as follows:
Number of bytes
name
content
4 bytes
Baotou
0x59485A53
1bytes
Data Channel
0xXX
4 bytes
Packet length
0xXXXXXXXX
1bytes
instruction
0xXX
1bytes
Parameter 1
0xXX
...
...
...
1bytes
Parameter n
0xXX
1bytes
Checksum
0xXX
illustrate:
All multi-byte low byte first
The packet header is fixed to four bytes 0x59485A53
Channel addresses 1 to 5 correspond to CH1 to CH5 on the software, CH1 is 0x01 , CH2 is 0x02
The packet length is the length of all data from the packet header to the checksum
The instruction is the corresponding function code
Parameters are added when the command requires parameters
Checksum mode - 8 bits
1.2 Instruction Classification
In the above data format, the "instruction" field should be paid special attention to, which indicates the specific meaning of this packet of data.
In addition, serial port data includes downlink data and uplink data . Downlink data means that the WildFire PID Assistant sends serial port data to the board according to the protocol packet format, and uplink data means that the board sends serial port data to the WildFire PID Assistant according to the protocol packet format.
1.2.1 Sending Data
Wildfire PID Assistant sends the set data or instructions to the board
Function
instruction
parameter
PID
0x10
3 floats
Target value
0x11
1 int
start up
0x12
none
stop
0x13
none
Reset
0x14
none
cycle
0x15
1 uint
1.2.2 Upload Data
The board uploads data or commands to the WildFire PID Assistant
Function
instruction
parameter
Target value
0x01
1 int
Actual value
0x02
1 int
PID
0x03
3 floats
start up
0x04
none
stop
0x05
none
cycle
0x06
1 uint
2 Data measurement and analysis
2.1 Measured and distributed data
To send test data, you can use only one computer for testing. Through the virtual serial port, connect the WildFire PID Assistant and another serial port assistant software respectively, send data to the other serial port assistant through the WildFire PID Assistant , display the received data in Hex format, and observe the data format.
Note: The PID data here is of float type and needs to be split into 4-byte Hex format when sending.
2.2 Measured Upload Data
To upload the test data, you need to download the program to the board. The board is connected to any serial port debugging software on the computer through the software to display the received data in Hex format and analyze the data format.
2.2.1 Upload start (0x04)/stop (0x05) status
Baotou
aisle
Packet length
instruction
check
start up
53 5A 48 59
01
0B 00 00 00
04
5E
stop
53 5A 48 59
01
0B 00 00 00
05
5F
2.2.2 Upload target value (0x01)/periodic value (0x06)
The received data is saved in the serial port receive buffer Recv1 array, and then the data can be parsed according to the protocol format.
4 Conclusion
This article introduces the serial port protocol format of the WildFire PID Assistant, including the data format for sending and uploading. It also compares and analyzes the Hex format data of the serial port data obtained and the definition of the protocol, so that the format of the serial port data can be better understood.
If the board does not respond to the command sent by the Wildfire PID Assistant, or the board cannot display the curve when uploading PID data, you should first check whether the format of the serial port data is correct . If not, you should check whether the serial port receiving and sending functions in your program are written correctly. Only when the serial port data conforms to the prescribed protocol format can data communication be carried out correctly.
If the serial port data format is normal but the motor still does not rotate, you need to check whether the hardware wiring is normal and whether you need to modify the parameters in the program according to your motor encoder parameters .