小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
拓展3:FishBot 树莓派配置建图导航
-
@2524167316 检查一下tf_tree
-
@小鱼 之前发现/odom有话题,但是没有数据传过来,现在/odom有数据了,但是还是建不了图
-
-
@小鱼 在 拓展3:FishBot 树莓派配置建图导航 中说:
ros2 launch fishbot_bringup fishbot_bringup.launch.py
运行之后,出现以下错误:
打开rviz之后也没有小车模型,也没有RobotModel话题,请问怎么解决。 -
-
@小鱼 雷达和四驱板都已经成功运行,运行ros2 launch fishbot_bringup fishbot_bringup.launch.py后,输出如下:
在进行建图操作时,输入ros2 launch slam_toolbox online_async_launch.py,输出如下:
在rviz中没有RobotModel话题:
我是想要加载小车的模型在进行建图。 -
-
@小鱼
这样的
这是节点:
-
@小鱼 你把这个文件 ishbot_bringup.launch.py 的内容粘贴出来,另外不要截图:
@小鱼 在 提问前必看!不符合要求的问题拒绝回答!! 中说:
- 不要截图,要复制粘贴,一定要代码块包裹
不要截图的原因是,代码方便回答者去复制帮你搜索,而且无论是在手机上还是电脑上都更容易看。
- 不要截图,要复制粘贴,一定要代码块包裹
-
import os from launch import LaunchDescription from launch.substitutions import LaunchConfiguration from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare def generate_launch_description(): package_name = 'fishbot_description' urdf_name = "fishbot_v1.0.0.urdf" ld = LaunchDescription() pkg_share = FindPackageShare(package=package_name).find(package_name) urdf_model_path = os.path.join(pkg_share, f'urdf/{urdf_name}') robot_state_publisher_node = Node( package='robot_state_publisher', executable='robot_state_publisher', arguments=[urdf_model_path] ) joint_state_publisher_node = Node( package='joint_state_publisher', executable='joint_state_publisher', name='joint_state_publisher', arguments=[urdf_model_path], output='screen', ) fishbot_bringup_node = Node( package='fishbot_bringup', executable='fishbot_bringup', name='fishbot_bringup', output='screen', ) ld.add_action(joint_state_publisher_node) ld.add_action(robot_state_publisher_node) ld.add_action(fishbot_bringup_node) return ld
-
@2216200358 在 拓展3:FishBot 树莓派配置建图导航 中说:
robot_state_publisher_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
arguments=[urdf_model_path]
)这个写的感觉不太对,应该加个参数好像,你看看书前面的代码,或者最近B站的课程,也可以把TF贴出来看看
-
@小鱼 ```
#include <rclcpp/rclcpp.hpp>
#include <rclcpp/rclcpp.hpp>
#include <nav_msgs/msg/odometry.hpp>
#include <tf2/utils.h>
#include <tf2_ros/transform_broadcaster.h>class TopicSubscribe01 : public rclcpp::Node
{
public:
TopicSubscribe01(std::string name) : Node(name)
{
RCLCPP_INFO(this->get_logger(), "大家好,我是%s.", name.c_str());
odom_subscribe_ = this->create_subscription<nav_msgs::msg::Odometry>("odom", rclcpp::SensorDataQoS(), std::bind(&TopicSubscribe01::odom_callback, this, std::placeholders::1));
tf_broadcaster = std::make_unique<tf2_ros::TransformBroadcaster>(this);
}private:
// 声明一个订阅者
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr odom_subscribe_;
std::unique_ptr<tf2_ros::TransformBroadcaster> tf_broadcaster_;
nav_msgs::msg::Odometry odom_msg_;void odom_callback(const nav_msgs::msg::Odometry::SharedPtr msg)
{
(void)msg;
RCLCPP_INFO(this->get_logger(), "recv odom->base_footprint tf :(%f,%f)", msg->pose.pose.position.x, msg->pose.pose.position.y);
odom_msg_.pose.pose.position.x = msg->pose.pose.position.x;
odom_msg_.pose.pose.position.y = msg->pose.pose.position.y;
odom_msg_.pose.pose.position.z = msg->pose.pose.position.z;odom_msg_.pose.pose.orientation.x = msg->pose.pose.orientation.x; odom_msg_.pose.pose.orientation.y = msg->pose.pose.orientation.y; odom_msg_.pose.pose.orientation.z = msg->pose.pose.orientation.z; odom_msg_.pose.pose.orientation.w = msg->pose.pose.orientation.w;
};
public:
void publish_tf()
{
geometry_msgs::msg::TransformStamped transform;
double seconds = this->now().seconds();
transform.header.stamp = rclcpp::Time(static_cast<uint64_t>(seconds * 1e9));
transform.header.frame_id = "odom";
transform.child_frame_id = "base_footprint";transform.transform.translation.x = odom_msg_.pose.pose.position.x; transform.transform.translation.y = odom_msg_.pose.pose.position.y; transform.transform.translation.z = odom_msg_.pose.pose.position.z; transform.transform.rotation.x = odom_msg_.pose.pose.orientation.x; transform.transform.rotation.y = odom_msg_.pose.pose.orientation.y; transform.transform.rotation.z = odom_msg_.pose.pose.orientation.z; transform.transform.rotation.w = odom_msg_.pose.pose.orientation.w; tf_broadcaster_->sendTransform(transform);
}
};int main(int argc, char argv)
{
rclcpp::init(argc, argv);
/产生一个的节点/
auto node = std::make_shared<TopicSubscribe01>("fishbot_bringup");
/ 运行节点,并检测退出信号/
rclcpp::WallRate loop_rate(1000.0);
while (rclcpp::ok())
{
rclcpp::spin_some(node);
node->publish_tf();
loop_rate.sleep();
}rclcpp::shutdown();
return 0;
} -
@小鱼 tf指的是 rqt-tf-tree 图,可以看看前面基础课程
-