Showing
1 changed file
with
38 additions
and
0 deletions
yujin_test/landByInput.py
0 → 100644
| 1 | +# 드론 착륙 by 키보드; 테스트 코드 (드론 1대용) | ||
| 2 | +import CoDrone | ||
| 3 | +import keyboard | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +def getPosition(drone): | ||
| 7 | + position = drone.get_opt_flow_position() # 상대좌표 (시작 0,0) | ||
| 8 | + height = drone.get_height() # 고 | ||
| 9 | + print("x={} y={} z={}".format(position.X, position.Y, height)) # 단위(mm) | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +def main(): | ||
| 13 | + drone = CoDrone.CoDrone() | ||
| 14 | + drone.connect() | ||
| 15 | + | ||
| 16 | + drone.takeoff() # 이륙 | ||
| 17 | + | ||
| 18 | + while True: | ||
| 19 | + getPosition(drone) | ||
| 20 | + if keyboard.is_pressed('q'): # 키보드에서 'q'가 입력되면 while문 탈출 | ||
| 21 | + print('Keyboard input occur: Quit!') | ||
| 22 | + break | ||
| 23 | + elif not drone.isConnected(): # 연결이 끊기면 프로그램 종료 | ||
| 24 | + print('Disconnected') | ||
| 25 | + return | ||
| 26 | + | ||
| 27 | + print('드론을 착륙시킵니다.') | ||
| 28 | + drone.arm_pattern() # LED 효과 | ||
| 29 | + print('Land') | ||
| 30 | + drone.land() # 착륙 | ||
| 31 | + drone.disconnect() # 연결해제 | ||
| 32 | + | ||
| 33 | + | ||
| 34 | +if __name__ == '__main__': | ||
| 35 | + main() | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + |
-
Please register or login to post a comment