CoDrone Setup


By Prof. Seungchul Lee
http://iai.postech.ac.kr/
Industrial AI Lab at POSTECH

  • Please submit the following files after today's class.
    • ipynb files
    • Demonstration videos of your drone
  • TA's E-mail : juwonna7@postech.ac.kr
    • The title of your mail should be "[MECH199-01][Drone & RC Car] (Group Name) WEEK1"

Table of Contents

1. Course Overview

  • To provide freshmen a chance to experience system design through mechatronics practice of drone and mobile robot project.
  • Drone project (semi-project)
    • Understand drones' flight principles
    • Use Python to control drones
    • Perform simple missions using Python coding
  • Mobile robot project (final-term project)
    • Understand the theory of sensors and communication methods
    • Combine software and hardware to create a single system

1.1. Drone Control Project

  • Codrone Specification



  • Basics for quadcopter movement

  • Principles of driving method and concept of hovering


  • Tentative mission
    • Assume a disaster situation
    • Control their drone to pass through obstacles, burst a balloon in a fire building, and return to land at a designated landing point


  • Drone Control Project (Video)


1.2. Mobile Robot Project

  • Mobile Robot Specification
    • Car design is the responsibility of students


  • Time Attack Mission


  • Mobile Robot Project (Video)


2. Python Setup

[1] Python 3.5.2 installer download

[2] Run the installer

  • You must add Python 3.5 to PATH

[3] Make sure the installation is good

  • Type "python" in the Windows Command Prompt

[4] Jupyter notebook & CoDrone installation

  • Type "pip install jupyter CoDrone" in the Windows Command Prompt

[5] Running Jupyter notebook

  • Type 'Jupyter notebook' in folder's domain

[6] Create Jupyter notebook

  • Click 'New'
  • Select 'Python 3'

2.1. Python Basic Coding

[1] Variable

In [1]:
x = 3 
y = 3.14
greet = "Hello World"

[2] Print

In [2]:
print("안녕하세요")
print(greet)
안녕하세요
Hello World

[3] Basic Operator

  • Python Arithmetic Operators
  • Python Comparison Operators
  • Python Logical Operators
In [3]:
print(x + y)
print(x < y)
print(x == y)
print(x < y or x > y)
6.140000000000001
True
False
True

[4] If statement

In [4]:
if x < y :
    print("x가 y보다 작습니다.")

if x < y :
    print("x가 y보다 작습니다.")
elif x == y:
    print("x와 y가 같습니다.")
else:
    print("x가 y보다 큽니다.")
x가 y보다 작습니다.
x가 y보다 작습니다.

[5] For / While statement

In [5]:
print('For Loop:')
for i in range(10):
    print(i, end=' ')
    
print('\nWhile Loop:')
i = 0
while i < 10:
    print(i, end=' ')
    i += 1
For Loop:
0 1 2 3 4 5 6 7 8 9 
While Loop:
0 1 2 3 4 5 6 7 8 9 

3. CoDrone Steup

3.1. Drone Bluetooth Module Connection

[1] CP210X_Universal_Windows_Driver 설치

[2] CP210x_Universal_Windows_Driver.zip 압축해제

[3] CP210x_Universal_Windows_Driver 폴더에서 아래 설치파일들 중 자신의 OS 에 맞는 설치파일 실행

  • CP210xVCPInstaller_x64 (64 Bit)
  • CP210xVCPInstaller_x86 (32 Bit)

[4] Bluetooth Module 을 노트북에 연결 (USB 포트)

[5] 윈도우 마크 우클릭 후 장치 관리자 열어서 포트에 아래 항목이 연결되어있는지 확인

  • Silicon Labs CP210x USB to UART Bridge

3.2. Drone Pairing

[1] Jupyter Notebook 실행

[2] Bluetooth Module 을 아래처럼 master mode 로 설정

- 1 : off, 2 : on

[3] CoDrone Library Import

In [6]:
from CoDrone.codrone import *

[4] Pairing Code 실행 (Nearest Drone Pairing)

In [7]:
drone = CoDrone()
drone.pair(drone.Nearest)
    
if drone.isConnected():
    print('Codrone이 성공적으로 페어링되었습니다.')
    
drone.close()
>> Port : [COM3]
>> Drone : [3218]
>> Battery : [0]
>> Low Battery!!
Codrone이 성공적으로 페어링되었습니다.

[5] 4자리 정수의 Address 을 기록하여 다음 페이링부터는 Address 로 페어링 할 수 있도록 함 (본 예제의 경우 3218)

In [8]:
drone = CoDrone()
drone.pair('3218')

if drone.isConnected():
    print('Codrone이 성공적으로 페어링되었습니다.')
>> Port : [COM3]
>> Drone : [3218]
>> Battery : [0]
>> Low Battery!!
Codrone이 성공적으로 페어링되었습니다.

[6] 드론의 후미등이 BLINK 에서 Solid로 바뀌었는지 확인

[7] 아래 error가 뜰 경우에는 Bluetooth Module 을 뽑았다가 다시 연결하세요

  • SerialException: could not open port 'COM#' : PermissionError(#, '액세스가 거부되었습니다.', None, #)

4. Turn on LED

4.1. CoDrone Library

[1] CoDrone Library Reference page 열기

[2] Reference 를 참고하되 Tap key 를 이용하여 함수 사용에 어려움이 없도록 하세요

4.2. LED Control

[1] 예제 코드

In [9]:
if drone.isConnected():
    drone.set_all_led(Color.Green, Mode.BLINK)
    sleep(5)
    drone.set_all_led(Color.Green, Mode.OFF)

[2] 예제 코드의 함수 외에 다른 함수를 사용하여 LED 조절해보세요.

In [10]:
# fill your code
In [11]:
%%javascript

$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')