This document describes how to send PTC commands to the LiDAR through the SDK in order to retrieve LiDAR information or configure its parameters.
Open the file ptc_tool.cc.
Select the desired communication command:
// #define SET_NET
// #define SET_DES_IP_AND_PORT
// #define SET_RETURN_MODE
// #define SET_SYNC_ANGLE
// #define SET_STANDBY_MODE
// #define SET_SPIN_SPEED
#define DEFINE_YOURSELFSET_NET: Set LiDAR network configurationSET_DES_IP_AND_PORT: Set destination IP and port for point cloud dataSET_RETURN_MODE: Set return mode of the LiDARSET_SYNC_ANGLE: Set sync angleSET_STANDBY_MODE: Set operating mode of the LiDARSET_SPIN_SPEED: Set spin speed of the LiDARDEFINE_YOURSELF: Custom command
In the HesaiLidar_SDK_2.0 folder, open a terminal and execute the following commands:
cd HesaiLidar_SDK_2.0/tool_ptc
mkdir build
cd build
cmake ..
makeAfter successful compilation, run the generated executable file ptc_tool inside the build directory.
When executing, you need to provide the LiDAR's IP address and the PTC communication port:
./ptc_tool 192.168.1.201 9347Set the destination IP address and related ports:
std::string destination_ip = "255.255.255.255"; // Set to unicast, multicast, or broadcast
uint16_t udp_port = 2368; // Set UDP port
uint16_t gps_udp_port = 10110; // Set GPS UDP portThe following log indicates that the parameters were successfully set:
SetDesIpandPort succeeded!
Configure IP address, subnet mask, gateway, and VLAN:
std::string net_IP = "192.168.1.201"; // Set LiDAR IP
std::string net_mask = "255.255.255.0"; // Set subnet mask
std::string net_getway = "192.168.1.1"; // Set gateway
uint8_t vlan_flag = 0; // VLAN flag, 0 means not set, 1 means set
uint16_t vlan_ID = 0; // Set VLAN IDThe following log indicates that the parameters were successfully set:
SetNet succeeded!
Note: Running this command may terminate the program. You will need to reconfigure your network with the new LiDAR IP before proceeding with further operations.
In ptc_tool.cc, use the DEFINE_YOURSELF macro and add saving logic. This will generate a calibration file named correction.dat in the build directory:
#ifdef DEFINE_YOURSELF
u8Array_t dataIn;
u8Array_t dataOut;
uint8_t ptc_cmd = 0x05;
int ret = -1;
ret = ptc_client_->QueryCommand(dataIn, dataOut, ptc_cmd);
if (ret == 0) {
LogInfo("GetCorrectionInfo succeeded!");
// Save to a file, e.g., correction.dat
FILE* fp = fopen("correction.dat", "wb");
if (fp != nullptr) {
fwrite(dataOut.data(), 1, dataOut.size(), fp);
fclose(fp);
LogInfo("Saved correction data to correction");
} else {
LogInfo("Failed to open file for writing correction data!");
}
} else {
LogWarning("GetCorrectionInfo failed!");
}
#endifIn ptc_tool.cc, define and use DEFINE_YOURSELF
#ifdef DEFINE_YOURSELF
u8Array_t dataIn; // Payload data, as defined by the PTC protocol. For extended commands, it also includes the extended command itself.
u8Array_t dataOut; // Response data, excluding header information, only contains payload data.
uint8_t ptc_cmd = 0x05; // PTC command. For extended commands, it should be set to 0xFF uniformly.
int ret = -1;
ret = ptc_client_->QueryCommand(dataIn, dataOut, ptc_cmd);
if (ret == 0) {
LogInfo("Define yourself succeeded");
} else {
LogWarning("Define yourself failed! return_code: %d", ptc_client_->ret_code_); // If ret_code_ is positive, it represents an error code returned by PTC. If negative, it indicates some unexpected error. Refer to the code for details.
}
#endif