在webots中,选中器件,右键点击help,可以查找对应的帮助文档,有简单ros以及编程基础就能轻松应用。这里总结一下camera、imu、gps、lidar等的使用方法。
一、Camera
- 首先在模型中添加camera,放置在合适的位置,在子节点中添加tramsform,在transform中添加子节点圆柱形shape。注意相机正方向为-z。在width以及height中可以设置相机的宽、高等参数。
二、IMU
在webots中 InertialUnit 只对外提供x.y.z.w四个数据
四、Lidar
注意lidar在使能时候有两个步骤,一个是enable lidar,一个是enable point cloud。
// enable lidar3d
ros::ServiceClient set_lidar3d_client;
ros::ServiceClient set_lidar3d1_client;
webots_ros::set_int lidar3d_srv;
webots_ros::set_bool lidar3d1_srv;
ros::Subscriber sub_lidar3d_scan;
set_lidar3d_client = n->serviceClient<webots_ros::set_int>("ros_key_test/lidar3d/enable");
set_lidar3d1_client = n->serviceClient<webots_ros::set_bool>("ros_key_test/lidar3d/enable_point_cloud");
lidar3d_srv.request.value = TIME_STEP;
lidar3d1_srv.request.value = true;
if (set_lidar3d_client.call(lidar3d_srv) && lidar3d_srv.response.success) {
ROS_INFO("lidar3d enabled.");
sub_lidar3d_scan = n->subscribe("ros_key_test/lidar3d/point_cloud", 10, lidar3dCallback);
ROS_INFO("Topic for lidar3d initialized.");
//while (sub_lidar3d_scan.getNumPublishers() == 0) {
//}
ROS_INFO("Topic for lidar3d scan connected.");
if (set_lidar3d1_client.call(lidar3d1_srv) && lidar3d1_srv.response.success) {
ROS_INFO("lidar3d pointclouds enabled .");
}
} else {
if (!lidar3d_srv.response.success)
ROS_ERROR("Sampling period is not valid.");
ROS_ERROR("Failed to enable lidar3d.");
return 1;
}
2.要想在rviz中看见点云,还需要发布tf
void broadcastTransform() {
static tf::TransformBroadcaster br;
tf::Transform transform;
transform.setOrigin(tf::Vector3(-GPSValues[2], GPSValues[0], GPSValues[1]));
tf::Quaternion q(inertialUnitValues[0], inertialUnitValues[1], inertialUnitValues[2], inertialUnitValues[3]);
q = q.inverse();
transform.setRotation(q);
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "odom", "base_link"));
transform.setIdentity();
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "base_link", "/ros_key_test/lidar3d"));
}
评论(1)
您还未登录,请登录后发表或查看评论