当前位置:   article > 正文

一级倒立摆控制 —— ROS2 仿真

一级倒立摆

系列文章目录

最优控制介绍
一级倒立摆控制 —— 系统建模(传递函数模型与状态空间方程表示)
一级倒立摆控制 —— PID 控制器设计及 MATLAB 实现
一级倒立摆控制 —— 最优控制 线性二次型控制(LQR)及 MATLAB 实现
一级倒立摆控制 —— MPC 控制器设计及 MATLAB 实现
一级倒立摆控制 —— ROS2 仿真
一级倒立摆控制 —— LQR 控制器 GAZEBO 仿真


文章目录

  • 系列文章目录
  • 项目描述
  • 一、安装说明
  • 二、如何运行演示程序
    • 1. Source 工作空间
    • 2. 启动演示程序
  • 三、如何配置实时设置
  • 四、代码阅读
    • 4.1 查看节点
    • 4.2 查看话题消息及其类型
    • 4.3 各节点与话题之间的关系


项目描述

该项目的目的是利用 ROS2 框架展示实时功能。本项目基于开放机器人组织之前的工作。本项目以这些软件包为基础。
这就是使用倒立摆进行实时演示的动机:

实时计算通常解决的控制问题的一个典型例子是平衡倒立摆。如果控制器意外地阻塞很长时间,摆就会倒下或变得不稳定。但是,如果控制器可靠地以比控制摆锤的电机运行速度更快的速度更新,摆锤就会成功地适应传感器数据,从而达到平衡摆锤的目的。

有关项目设计演示的详细介绍,请点击此处: 设计文章


一、安装说明

mkdir -p ~/pendulum_ws/src
cd ~/pendulum_ws/src
git clone -b foxy https://github.com/ros2-realtime-demo/pendulum.git
cd ~/pendulum_ws/
colcon build
  • 1
  • 2
  • 3
  • 4
  • 5

二、如何运行演示程序

1. Source 工作空间

如果从源代码安装:

cd ~/pendulum_ws
source ./install/setup.bash
  • 1
  • 2

2. 启动演示程序

关于运行演示的所有可能选项的完整解释,请参阅教程文件:教程
为了进行快速测试,请启用 rviz 启动演示程序:

ros2 launch pendulum_bringup pendulum_bringup.launch.py rviz:=True
  • 1
[INFO] [launch]: All log files can be found below /home/kuanli/.ros/log/2023-10-20-18-38-39-935958-kuanli-3634
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [robot_state_publisher-1]: process started with pid [3635]
[INFO] [pendulum_demo-2]: process started with pid [3637]
[INFO] [rviz2-3]: process started with pid [3639]
[INFO] [pendulum_state_publisher-4]: process started with pid [3641]
[robot_state_publisher-1] [INFO] [1697798320.043931055] [robot_state_publisher]: got segment base_link
[robot_state_publisher-1] [INFO] [1697798320.043982777] [robot_state_publisher]: got segment bearing
[robot_state_publisher-1] [INFO] [1697798320.043987181] [robot_state_publisher]: got segment cart
[robot_state_publisher-1] [INFO] [1697798320.043989438] [robot_state_publisher]: got segment pole
[robot_state_publisher-1] [INFO] [1697798320.043991703] [robot_state_publisher]: got segment pole_mass
[robot_state_publisher-1] [INFO] [1697798320.043993775] [robot_state_publisher]: got segment wheel_l_back_link
[robot_state_publisher-1] [INFO] [1697798320.043995904] [robot_state_publisher]: got segment wheel_l_front_link
[robot_state_publisher-1] [INFO] [1697798320.043998008] [robot_state_publisher]: got segment wheel_r_back_link
[robot_state_publisher-1] [INFO] [1697798320.043999934] [robot_state_publisher]: got segment wheel_r_front_link
[robot_state_publisher-1] [INFO] [1697798320.044001901] [robot_state_publisher]: got segment world
[pendulum_demo-2] [INFO] [1697798320.044821446] [pendulum_controller]: Configuring
[pendulum_demo-2] [INFO] [1697798320.044873711] [pendulum_controller]: Activating
[pendulum_demo-2] [INFO] [1697798320.044884645] [pendulum_driver]: Configuring
[pendulum_demo-2] [INFO] [1697798320.044894735] [pendulum_driver]: Activating
[rviz2-3] [INFO] [1697798320.202078066] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-3] [INFO] [1697798320.202170972] [rviz2]: OpenGl version: 4.6 (GLSL 4.6)
[rviz2-3] [INFO] [1697798320.221277601] [rviz2]: Stereo is NOT SUPPORTED
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

如果一切顺利,您应该可以在 rviz 中看到倒立摆受到控制:
gif

查看话题:

ros2 topic list

/clicked_point
/disturbance
/initialpose
/joint_command
/joint_states
/move_base_simple/goal
/parameter_events
/pendulum_controller/transition_event
/pendulum_driver/transition_event
/pendulum_joint_states
/robot_description
/rosout
/teleop
/tf
/tf_static
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

使用 rqt_plot 实时可视化数据

ros2 run rqt_plot rqt_plot

rqt_plot
使用 rqt_topic 实时查看话题信息

ros2 run rqt_topic rqt_topic

rqt_topic
使用 rqt_graph 实时查看节点及话题

