在rviz中可以加载visualization_msgs::MarkerArray类型,这其中可以加载mesh_resource类型的marker,例子如下:
visualization_msgs::MarkerArray generateCarModel(nav_msgs::Odometry loc_info) {
visualization_msgs::MarkerArray markerArray_msg;
visualization_msgs::Marker car_mesh;
car_mesh.header.stamp = ros::Time::now();
car_mesh.header.frame_id = "map";
car_mesh.type = visualization_msgs::Marker::MESH_RESOURCE;
car_mesh.action = visualization_msgs::Marker::ADD;
car_mesh.id = 0;
car_mesh.mesh_resource =
"file:///home/pi_catkin_ws/src/data/car.dae";
car_mesh.pose.position = loc_info.pose.pose.position;
tf::Quaternion tf_quat;
tf::quaternionMsgToTF(loc_info.pose.pose.orientation, tf_quat);
double roll, pitch, yaw;
tf::Matrix3x3(tf_quat).getRPY(roll, pitch, yaw);
tf::Quaternion q;
q.setRPY(roll + M_PI_2, pitch, yaw + M_PI);
geometry_msgs::Quaternion msg_q;
tf::quaternionTFToMsg(q, msg_q);
car_mesh.pose.orientation = msg_q;
car_mesh.color.a = 1.0;
car_mesh.color.r = 1.0;
car_mesh.color.g = 0.0;
car_mesh.color.b = 0.0;
float major_scale = 1.0;
car_mesh.scale.x = major_scale;
car_mesh.scale.y = major_scale;
car_mesh.scale.z = major_scale;
markerArray_msg.markers.push_back(car_mesh);
return markerArray_msg;
}
模型可以使用dae模型