将serialized_data用websocket wss发送,#include "ros/ros.h" #include "std_msgs/String.h" #include <boost/thread/locks.hpp> #include <boost/thread/shared_mutex.hpp> #include "third_party/apollo/proto/perception/perception_obstacle.pb.h" #include "t3_perception.pb.h" apollo::perception::PerceptionObstacles perception_obstacles_; void perceptionCallback(const std_msgs::String& msg) { ROS_WARN("t3 perceptionCallback parse"); if (perception_obstacles_.ParseFromString(msg.data)) { double timestamp = perception_obstacles_.header().timestamp_sec(); ROS_INFO("t3 perceptionCallback timestamp %f count:%d", timestamp, perception_obstacles_.perception_obstacle().size()); std::string data; perception_obstacles_.SerializeToString(&data); VehData veh_data; veh_data.set_messagetype(5); veh_data.set_messagedes("PerceptionObstacles"); veh_data.set_contents(data); std::string serialized_data; veh_data.SerializeToString(&serialized_data); } else { ROS_ERROR("t3 perceptionCallback parse fail!"); } } int main(int argc, char **argv) { ros::init(argc, argv, "listener"); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("/perception_node/perception_objects", 1000, perceptionCallback); ros::spin(); return 0; }
时间: 2024-04-07 15:32:29 浏览: 72
jai_imageio-1_0_01-doc.zip_doc_jai_imageio-1.1
这段代码的功能是订阅ROS节点中的/perception_node/perception_objects主题,当有数据到来时,会调用perceptionCallback()函数进行处理。在这个函数中,首先尝试将接收到的数据解析为PerceptionObstacles类型的数据,如果解析成功,则将数据序列化为字符串,并且封装到VehData类型的数据中,最后将VehData类型的数据序列化为字符串,以便通过websocket wss发送。但是,在这段代码中,并没有实现websocket wss发送的相关代码,需要根据具体的需求进行实现。
阅读全文