CHOU

[MSRDS] Robot Service - BumperSensor_1 본문

Tech/Microsoft Products

[MSRDS] Robot Service - BumperSensor_1

chobabo 2009. 4. 8. 19:47


 로봇 제어를 위해 필요한 기능을 생각해 보면 기본적으로 모터를 제어하고, 입력 받은 센서를 적절히 처리해야 하며, 통합적인 관리 정도라고 생각합니다. 물론 세부적으로 들어가 보면 더욱 많은 기능들이 필요하겠지만, 저는 한동안 Pioneer3DX를 제어해 보기 위한 기본적인 서비스만 생각해 보려 합니다. 

 MSRDS 네이버 카페에 김영준 수석님께서 올려주신 범퍼센서 만들기 예제를 수행해 보면서 로봇 서비스 개발을 이해해 보고, 나아가 통합적으로 구현하는 Brick 개념에 대해 공부해 보겠습니다.

우선 Bumper Service 구현에 앞서, 타이머를 구현 하겠습니다. 타이머는 로봇 서비스와는 관계가 없지만, 범퍼 서비스에서 범퍼 데이터를 가상으로 생성할 때 이용하기 위해 구현해야 합니다^^;

1. 우선 Visual C# 프로젝트 창에서 DSS 2.0 프로젝트를 실행합니다.




 프로젝트 창이 실행이 되면 New Dss Service 창이 뜨는데 특별한 옵션을 부여하지 않는 이상 그냥 OK 하면 됩니다. 물론 개발자의 취향에 맞게 적절한 옵션을 주는 것도 나쁘지는 않습니다.  

 





2. 코드가 실행되면 프로젝트이름.cs 파일을 열어서 다음과 같이 코드를 추가해 줍니다. 아래 코드에서 빨간 부분만 추가하면 됩니다.

using System;
using System.Collections.Generic;
using System.ComponentModel;

using Microsoft.Ccr.Core;

//add using definition
using Microsoft.Dss.Core;
using System.Xml;
//----------------------
using Microsoft.Dss.Core.Attributes;
using Microsoft.Dss.ServiceModel.Dssp;
using Microsoft.Dss.ServiceModel.DsspServiceBase;
using W3C.Soap;
using submgr = Microsoft.Dss.Services.SubscriptionManager;


namespace testTimerService
{
    [Contract(Contract.Identifier)]
    [DisplayName("testTimerService")]
    [Description("testTimerService service (no description provided)")]
    class testTimerService : DsspServiceBase
    {
        /// <summary>
        /// Service state
        /// </summary>
        [ServiceState]
        testTimerServiceState _state = new testTimerServiceState();

        /// <summary>
        /// Main service port
        /// </summary>
        [ServicePort("/testTimerService", AllowMultipleInstances = true)]
        testTimerServiceOperations _mainPort = new testTimerServiceOperations();

        [SubscriptionManagerPartner]
        submgr.SubscriptionManagerPort _submgrPort = new submgr.SubscriptionManagerPort();

        /// <summary>
        /// Service constructor

        private Port<DateTime> _timePort = new Port<DateTime>();

        /// </summary>
        public testTimerService(DsspServiceCreationPort creationPort)
            : base(creationPort)
        {
        }

        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {

            //
            // Add service specific initialization here
            //

            base.Start();

            // 타이머 최초 구동명령
            _timePort.Post(DateTime.Now);
            Activate(Arbiter.Receive(true, _timePort, TimerHandler));

        }

        /// <summary>
        /// Handles Subscribe messages
        void TimerHandler(DateTime signal)
        {
            //현재 날짜와 시간을 콘솔에 출력함
            LogInfo(LogGroups.Console, "[[[타이머모듈발생]]] " + System.DateTime.Now.ToString());

            Activate(
                Arbiter.Receive(false, TimeoutPort(1000),
                    delegate(DateTime time)
                    {
                        _timePort.Post(time);
                    }
                )
            );
        }
        /// </summary>
        /// <param name="subscribe">the subscribe request</param>
        [ServiceHandler]
        public void SubscribeHandler(Subscribe subscribe)
        {
            SubscribeHelper(_submgrPort, subscribe.Body, subscribe.ResponsePort);
        }
    }
}


3. 올바르게 코드를 삽입하고 컴파일을 해보면 1초 간격으로 메세지가 발생되는 것을 볼 수 있습니다^^




아래 영상은 결과수행을 보여주고 있습니다.




참고자료

1. http://cafe.naver.com/msrskorea

2. 예제 코드파일