この記事は「新人クリエーションセレモニー」活動に参加し、一緒にナゲットクリエーションの道を歩み始めました
Wander_bot
1.問題の背景
この割り当ての目的は、Robot Operating System(ROS)を使用して(シミュレートされた)ロボットを制御するためのソフトウェアを作成する方法を提供することです。この割り当てでは、「ルンバ」ロボット掃除機のように、単純な放浪者アルゴリズムを使用してロボットを駆動するROSノードを作成します。ロボットは、障害物に到達するまで前方に移動し、前方が明確になるまで同じ位置で回転してから、再び前方に移動して繰り返します。
2.wander_botパッケージの作成
ROSでは、プログラムはパッケージとして編成されています。したがって、プログラムを作成する前にROSパッケージを作成する必要があります。ROSパッケージを作成するには、パッケージに名前を付けてから、パッケージ内のプログラムのコンパイルに役立つ依存パッケージを指定する必要があります。たとえば、パッケージにC ++プログラムが含まれている場合は、依存関係として「roscpp」を追加する必要があります。パッケージを作成する前に、まずsrcフォルダーに切り替えます。
$ cd ~/catkin_ws/src
$ catkin_create_pkg wander_bot roscpp rospy std_msgs
复制代码
図1は、このコマンドを実行したときの出力を示しています。図1.パッケージの作成
4.Wander.cppの作成
5.ROSwander_botノードの作成
6.CMakeLists.txtファイルの編集
After saving the two files in the wander_bot/src folder, the nodes need to be compiled to create the executable. To do this, we have to edit the CMakeLists.txt file, which is not too complicated. We need to add four lines of code to CMakeLists.txt. Figure 2 shows the additional lines of code to insert (Line 128 - 129)
Figure 2. Changes to the CMakeLists.txt file (Line 128-129)
7.Building C++ Nodes
After saving CMakeLists.txt, we can build the source code. The command to build the nodes is catkin_make. Just switch to the workspace folder and execute the catkin_make command. To switch to the catkin_ws folder, assume that the workspace is in the home folder.
$ cd ~/catkin_ws
复制代码
Executing the catkin_make command to build the nodes
$ catkin_make --pkg wander_bot
复制代码
If everything is correct, you get a message saying that the build was successful (see Figure 3).
Figure 3.Building Successful So we have successfully built the nodes. Now what? We can execute these nodes, right? That is covered in the next section.
8.Creating Launch Files
<launch>
<param name="/use_sim_time" value="true" />
<!-- Launch turtlebot3 world -->
<include file="$(find turtlebot3_gazebo)/launch/turtlebot3_world.launch"/>
<!-- Launch stopper node -->
<node name="wander_bot" pkg="wander_bot" type="wander_bot" output="screen"/>
</launch>
复制代码
The following is the command to execute this launch file. We can execute it from any terminal path.
$ roslaunch wander_bot wander_bot.launch
复制代码
After the roslaunch command, use the package name and then the launch file name
Figure 4. Talker and Listener working together
9.Visualising a Computing Graph
The rqt_graph GUI tool visualises the ROS computation graph. Use any of the launch files that we created in the previous section.
$ roslaunch wonder_bot wonder_bot.launch
复制代码
And in another terminal, run the following.
$ rqt_graph
复制代码
Figure 5 shows the output of this GUI tool.
Figure 5. ROS Graph Check the list of ROS topics in the system by using the following command.
$ rostopic list
复制代码
Figure 6. Rostopic List
效果视频
[ビデオ(video-GB7asKQy-1648260810233)(type-bilibili)(url-player.bilibili.com/player.html…)]