ping

Ping ν…ŒμŠ€νŠΈ

  • 쑰쒅기에 Ping을 보내고, Ack 응닡을 λ°›μ•„μ„œ 화면에 좜λ ₯ν•˜λŠ” μ˜ˆμ œμž…λ‹ˆλ‹€.

  • sendPing() ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•˜κ³  응닡을 받을 λ•ŒκΉŒμ§€ κΈ°λ‹€λ¦¬λŠ” μ‹œκ°„μ΄ ν•„μš”ν•˜κΈ° λ•Œλ¬Έμ— sleep() ν•¨μˆ˜λ₯Ό μ‚¬μš©ν–ˆμŠ΅λ‹ˆλ‹€.

  • 데이터 μ†‘μˆ˜μ‹  κ³Όμ •μ—μ„œ λ¬Έμ œκ°€ 생겨 Ackλ₯Ό 받지 λͺ»ν•˜λŠ” κ²½μš°κ°€ μžˆμ„ 수 μžˆμœΌλ―€λ‘œ 1초 λ™μ•ˆ 응닡이 μ—†μœΌλ©΄ μˆ˜μ‹ μ²˜λ¦¬λ₯Ό μ’…λ£Œν•˜κ²Œ ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

from time import sleep

from e_drone.drone import *
from e_drone.protocol import *


if __name__ == '__main__':

    drone = Drone(False)
    drone.open()

    drone.sendPing(DeviceType.Controller)

    timeStart = time.time()

    while True:
        sleep(0.01)
        dataType = drone.check()

        if dataType == DataType.Ack:
            ack = drone.getData(DataType.Ack)
            print("{0} / {1} / {2:04X}".format(ack.dataType.name, ack.systemTime, ack.crc16))
            print("T: {0}".format(time.time() - timeStart))
            break;

        # 1초 λ™μ•ˆ 응닡이 없을 경우 응닡 확인을 λΉ μ Έλ‚˜κ°
        if time.time() > timeStart + 1:
            print("Time Over")
            break;

    drone.close()

Ping ν…ŒμŠ€νŠΈ(이벀트 ν•¨μˆ˜ 등둝)

  • 쑰쒅기에 Ping을 보내고, Ack 응닡을 λ°›μ•„μ„œ 화면에 좜λ ₯ν•˜λŠ” μ˜ˆμ œμž…λ‹ˆλ‹€.

  • μˆ˜μ‹  받을 데이터λ₯Ό μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜λ₯Ό λ§Œλ“€μ–΄ setEventHandler(DataType, function)λ₯Ό μ‚¬μš©ν•˜μ—¬ λ“±λ‘ν•˜λ©΄ ν•΄λ‹Ή 데이터λ₯Ό λ°›μ•˜μ„ λ•Œ 미리 μ—°κ²°ν•œ ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•©λ‹ˆλ‹€.

  • λ§ˆμ§€λ§‰ sleep(0.1)은 Ping 전솑 ν›„ Ack 응닡이 λ“€μ–΄μ˜¬ λ•ŒκΉŒμ§€ 기닀리기 μœ„ν•΄ μ‚¬μš©ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

from time import sleep

from e_drone.drone import *
from e_drone.protocol import *


def eventAck(ack):
    print("eventAck()")
    print("{0} / {1} / {2:04X}".format(ack.dataType.name, ack.systemTime, ack.crc16))


if __name__ == '__main__':

    drone = Drone()
    drone.open()

    # 이벀트 핸듀링 ν•¨μˆ˜ 등둝
    drone.setEventHandler(DataType.Ack, eventAck)

    # Ping 전솑
    drone.sendPing(DeviceType.Controller)
    
    sleep(0.1)

    drone.close()

Last updated