CoDrone Basic
Table of Contents
[1] 페어링
from CoDrone.codrone import *
drone = CoDrone()
drone.pair('3218')
if drone.isConnected():
print('Codrone이 성공적으로 페어링되었습니다.')
[2] 이륙/착륙
drone.takeoff()
drone.hover(1)
drone.land()
[3] 전진
drone.takeoff()
drone.go(Direction.FORWARD, 1)
drone.land()
drone.takeoff()
drone.hover(3)
drone.land()
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)
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)
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)
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)
[1] CoDrone Library Reference 를 참고하여 드론으로 다각형을 그려보세요
[2] LED 명령 코드와 Movement 명령 코드를 조합하여 아래처럼 다양한 Episode 를 만들어보세요
# fill your code
This function gets the state of the drone, as in whether it’s: ready, takeoff, flight, flip, stop, landing, reverse, accident, error.
# take off the drone if state is not on flight
state = drone.get_state()
if state != "FLIGHT":
drone.takeoff()
drone.hover(3)
drone.land()
This function gets the $x$ and $y$ coordinates from the optical flow sensor. Keep in mind, the positioning does not take rotation into account.
# print the optical flow position x,y value
position = drone.get_opt_flow_position()
print(position.X, position.Y)
This function gets the voltage of the battery.
# print the battery voltage of drone.
battery = drone.get_battery_voltage()
print(battery)
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.
# print the temperature of drone
temperature = drone.get_drone_temp()
print(temperature)
This is a getter function gets the data from the barometer sensor.
# print the pressure
pressure = drone.get_pressure()
print(pressure)
This function gets the current trim values of the drone.
#print current drone's trim value
trim = drone.get_trim()
print(trim.ROLL, trim.PITCH, trim.YAW, trim.THROTTLE)
This is a getter function gets the current height of the drone from the object directly below its IR sensor.
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()
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.
# print the acceleration of drone
acceleration = drone.get_accelerometer()
print(acceleration.X, acceleration.Y, acceleration.Z)
This function gets the data from the gyrometer sensor to determine the roll, pitch, and yaw as angles.
# print the angles of drone
GyroAngles = drone.get_gyro_angles()
print(GyroAngles.ROLL, GyroAngles.PITCH, GyroAngles.YAW)
This function gets the battery percentage of the drone, returning a value from 0 to 100.
drone.takeoff()
# stop the drone if battery is lower than 10 percent.
battery = drone.get_battery_percentage()
if battery < 10:
drone.emergency_stop()
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')