使用天准TADC-D52在TROS.A中读取速腾M1激光雷达的点云数据
·
前言
使用RJ45读取激光雷达的点云数据不是一件难事,但是为了确保项目硬件连接的可靠性,我们选择使用T口进行车规级的连接。
速腾M1
速腾M1的T口使用的连接器是安费诺的口

天准TADC-D52
域控这边的口用的是泰科的口

将雷达和域控连接起来
首先我们需要明确,与普通标准以太网不同,车载以太网是分主从的。由于在默认情况下,域控和雷达的ETH口都是master模式,所以我们选择把雷达的网口改成slave。
在连接上雷达后,使用ucode修改雷达模式

安费诺的口和泰科的口不能直接连接,故需要转接线

硬件连接如下

读取点云数据
硬件连接好后,先试试能不能ping通
这里雷达的源ip为192.168.55.200,目的ip为192.168.55.100

确认网络正常后,使用天准提供的SDK在TROS.A中读取并发布数据


自己写个小demo订阅雷达数据

订阅代码如下
#include <iostream>
#include <thread>
#include <chrono>
#include <protocol/lidar.pb.h>
#include "communication/subscriber.h"
using hobot::communication::CommAttr;
using hobot::communication::ParticipantAttr;
using hobot::communication::Subscriber;
using hobot::communication::PROTOCOL_ZMQ_TCP;
using hobot::communication::PROTOCOL_COMPOSITE;
using hobot::communication::ProtoMsg;
using hobot::communication::ProtobufSerializer;
using LidarProtoMsg = ProtoMsg<LidarProto::LidarFrame>;
using LidarProtoSerializer = ProtobufSerializer<LidarProto::LidarFrame>;
struct VPoint {
float x;
float y;
float z; // quad-word XYZ
uint8_t intensity; // laser intensity reading
uint16_t ring; // laser ring
int32_t timestamp; // point timestamp
};
static void LidarSubCallback(
const std::shared_ptr<LidarProtoMsg> &msg) {
std::cout << "received lidar msg info:" << std::endl;
std::cout << "header_stamp = " << msg->proto.header().stamp()<< std::endl;
// std::cout << "data = " << msg->GetData()->GetData() << std::endl;
uint32_t pcl_cnt = msg->GetData()->GetDataSize() / sizeof(VPoint);
const VPoint* data = reinterpret_cast<VPoint*>
(msg->GetData()->GetData());
if (data == nullptr) {
std::cout << "data is nullptr" << std::endl;
return;
}
for (uint32_t i = 0; i < pcl_cnt; ++i) {
std::cout << "x: "<< data[i].x<< std::endl;
std::cout << "y: "<< data[i].y<< std::endl;
std::cout << "z: "<< data[i].z<< std::endl;
}
}
int main() {
hobot::communication::Init("communication.json");
CommAttr comm_attr;
comm_attr.participant_attrs_.push_back(ParticipantAttr{2});
std::string topic = "lidar_3";
std::shared_ptr<Subscriber<LidarProtoSerializer>> subscriber;
subscriber = Subscriber<LidarProtoSerializer>::New(
comm_attr, topic, 0, LidarSubCallback, PROTOCOL_ZMQ_TCP);
while (1) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout << "subscriber is running ..." << std::endl;
}
return 0;
}
更多推荐
所有评论(0)