[Simulation] 나의 world에서 키보드로 로봇 움직이기

Yujin-Shim·2023년 6월 22일
0

simulation

목록 보기
3/10

목표

  • 나만의 World 만들기
  • 다양한 모델과 population을 이용하기
  • world를 열기 위한 launch 파일 작성하고 실행시키기
  • 로봇 spawn하여 teleop_twist_keyboard로 주행해보기

.
.

step1. 나만의 world 만들기

  • 나의 world concept: 학교!

.
.
<.world 파일>

<?xml version="1.0" ?>
<sdf version="1.5">
    <world name="default">

        <!-- A global light source -->
        <include>
            <uri>model://sun</uri>
        </include>

        <!-- A ground plane -->
        <include>
            <uri>model://ground_plane</uri>
        </include>

        <include>
            <uri>model://school</uri>
            <static>true</static>
            <pose>-20 -10 0.3 0 0 3.14 </pose>
        </include>
        <include>
            <uri>model://playground</uri>
            <static>true</static>
            <pose>10 10 0.3 0 0 3.14 </pose>
        </include>


        <!-- +X barriers -->
        <population name="pine_tree_population">
            <model name="pine_tree">
                <include>
                    <static>true</static>
                    <uri>model://pine_tree</uri>
                </include>
            </model>
            <pose>0 19 0.3 0 0 0</pose>
            <box>
                <size>40 40 0.01</size>
            </box>
            <model_count>20</model_count>
            <distribution>
                <type>linear-x</type>
            </distribution>
        </population>

        <!-- -X barriers -->
        <population name="pine_tree_population">
            <model name="pine_tree_2">
                <include>
                    <static>true</static>
                    <uri>model://pine_tree</uri>
                </include>
            </model>
            <pose>10 5 0.3 0 0 0</pose>
            <box>
                <size>10 20 0.01</size>
            </box>
            <model_count>10</model_count>
            <distribution>
                <type>linear-x</type>
            </distribution>
        </population>

        <!-- +Y barriers -->
        <population name="pine_tree_population">
            <model name="pine_tree_3">
                <include>
                    <static>true</static>
                    <uri>model://pine_tree</uri>
                    <pose>0 0 0 0 0 1.57</pose>
                </include>
            </model>
            <pose>19 10 0.3 0 0 0</pose>
            <box>
                <size>10 10 0.01</size>
            </box>
            <model_count>10</model_count>
            <distribution>
                <type>linear-y</type>
            </distribution>
        </population>

        <!-- random models population -->
        <population name="person_walking_population">
            <model name="person_walking">
                <include>
                <static>false</static>
                <uri>model://person_walking</uri>
                </include>
            </model>
            <pose>0 0 0.2 0 0 0</pose>
            <box>
                <size>30 30 0.01</size>
            </box>
            <model_count>5</model_count>
            <distribution>
                <type>random</type>
            </distribution>
        </population>

            <!-- random models population -->
        <population name="oak_tree_population">
            <model name="oak_tree">
                <include>
                <static>true</static>
                <uri>model://oak_tree</uri>
                </include>
            </model>
            <pose>0 0 0.2 0 0 0</pose>
            <box>
                <size>60 60 0.01</size>
            </box>
            <model_count>5</model_count>
            <distribution>
                <type>random</type>
            </distribution>
        </population>
    </world>
</sdf>

.
.

step2. Robot spawn

roslaunch robot_description spawn.launch

로봇 배치! - 이건 그전 포스팅 로봇만들기 편 참고

step3. Robot keyboard control

방법은..

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

package가 없다는 에러가 난다면 설치가 안되어서 그럴 수 있으므로
terminal에서 설치를 해주면 된다.
이때 자신의 ros version에 맞게 melodic을 바꿔줘야한다.
melodic이면 아래처럼 적고 noetic이면 ros-noetic-teleop-twist-keyboard 이런식으로

sudo apt-get install ros-melodic-teleop-twist-keyboard

이제 키보드를 눌러 만든 world에서 자유롭게 이동하는 로봇을 구경하면 된다!
.
.

0개의 댓글