ROS 학습 - nao 로봇 개발

4250 단어 로보트Python
회사 에는 몇 개의 nao 로봇 이 있 는데 주로 음성 인식 합성 등 기능 을 마 운 트 하여 대외 적 으로 시연 하기 위해 사용 된다.
최근 며칠 동안 하나의 기능 을 수정 하 는 데 도움 을 주 었 을 때 nao 의 문 서 를 보 았 습 니 다. 주 소 는 다음 과 같 습 니 다.
http://doc.aldebaran.com/2-1/getting_started/helloworlds.html
nao 로봇 의 시스템 도 Liux 를 바탕 으로 디자인 방향 은 ROS 와 비슷 한 부분 이 많아 서 학습 에 비해 깊이 이해 할 수 있 습 니 다.
ROS 의 주요 개념 은 노드 (node), 주제 (topic), 메시지 (message), 서비스 (server. ice) 가 있다.그 밖 에 또 하나의 중심 노드 가 있 는데 그것 이 바로 시작 할 때 실행 되 는 roscore 이 고 이미 시 작 된 노드 를 유지 하 며 각 노드 간 의 메시지 전달 을 유지 하 는 것 을 책임 집 니 다.
nao 로봇 에 대응 하 는 naoqi 시스템 에서 먼저 메 인 노드 인 Broker 도 있 습 니 다. 기본 포트 는 바로 이 컴퓨터 IP, 포트 9559 입 니 다.한편, 로봇 의 구체 적 인 기능 노드 를 module 이 라 고 부른다. 만약 에 우리 가 자신의 프로그램 에서 로봇 에 내 장 된 module 또는 제3자 의 module 를 호출 하려 면 메 인 Broker 를 연결 하고 Proxy 로 이 module 를 예화 하면 된다. 여기 서 예화 가 정확 하지 않 고 PRC 프로 토 콜 과 유사 한 원 격 호출 을 느 낄 수 있다.
그러면 우 리 는 모듈 을 개발 하고 실행 하려 고 하 는데 어떻게 처리 해 야 합 니까?
사실은 매우 편리 합 니 다. module 을 계승 하면 자신의 기능 을 실현 하 는 module 을 개발 할 수 있 습 니 다. 그리고 Broker 를 만 들 고 위 에서 언급 한 메 인 broker 를 '이 Broker 의 아버지 Broker' 로 지정 하면 됩 니 다. 그러면 이 broker 를 실행 한 후에 당신 의 broker 는 이 module 을 메 인 broker 에 등록 하 는 것 을 책임 집 니 다.이 모듈 을 사용 하 는 방식 도 nao 에 내 장 된 모듈 을 사용 하 는 것 과 다 르 지 않다.
다음은 문서 의 예 입 니 다.
# -*- encoding: UTF-8 -*-
""" Say 'hello, you' each time a human face is detected

"""

import sys
import time

from naoqi import ALProxy
from naoqi import ALBroker
from naoqi import ALModule

from optparse import OptionParser

NAO_IP = "nao.local"


# Global variable to store the HumanGreeter module instance
HumanGreeter = None
memory = None


class HumanGreeterModule(ALModule):
    """ A simple module able to react
    to facedetection events

    """
    def __init__(self, name):
        ALModule.__init__(self, name)
        # No need for IP and port here because
        # we have our Python broker connected to NAOqi broker

        # Create a proxy to ALTextToSpeech for later use
        self.tts = ALProxy("ALTextToSpeech")

        # Subscribe to the FaceDetected event:
        global memory
        memory = ALProxy("ALMemory")
        memory.subscribeToEvent("FaceDetected",
            "HumanGreeter",
            "onFaceDetected")

    def onFaceDetected(self, *_args):
        """ This will be called each time a face is
        detected.

        """
        # Unsubscribe to the event when talking,
        # to avoid repetitions
        memory.unsubscribeToEvent("FaceDetected",
            "HumanGreeter")

        self.tts.say("Hello, you")

        # Subscribe again to the event
        memory.subscribeToEvent("FaceDetected",
            "HumanGreeter",
            "onFaceDetected")


def main():
    """ Main entry point

    """
    parser = OptionParser()
    parser.add_option("--pip",
        help="Parent broker port. The IP address or your robot",
        dest="pip")
    parser.add_option("--pport",
        help="Parent broker port. The port NAOqi is listening to",
        dest="pport",
        type="int")
    parser.set_defaults(
        pip=NAO_IP,
        pport=9559)

    (opts, args_) = parser.parse_args()
    pip   = opts.pip
    pport = opts.pport

    # We need this broker to be able to construct
    # NAOqi modules and subscribe to other modules
    # The broker must stay alive until the program exists
    myBroker = ALBroker("myBroker",
       "0.0.0.0",   # listen to anyone
       0,           # find a free port and use it
       pip,         # parent broker IP
       pport)       # parent broker port


    # Warning: HumanGreeter must be a global variable
    # The name given to the constructor must be the name of the
    # variable
    global HumanGreeter
    HumanGreeter = HumanGreeterModule("HumanGreeter")

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print
        print "Interrupted by user, shutting down"
        myBroker.shutdown()
        sys.exit(0)



if __name__ == "__main__":
    main()

좋은 웹페이지 즐겨찾기