News Download Tutorial FAQ Reference Buy

자바 언어 : 말판 이동하기 #1 (순차, 횟수 반복)

동굴 탐험 (순차)
햄스터 로봇이 길을 떠나 동굴 속을 탐험하려고 합니다. 동굴 속에는 햄스터가 좋아하는 해바라기 씨가 가득한 보물 상자가 있습니다. 아래 그림에서 햄스터 로봇이 보물 상자 앞까지 이동하려면 어떻게 움직여야 할지 생각해 봅시다. 도착 지점으로 이동한 후에는 보물 상자를 열 수 있도록 햄스터 로봇이 보물 상자 방향을 바라보아야 합니다.

말판 내려 받기 PDF PPT

다음 메소드들을 사용하면 말판 위에서 이동하거나 회전할 수 있습니다.

햄스터 로봇을 말판의 출발 위치에 방향을 맞추어 올려놓고 보물 상자 앞까지 이동시켜 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        hamster.boardForward();
        hamster.boardRight();
        hamster.boardForward();
        hamster.boardForward();
    }
}

두 번째 동굴도 탐험해 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        hamster.boardForward();
        hamster.boardForward();
        hamster.boardRight();
        hamster.boardForward();
        hamster.boardForward();
        hamster.boardRight();
        hamster.boardForward();
        hamster.boardForward();
    }
}

세 번째 동굴도 탐험해 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        hamster.boardForward();
        hamster.boardRight();
        hamster.boardForward();
        hamster.boardLeft();
        hamster.boardForward();
        hamster.boardRight();
        hamster.boardForward();
        hamster.boardLeft();
    }
}
우물 찾기 (횟수 반복)
햄스터 로봇이 목이 마릅니다. 숲 속 우물을 향해 달려가야 합니다. 아래 그림에서 햄스터 로봇이 우물 앞까지 이동하려면 어떻게 움직여야 할지 생각해 봅시다. 도착 지점으로 이동한 후에는 햄스터 로봇이 물을 마실 수 있도록 우물 방향을 바라보아야 합니다.

말판 내려 받기 PDF PPT

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        hamster.boardLeft();
        for(int i = 0; i < 3; ++i) {
            hamster.boardForward();
        }
        hamster.boardRight();
    }
}

두 번째 우물도 찾아 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        hamster.boardForward();
        hamster.boardRight();
        for(int i = 0; i < 3; ++i) {
            hamster.boardForward();
        }
    }
}

세 번째 우물도 찾아 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        for(int i = 0; i < 2; ++i) {
            hamster.boardForward();
            hamster.boardRight();
            hamster.boardForward();
        }
        hamster.boardForward();
    }
}

네 번째 우물도 찾아 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        hamster.boardRight();
        for(int i = 0; i < 2; ++i) {
            hamster.boardForward();
            hamster.boardRight();
            hamster.boardForward();
            hamster.boardLeft();
        }
    }
}

다섯 번째 우물도 찾아 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        for(int i = 0; i < 3; ++i) {
            hamster.boardForward();
        }
        hamster.boardRight();
        for(int i = 0; i < 3; ++i) {
            hamster.boardForward();
        }
        hamster.boardLeft();
    }
}

여섯 번째 우물도 찾아 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        for(int i = 0; i < 2; ++i) {
            hamster.boardForward();
            hamster.boardRight();
            hamster.boardForward();
        }
        for(int i = 0; i < 2; ++i) {
            hamster.boardForward();
            hamster.boardLeft();
            hamster.boardForward();
        }
    }
}

일곱 번째 우물도 찾아 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        for(int i = 0; i < 3; ++i) {
            for(int j = 0; j < 3; ++j) {
                hamster.boardForward();
            }
            hamster.boardRight();
        }
    }
}

여덟 번째 우물도 찾아 봅시다.

import org.roboid.hamster.Hamster;

public class Controller {
    public static void main(String[] args) {

        Hamster hamster = new Hamster();

        for(int i = 0; i < 2; ++i) {
            for(int j = 0; j < 2; ++j) {
                hamster.boardForward();
                hamster.boardRight();
                hamster.boardForward();
            }
            hamster.boardLeft();
        }
        hamster.boardForward();
        hamster.boardRight();
    }
}
목차
Hardware
  1. Hamster robot
  2. USB dongle
Preparation for Class
  1. Software installation
  2. Robot to PC connection
  3. Run example files
Basic
  1. Create a new project
  2. Work in the cloud PC environment (optional)
  3. Move on a board #1 (sequence, repetition)
  4. Move and turn
  5. Turn on LEDs and make a sound
  6. Command in order repeatedly
  7. Use proximity sensors
  8. Move on a board #2 (repeat while)
  9. Use floor sensors
  10. Use light and acceleration sensors
  11. Braitenberg's robot
Advanced
  1. Create a board game
  2. Keyboard events
  3. Graphical interface
  4. Line following with one sensor
  5. Line following with two sensors
  6. Follow hamster friends (2 people 1 pair)
  7. Follow a wall
  8. Imitating a robot cleaner
  9. Line following at intersection
  10. Escape a maze
Extension Kit
  1. Assembling
  2. Pin/socket layout
  3. Digital input - Press button to beep
  4. Digital output - LED is on when it is dark
  5. Digital output - flashing twinkling LED
  6. Digital output - LED is on in tilting direction
  7. Analog input - Rotating the potentiometer changes the pitch.
  8. Analog input - please do not let it get hot
  9. Analog Input - Move along the light
  10. PWM output - LED light gently brighter and darker
  11. PWM output - LED candle shakes in the wind
  12. Analog servo output - hamster robot has tail
More Advanced
  1. Behavior based robot control
  2. Path navigation
  3. Swap
Copyright Robot Software Education Institute. All rights reserved.
Please contact prof. Kwang-Hyun Park (akaii@kw.ac.kr) if you have any problem.