Gazebo筆記(二)

Chien-lin.Tseng
My learning note
Published in
7 min readJul 11, 2019

2019年7月10日(三)

目錄:

一、網站

二ˋ Tutorial: ROS Control

三、本該放在前面的說明

一、網站

(1) Tutorial: ROS Control

(2) 安裝一大堆東西的網站
( ros_control, ros_controllers, and their dependencies )

(3) 中文翻譯網站

(4) 詳細的教學網站

(5) ros 版本參考

二ˋ Tutorial: ROS Control

(1) Data flow of ros_control and Gazebo

模擬軟體和實際硬體的對應:

(2) 先安裝( ros_control, ros_controllers, and their dependencies )

(3) Create a ros_controls package

We’ll next need to create a configuration file and launch file for our ros_control controllers that interface with Gazebo.

  • 建立一個名叫MYROBOT_control 的 package:
    (我是建在 catkin_ws/src 中,教學不是。並且在 MYROBOT_control 中建立 config 和 launch 資料夾)
  • 在config 中建立一個 rrbot_control.yaml 檔:

The PID gains and controller settings must be saved in a yaml file that gets loaded to the param server via the roslaunch file.
In the config folder of your MYROBOT_control package, adapt the following RRBot example to your robot as MYROBOT_control/config/rrbot_control.yaml

rrbot:
# Publish all joint states -----------------------------------
joint_state_controller:
type: joint_state_controller/JointStateController
publish_rate: 50

# Position Controllers ---------------------------------------
joint1_position_controller:
type: effort_controllers/JointPositionController
joint: joint1
pid: {p: 100.0, i: 0.01, d: 10.0}
joint2_position_controller:
type: effort_controllers/JointPositionController
joint: joint2
pid: {p: 100.0, i: 0.01, d: 10.0}

(注意以上的controller)

  • 創立一個 roslaunch file :

Create a roslaunch file for starting the ros_control controllers.
在launch資料夾中,建立一個 MYROBOT_control.launch 檔

分析: (暫時抄的,之後要改)

The first line, “rosparam”, loads the controller settings to the parameter server by loading a yaml configuration file (discussed in the next section).

The controller_spawner node starts the two joint position controllers for the RRBot by running a python script that makes a service call to the ros_control controller manager. The service calls tell the controller manager which controllers you want. It also loads a third controller that publishes the joint states of all the joints with hardware_interfaces and advertises the topic on /joint_states. The spawner is just a helper script for use with roslaunch.

The final line starts a robot_state_publisher node that simply listens to /joint_states messages from the joint_state_controller then publishes the transforms to /tf. This allows you to see your simulated robot in Rviz as well as do other tasks.

(4) Start the controllers using roslaunch

  • 開始 RRBot 的模擬
roslaunch rrbot_gazebo rrbot_world.launch 
-------------------------------------------------------------
可能會有以下error:
[ERROR] [1562920744.368737583, 0.001000000]: GazeboRosControlPlugin missing <legacyModeNS> while using DefaultRobotHWSim, defaults to true.
This setting assumes you have an old package with an old implementation of DefaultRobotHWSim, where the robotNamespace is disregarded and absolute paths are used instead.
If you do not want to fix this issue in an old package just set <legacyModeNS> to true.

我的解決方法:

rosed rrbot_description rrbot.gazebo  //打開 rrbot.gazebo

然後加上:

<legacyModeNS>true</legacyModeNS>

如下方所示:

  • Load the controllers for the two joints by running the second launch file
    ( 載入controller )
roslaunch rrbot_control rrbot_control.launch

(5) 手動傳送 joint 命令

(6) use rqt_gui to send command

  • 安裝 rqt_gui
sudo apt-get install ros-kinetic-rqt ros-kinetic-rqt-common-plugins
sudo apt-get install ros-kinetic-rqt-robot-plugins

執行 rqt_gui

rosrun rqt_gui rqt_gui
  • Add a Command Publisher

On the ‘Plugins’ menu of RQT add the ‘Topics->Message Publisher’ plugin then choose the topic from the drop down box that commands any particular controller that you want to publish to.

a. 把 rqt_gui視窗放到最大,再把滑鼠移到最上面視窗欄,可以看到plugins
(一定要這樣弄,才看的到)

b. 按下Plugins,選 Topics->Message Publisher,選擇/rrbot/joint1_position_controller/command 這個topic

Then press the green plus sign button at the top right.

Enable the topic publisher by checking the check box on the left of the topic name. Set the rate column to 100 (the frequency we send it commands — 100hz in this case).

Next, expand the topic so that you see the “data” row. In the expression column, on the data row, try different radian values between joint1’s joint limits — in RRBot’s case there are no limits because the joints are continuous, so any value works. You should be able to get the RRBot to swing around if you are doing this tutorial with that robot.

Next, in that same expression box we’ll have it automatically change values using a sine wave. 把它改成:

sin(i/100)

類似下圖:

因為 sin值範圍是 -1 ~ 1 ,所以它會來回擺動。輸入0時,它會往上指;輸入3時,它會往下指。

(7) Visualize the controller’s performance

  • Add a Plot plugin to RQT and add the same topic as the one you chose above for the topic publisher: (輸入命令的目標位子)
/rrbot/joint1_position_controller/command/data
  • Add another topic to the Plot plugin that tracks the actual position of the actuator being controlled. (實際位子)
