CoDrone Basic


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) WEEK2"

Table of Contents

1. Calibration & Flight

1.1. Calibration

[1] Calibration 시행하기전 반드시 조교의 허락을 받으세요

[2] 드론을 뒤집어 드론의 Arm 에 있는 LED 가 흰색으로 깜박일 때까지 드론의 양 옆을 꾹 누릅니다.

[3] 드론이 흰색으로 깜박이면, 평평한 바닥에 놓습니다. 곧 드론이 자동으로 Calibration을 하는 비행을 합니다.

[4] 드론이 착륙하면 Calibration 이 완료된 것입니다.

1.2. Basic Drone Flight

[1] 페어링

In [1]:
from CoDrone.codrone import *

drone = CoDrone()
drone.pair('3218') 

if drone.isConnected():
    print('Codrone이 성공적으로 페어링되었습니다.')

[2] 이륙/착륙

In [2]:
drone.takeoff()

drone.hover(1)
drone.land()

[3] 전진

In [3]:
drone.takeoff()

drone.go(Direction.FORWARD, 1)
drone.land()

2. Movement Command

2.1. Takeoff and Landing

  • Previously, we have only used this command.


In [4]:
drone.takeoff()

drone.hover(3)
drone.land()

2.2 Throttle

  • Throttle controls the vertical up and down motion of the drone. Positive throttle will make the drone fly higher and negative throttle will make the drone fly lower.


In [5]:
drone.takeoff()

# -100 to 100 that sets the pitch variable.
# Drone goes up for 1 second with 50 power
drone.set_throttle(100)
drone.move(1)

2.3 Yaw

  • Yaw is the left and right rotation of the drone. Positive yaw will make the drone turn to the right and negative yaw will make the drone turn to the left.


In [6]:
drone.takeoff()

# -100 to 100 that sets the pitch variable.
# Drone turns right for 1 second with 50 power
drone.set_yaw(-100)
drone.move(1)

2.4 Pitch

  • Pitch is the forward and backward tilt of the drone. positive pitch will make the drone tilt and move forward and negative pitch will make the drone tilt and move backwards.


In [7]:
drone.takeoff()

# -100 to 100 that sets the pitch variable.
# Drone goes right for 1 second with 50 power
drone.set_pitch(50)
drone.move(1)

2.5 Roll

  • Roll is the side to side tilt of the drone. Positive roll will make the drone tilt to the right and negative roll will make the drone tilt to the left.


In [8]:
drone.takeoff()

# -100 to 100 that sets the pitch variable.
# Drone goes right for 1 second with 50 power
drone.set_roll(50)
drone.move(1)

3. CoDorne Library Reference

[1] CoDrone Library Reference 를 참고하여 드론으로 다각형을 그려보세요

[2] LED 명령 코드와 Movement 명령 코드를 조합하여 아래처럼 다양한 Episode 를 만들어보세요

  • 방향 전환할 때마다 LED 색이 바뀌면서 사각형을 그리는 Episode
  • N second 상승할 때마다, LED 가 N 번 깜박이는 Episode
In [9]:
# fill your code

4. Sensors

4.1. Drone State

This function gets the state of the drone, as in whether it’s: ready, takeoff, flight, flip, stop, landing, reverse, accident, error.

In [10]:
# take off the drone if state is not on flight
state = drone.get_state()
if state != "FLIGHT":
    drone.takeoff()

drone.hover(3)
drone.land()

4.2. Optical Flow Sensor

This function gets the $x$ and $y$ coordinates from the optical flow sensor. Keep in mind, the positioning does not take rotation into account.

In [11]:
# print the optical flow position x,y value
position = drone.get_opt_flow_position()
print(position.X, position.Y)

4.3. Battery Voltage

This function gets the voltage of the battery.

In [12]:
# print the battery voltage of drone.
battery = drone.get_battery_voltage()
print(battery)

4.4. Temperature

This is a getter function gets the data from the drone’s temperature sensor. Importantly, it reads the drone’s temperature, not the air around it.

In [13]:
# print the temperature of drone
temperature = drone.get_drone_temp()
print(temperature)

4.5. Pressure

This is a getter function gets the data from the barometer sensor.

In [14]:
# print the pressure
pressure = drone.get_pressure()
print(pressure)

4.6. Trim

This function gets the current trim values of the drone.

In [15]:
#print current drone's trim value
trim = drone.get_trim()
print(trim.ROLL, trim.PITCH, trim.YAW, trim.THROTTLE)

4.7. Height

This is a getter function gets the current height of the drone from the object directly below its IR sensor.

In [16]:
drone.takeoff()

for i in range(100):
    height = drone.get_height()
    print(height)
    if height < 1000:
        drone.go(Direction.UP)
    elif height > 1000:
        break
drone.hover(2)

drone.land()

4.8. Accelerometer

This function gets the accelerometer sensor data, which returns $x$, $y$, and $z$ values in $m/s^2$. It outputs to the UI in Blockly and as a class in Python as a struct in Arduino.

In [17]:
# print the acceleration of drone
acceleration = drone.get_accelerometer()
print(acceleration.X, acceleration.Y, acceleration.Z)

4.9. Gyro Sensor

This function gets the data from the gyrometer sensor to determine the roll, pitch, and yaw as angles.

In [18]:
# print the angles of drone
GyroAngles = drone.get_gyro_angles()
print(GyroAngles.ROLL, GyroAngles.PITCH, GyroAngles.YAW)

4.10. Battery

This function gets the battery percentage of the drone, returning a value from 0 to 100.

In [19]:
drone.takeoff()

# stop the drone if battery is lower than 10 percent.
battery = drone.get_battery_percentage()
if battery < 10:
    drone.emergency_stop()
In [20]:
%%javascript

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