机器人信息发布

代码 /root/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_bringup/yahboomcar_bringup/Mcnamu_driver_X3.py

        #create subcriber
        self.sub_cmd_vel = self.create_subscription(Twist,"cmd_vel",self.cmd_vel_callback,1)
        self.sub_RGBLight = self.create_subscription(Int32,"RGBLight",self.RGBLightcallback,100)
        self.sub_BUzzer = self.create_subscription(Bool,"Buzzer",self.Buzzercallback,100)

        #create publisher
        self.EdiPublisher = self.create_publisher(Float32,"edition",100)
        self.volPublisher = self.create_publisher(Float32,"voltage",100)
        self.staPublisher = self.create_publisher(JointState,"joint_states",100)
        self.velPublisher = self.create_publisher(Twist,"vel_raw",50)
        self.imuPublisher = self.create_publisher(Imu,"/imu/data_raw",100)
        self.magPublisher = self.create_publisher(MagneticField,"/imu/mag",100)

        #create timer
        self.timer = self.create_timer(0.1, self.pub_data)
  • ros2 run yahboomcar_bringup Mcnamu_driver_X3
  • ros2 topic list

    话题名字 话题内容
    /Buzzer 蜂鸣器
    /RGBLight 灯带效果控制
    /cmd_vel 速度控制
    /edition 版本信息
    /imu/data_raw IMU传感器数据
    /imu/mag IMU-磁力计数据
    /vel_raw 小车速度信息
    /voltage 电池电压信息
  • ros2 topic echo /voltage 读取电压数据
  • 运动 ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.2}}" , 停止 ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}"

机器人控制

代码在 /root/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_ctrl/yahboomcar_ctrl/yahboo m_keyboard.py

    def getKey(self):
        tty.setraw(sys.stdin.fileno())
        rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
        if rlist: key = sys.stdin.read(1)
        else: key = ''
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self.settings)
        return key
  • ros2 run yahboomcar_bringup Mcnamu_driver_X3
  • ros2 run yahboomcar_ctrl yahboom_keyboard 键盘控制程序

节点通信图 ros2 run rqt_graph rqt_graph :

机器人状态估计

代码 /root/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_bringup/launch/yahboomcar_bringup_X3_launch.py/root/yahboomcar_ros2_ws/software/library_ws/src/robot_localization/launch/ekf.launch.py

  • ros2 launch yahboomcar_bringup yahboomcar_bringup_X3_launch.py
  • ros2 run rqt_graph rqt_graph
  • ros2 node info /ekf_filter_node 查看节点信息
    driver_node = Node(
        package='yahboomcar_bringup',
        executable='Mcnamu_driver_X3',
    )

    base_node = Node(
        package='yahboomcar_base_node',
        executable='base_node_X3',
        # 当使用ekf融合时,该tf有ekf发布
        parameters=[{'pub_odom_tf': LaunchConfiguration('pub_odom_tf')}]
    )

    imu_filter_node = Node(
        package='imu_filter_madgwick',
        executable='imu_filter_madgwick_node',
        parameters=[imu_filter_config]
    )

    ekf_node = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([os.path.join(
            get_package_share_directory('robot_localization'), 'launch'),
            '/ekf_x1_x3_launch.py'])
    )
  • driver_node:启动小车底盘,获取到轮子的速度vel数据,发布给/base_node节点,获取imu数据,发布给/Imu_filter_madgwick节点;
  • base_node:接收vel数据,通过计算,转换成odom_raw数据,发布给/ekf_filter_node节点;
  • Imu_filter_madgwick:接收底盘发布的imu数据,通过自身算法过滤后,发布过滤后的imu/data 数据给/ekf_filter_node节点;
  • ekf_filter_node:接收/base_node节点发布的odom数据和/Imu_filter_madgwick发布过来的 imu/data数据,通过自身算法,融合后,发布odom数据。
    # Depending on gui parameter, either launch joint_state_publisher or joint_state_publisher_gui
    joint_state_publisher_node = Node(
        package='joint_state_publisher',
        executable='joint_state_publisher',
        condition=UnlessCondition(LaunchConfiguration('gui'))
    )

    joint_state_publisher_gui_node = Node(
        package='joint_state_publisher_gui',
        executable='joint_state_publisher_gui',
        condition=IfCondition(LaunchConfiguration('gui'))
    )

机器人校准

URDF模型

发表评论