/rrbot/joint1_position_controller/state/process_value

圖看起來像這樣:

  • Tune the PID gains

目標是把上面那張圖的兩條線,調到相當吻合。

Add the ‘Dynamic Reconfigure’ plugin to RQT and click ‘Expand All’ to see the sub-options. 按下pid按鈕,會出現 pid調整表。

(註:如果按了pid還是沒看到,則把框框拉一拉,有可能就會出現了,不是因為少裝什麼東西)

(8) Connect Rviz to Gazebo Simulation

Now that you are using ros_control to send commands to your robot in simulation, you can also use the ros_control jointstatecontroller to read the state of the robot from Gazebo. The idea behind a good simulator is that you should be able to use the same software on your real hardware as you do in simulation. A good starting point for that is visualizing your simulated robot in Rviz, similar to how it is done with real hardware.

  • 執行 rviz
rosrun rviz rviz
  • Under “Global Options” change your “Fixed Frame” to “world” to resolve any errors it might be giving you.
  • Next, add a “RobotModel” display type to Rviz and you should then see your simulated robot in Gazebo being visualized in Rviz!

按左下角 Add,點 RobotModel:

得到RRBot了:

三、本該放在前面的說明

(1) Add transmission elements to a URDF

To use ros_control with your robot, you need to add some additional elements to your URDF.
The <transmission> element is used to link actuators to joints.
<transmission> element 是用來連接 actuators 到 joints 。

For the purposes of gazebo_ros_control in its current implementation,
在 transmission tags 中較重要的是:

  • <joint name="">
    the name must correspond to a joint else where in your URDF.
    name必須與在URDF中其他地方的joint對應。
  • <type>
    the type of transmission.
    Currently only “transmission_interface/SimpleTransmission” is implemented. (可依自己需求改變)
  • <hardwareInterface>
    within the <actuator> and <joint> tags, this tells the gazebo_ros_control plugin (gazebo_ros_control plugin 在下面會提到) what hardware interface to load (position, velocity or effort interfaces).

    Currently only effort interfaces are implemented. (可依自己需求改變)
    註: effort 是力的意思。

(2) Add the gazebo_ros_control plugin (注意寫上檔案名稱)

In addition to the transmission tags, a Gazebo plugin needs to be added to your URDF that actually parses the transmission tags and loads the appropriate hardware interfaces and controller manager.
註解: a Gazebo plugin (gazebo_ros_control plugin) 需要加到URDF中。它的功能是 解析 transmission tags 、載入合適的hardware interface和controller manager 。

By default the gazebo_ros_control plugin is very simple, though it is also extensible via an additional plugin architecture to allow power users to create their own custom robot hardware interfaces between ros_control and Gazebo.

The default plugin XML should be added to your URDF:(在 rrbot.gazebo )

The gazebo_ros_control <plugin> tag 有以下內容:

  • <robotNamespace>
    The ROS namespace to be used for this instance of the plugin, defaults to robot name in URDF/SDF.
    外掛例項的ROS名稱空間, 在URDF/SDF檔案預設是機器人名字。
  • <controlPeriod>
    The period of the controller update (in seconds), defaults to Gazebo’s period.
  • <robotParam>
    The location of the robot_description (URDF) on the parameter server, defaults to ‘/robot_description’
  • <robotSimType>
    The pluginlib name of a custom robot sim interface to be used (see below for more details), defaults to ‘DefaultRobotHWSim’
    robot sim interface外掛名字,預設是 DefaultRobotHWSim (下方會再次提及)。

(3) Default gazebo_ros_control Behavior

如果沒有 <robotSimType> tag,在預設的情況下,
gazebo_ros_control will attempt to get all of the information it needs to interface with a ros_control-based controller out of the URDF.

The default behavior provides the following ros_control interfaces:

  • hardware_interface::JointStateInterface
  • hardware_interface::EffortJointInterface
  • hardware_interface::VelocityJointInterface — not fully implemented

(4) Advanced: custom gazebo_ros_control Simulation Plugins (進階)

The gazebo_ros_control Gazebo plugin also provides a pluginlib-based interface to implement custom interfaces between Gazebo and ros_control for simulating more complex mechanisms (nonlinear springs, linkages, etc).

These plugins must inherit gazebo_ros_control::RobotHWSim which implements a simulated ros_control hardware_interface::RobotHW. RobotHWSim provides API-level access to read and command joint properties in the Gazebo simulator.

The respective RobotHWSim sub-class is specified in a URDF model and is loaded when the robot model is loaded.
For example, the following XML will load the default plugin (same behavior as when using no <robotSimType> tag)(和沒有 <robotSimType> tag 一樣):

(5) RRBot Example

  • We add a <transmission> block similar to the following for every joint that we wish to have Gazebo actuate.
    每一個希望有Gazebo actuate的joint,都被加了<transmission> block。Note that the <hardwareInterface> must be included in both the <joint> and <actuator> tags.
    <hardwareInterface> 必須被<joint><actuator> 加進去。

以下程式碼,在 rrbot.xacro :

  • You’ll also see the gazebo_ros_control plugin in rrbot.gazebo that reads in all the <transmission> tags.
    rrbot.gazebo 中,可以看到 gazebo_ros_control plugin。
    gazebo_ros_control plugin 會 讀取 <transmission> tags。
rosed rrbot_description rrbot.gazebo

--

--