File size: 6,541 Bytes
2d6bfa0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
.. _mapping_and_navigaiton:

Mapping and Navigation for Simulation
=====================================


Mapping
-------

Run simulation related nodes

* Run roscore

  .. code-block:: bash

    roscore

* Launch the robot (In another terminal)

  .. code-block:: bash

    roslaunch mir_bringup_sim robot.launch

* Run gazebo simulator (In another terminal)

  .. code-block:: bash

    rosrun gazebo_ros gzclient

* Run rviz (In another terminal)

  .. code-block:: bash

    rosrun rviz rviz

  .. note::

    To setup the RViz, please go to the bottom of this page.

Generate map
------------

* Run 2D SLAM (In another terminal)

  .. code-block:: bash

    roslaunch mir_2dslam 2dslam.launch


  Now there should be robot in an empty map in RViz.

* Move the robot around the map. (In another terminal)

  .. code-block:: bash

    roslaunch mir_teleop teleop_keyboard.launch

  WSAD keys set the robot in motion and "Space bar" stops that motion.

  As you move the robot around, you should be able to see walls appearing in the map
  in RViz and all the other area will be free. After you have mapped the whole environment,
  you can save the map in config map directory.

* Move to map config directory (In another terminal)

  .. code-block:: bash

    roscd mcr_default_env_config

* Then make a directory and move inside that newly created directory

  .. code-block:: bash

    mkdir test_map
    cd test_map

* Now you can save the map that you just created

  .. code-block:: bash

    rosrun map_server map_saver

  This will ideally create 2 files namely *map.pgm* and *map.yml*.
  Now you can exit out of *mir_2dslam* execution. You can also exit from *mir_teleop, gazebo, mir_bringup_sim*

Making the map usable
----------------------

In order to use this map in future to navigate, follow the following steps:

* Add files where the goals will be saved \(in the same directory where the map files have been saved\)

  .. code-block:: bash

    touch navigation_goals.yaml
    touch orientation_goals.yaml

* Make a copy of the existing launch file.

  .. code-block:: bash

    cd ~/catkin_ws/src/mas_common_robotics/mcr_environments/mcr_gazebo_worlds/ros/launch
    cp brsu-c025-sim.launch test_map.launch

  .. note::

    Inside *test_map.launch*, edit the argument of **robot_env** (line 10).
    Replace *brsu-c025-sim* with *test_map*. Save this file.

* Make a copy of xacro file.

  .. code-block:: bash

    cd ~/catkin_ws/src/mas_common_robotics/mcr_environments/mcr_gazebo_worlds/common/worlds/
    cp brsu-c025-sim.urdf.xacro test_map.urdf.xacro

.. note::

  Now your newly created map should be ready for use.

Navigation
-----------

* Run the commands from "Run simulation related nodes" as mentioned above to bring the robot up.

* Launch the navigation node

  .. code-block:: bash

    roslaunch mir_2dnav 2dnav.launch

* Open RViz

  Add *PoseArray* in RViz and change its topic to */particlecloud*.
  Now you will be able to see red arrows around the robot. These arrow show the pose of the robot.

* You now need to localize the robot to get its correct pose. Move the robot around the map. (In another terminal)

  .. code-block:: bash

    roslaunch mir_teleop teleop_keyboard.launch

  Rotate the robot in its place using QE keys.
  You will notice the red arrows converging around the robot. Once the the robot is reasonably localised,
  you can navigate the robot around in 2 ways:

  1. GUI (RViz)

    Click on the `2D Nav Goal` and select a goal on the map.

  2. Terminal based (ROS Action Server Client)

    For Action server client, the robot first needs name of position for source and
    destination places (It cannot use `x, y, theta` values)

    To name the poses, you have to execute *save_base_map_poses_to_file*

    .. code-block:: bash

      roscd mcr_default_env_config
      cd test_map
      rosrun mcr_navigation_tools save_base_map_poses_to_file

    This program is terminal based interactive program. The program will ask you to name the position.
      1. You can now navigate the robot to your desired position (using GUI of RViz or *mir_teleop*).
      2. Once your robot is at the desired position, you can enter a name and press enter.

        .. note::

          Note : The name of the location should be ALL CAPS.
          For example, CORNER_1, MAIN_DOOR, etc. If the name contains any lower case character,
          the server will not work) You will see pose of the robot inside square brackets in
          the next line and prompted for another name.

      3. Repeat step 1 and 2 to add multiple names to different locations inside the map.
      4. To close this interactive program, press *Ctrl + z*. (Note : *Ctrl + c* won't work.) Then kill this process.

        .. code-block:: bash

          ps

        take a note of the `pid` of python process.

        .. code-block:: bash

          kill -9 <pid_number>

        Now stop *mir_2dnav* and start it again.

        Launch move base launch file (In another terminal)

        .. code-block:: bash

          roslaunch mir_move_base_safe move_base.launch

        Run the server file. (In another terminal)

        .. code-block:: bash

          rosrun mir_move_base_safe move_base_safe_server.py

        You can test everything by running client test file. (In another terminal)

        .. code-block:: bash

          rosrun mir_move_base_safe move_base_safe_client_test.py SOURCE_NAME DESTINATION_NAME

        For example, if you want to move the robot from MAIN_DOOR to CORNER_1, then

        .. code-block:: bash

          rosrun mir_move_base_safe move_base_safe_client_test.py MAIN_DOOR CORNER_1

        .. note::

          The source location is irrelevant for the client test file.
          Your robot can be anywhere and the program will still work correctly.
          Just give some valid location name as a place holder.)
          The client will print **success : True**, if it was able to successfully navigate to the destination position.

RViz setup
-----------


* Add *Map, RobotModel, LaserScan* using the "Add" button in bottom left corner of "Display" section of RViz.

* In *Map*, change the topic to */map*

* In *LaserScan*, change the topic to */scan_front*. Add another *LaserScan* and change its topic to */scan_rear*.

* In global option, change the *Fixed Frame* to *map*.

.. note::

  You can also add another *PoseArray* and change its topic to */move_base/GlobalPlannerWithOrientation*
  to visualise the plan created by the *mir_2Dnav* node.