ros2 run rqt_graph rqt_graph

only_node
all_nodes_topics


三、如何配置实时设置

配置演示版实时设置的说明可在此处找到。


四、代码阅读

4.1 查看节点

ros2 node list

/pendulum_controller
/pendulum_driver
/pendulum_state_publisher
/robot_state_publisher
/rviz2
/transform_listener_impl_55eb8906e3f0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4.2 查看话题消息及其类型

ros2 topic list

/clicked_point
/disturbance
/initialpose
/joint_command
/joint_states
/move_base_simple/goal
/parameter_events
/pendulum_controller/transition_event
/pendulum_driver/transition_event
/pendulum_joint_states
/robot_description
/rosout
/teleop
/tf
/tf_static
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
话题类型
/disturbancependulum2_msgs/msg/JointCommand
/joint_commandpendulum2_msgs/msg/JointCommand
/pendulum_joint_statespendulum2_msgs/msg/JointState
/teleoppendulum2_msgs/msg/PendulumTeleop
/initialposegeometry_msgs/msg/PoseWithCovarianceStamped
/joint_statessensor_msgs/msg/JointState
/move_base_simple/goalgeometry_msgs/msg/PoseStamped
/robot_descriptionstd_msgs/msg/String
/tftf2_msgs/msg/TFMessage
/tf_statictf2_msgs/msg/TFMessage
/pendulum_controller/transition_eventlifecycle_msgs/msg/TransitionEvent
/pendulum_driver/transition_eventlifecycle_msgs/msg/TransitionEvent

ros2 interface show pendulum2_msgs/msg/JointCommand

# This represents a linear force applied to the pendulum cart along the X-axis
float64 force	#沿 X 轴方向给小车施加的力
  • 1
  • 2

ros2 interface show pendulum2_msgs/msg/JointState

float64 pole_angle		#摆杆角度
float64 pole_velocity	#摆杆速度
float64 cart_position	#小车位置
float64 cart_velocity	#小车速度
float64 cart_force		#小车受力
  • 1
  • 2
  • 3
  • 4
  • 5

ros2 interface show pendulum2_msgs/msg/PendulumTeleop

# This represents the desired state of the pendulum for teleoperation
# 表示想要倒立摆达到的状态
float64 pole_angle		# 摆杆角度
float64 pole_velocity	#摆杆速度
float64 cart_position	#小车位置
float64 cart_velocity	#小车速度
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

ros2 interface show geometry_msgs/msg/PoseWithCovarianceStamped

# This expresses an estimated pose with a reference coordinate frame and timestamp
# 这表示一个带有参考坐标系和时间戳的估计姿态

std_msgs/Header header
        builtin_interfaces/Time stamp
                int32 sec
                uint32 nanosec
        string frame_id
PoseWithCovariance pose
        Pose pose
                Point position
                        float64 x
                        float64 y
                        float64 z
                Quaternion orientation	# 四元数方位
                        float64 x 0
                        float64 y 0
                        float64 z 0
                        float64 w 1
        float64[36] covariance
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

ros2 interface show sensor_msgs/msg/JointState

# This is a message that holds data to describe the state of a set of torque controlled joints.
#
# The state of each joint (revolute or prismatic) is defined by:
#  * the position of the joint (rad or m),
#  * the velocity of the joint (rad/s or m/s) and
#  * the effort that is applied in the joint (Nm or N).

# 这是一条消息,其中包含描述一组扭矩控制关节状态的数据。
#
# 每个关节(旋转或平移关节)的状态由以下参数定义:
# 关节的位置(弧度或米)、
# 关节的速度(弧度/秒或米/秒)和
# 施加在关节上的力(力矩)值(牛顿米或牛顿)。

# Each joint is uniquely identified by its name
# The header specifies the time at which the joint states were recorded. All the joint states
# in one message have to be recorded at the same time.
#
# This message consists of a multiple arrays, one for each part of the joint state.
# The goal is to make each of the fields optional. When e.g. your joints have no
# effort associated with them, you can leave the effort array empty.
#
# All arrays in this message should have the same size, or be empty.
# This is the only way to uniquely associate the joint name with the correct
# states.

std_msgs/Header header
        builtin_interfaces/Time stamp
                int32 sec
                uint32 nanosec
        string frame_id

string[] name
float64[] position
float64[] velocity
float64[] effort
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

ros2 interface show tf2_msgs/msg/TFMessage

geometry_msgs/TransformStamped[] transforms
        #
        #
        std_msgs/Header header
                builtin_interfaces/Time stamp
                        int32 sec
                        uint32 nanosec
                string frame_id
        string child_frame_id
        Transform transform
                Vector3 translation
                        float64 x
                        float64 y
                        float64 z
                Quaternion rotation
                        float64 x 0
                        float64 y 0
                        float64 z 0
                        float64 w 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

ros2 interface show geometry_msgs/msg/Transform

# This represents the transform between two coordinate frames in free space.
# 这表示自由空间中两个坐标系之间的变换。三维平移向量和四元数表示的旋转向量。
Vector3 translation
        float64 x
        float64 y
        float64 z
Quaternion rotation
        float64 x 0
        float64 y 0
        float64 z 0
        float64 w 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

4.3 各节点与话题之间的关系

在这里插入图片描述


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/519854
推荐阅读
相关标签
  

闽ICP备14008679号