26 CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate,
27 Optional = false
28 )]
29 private brick.MyBrickServiceOperations _brickPort = new brick.MyBrickServiceOperations();
30 [Partner(
31 "SubMgr",
32 Contract = submgr.Contract.Identifier,
33 CreationPolicy = PartnerCreationPolicy.CreateAlways,
34 Optional = false)]
35 private submgr.SubscriptionManagerPort _subMgrPort = new submgr.SubscriptionManagerPort();
36
37
注意:主端口(main port)處理主端口的消息,備用端口處理備用端口的消息。
現(xiàn)在為備用端口的消息添加消息處理方法:
1 // Listen on the main port for requests and call the appropriate handler.
2 Interleave mainInterleave = ActivateDsspOperationHandlers();
3 //listen on alternate service port for requests and call the appropriate handler.
4 mainInterleave.CombineWith(new Interleave(
5 new TeardownReceiverGroup(
6 Arbiter.Receive(
7 false,
8 _bumperPort,
9 DefaultDropHandler
10 )
11 ),
12 new ExclusiveReceiverGroup(
13 Arbiter.ReceiveWithIterator(
14 true,
15 _bumperPort,
16 ReplaceHandler
17 ),
18 Arbiter.ReceiveWithIterator(
19 true,
20 _bumperPort,
21 SubscribeHandler
22 ),
23 Arbiter.ReceiveWithIterator(
24 true,
25 _bumperPort,
26 ReliableSubscribeHandler
27 )
28 ),
29 new ConcurrentReceiverGroup(
30 Arbiter.ReceiveWithIterator(
31 true,
32 _bumperPort,
33 GetHandler
34 ),
35 Arbiter.Receive(
36 true,
37 _bumperPort,
38 DefaultLookupHandler
39 )
40 )
41 ));
注意你需要為主端口和備用端口的相同的消息實(shí)現(xiàn)不同處理方法,比如Get,Replace,Dubscribe等,Get消息的處理方法如下:
1 [ServiceHandler(ServiceHandlerBehavior.Concurrent)]
2 public IEnumerator MyGetHandler(Get get)
3 {
4 get.ResponsePort.Post(_state);
5 yield break;
6 }
7 public IEnumerator GetHandler(bumper.Get get)
8 {
9 get.ResponsePort.Post(bumper.ContactSensorArrayState)_state.Clone());
10 yield break;
11 }
注意:在后面的Get消息處理方法中,需要將子類轉(zhuǎn)換為父類(ContactSensorArrayState),因?yàn)樵趯顟B(tài)對象序列化時,是序列化它實(shí)際的對象類型,假如你想獲取基類型的序列化對象,但是實(shí)際獲得的卻是子類對象,所以狀態(tài)類顯式實(shí)現(xiàn)了Clone()方法進(jìn)行類型轉(zhuǎn)換,而不是利用隱式轉(zhuǎn)換??!
最后
說實(shí)話,俺沒怎么接觸過硬件,雖然學(xué)的是硬件相關(guān)的專業(yè),文章是MSDN里的一篇《Robotics Tutorial 6 (C#) - Remotely Connected Robots》,最近學(xué)這個東東,英文看完眼睛疼,而且看完英文就好像什么都沒記住一樣,我想翻譯出來會好些吧?雖然本文沒有什么思想之類的東西……,語言也不太順暢,如果你沒接觸過Microsoft Robotics Studio ,看起了可能比較難,這個博客=》laneser 對Robotics Studio研究的比較深,可惜只是他不再更新了。
噢耶!You Potential!Our Passoin!
Tags:機(jī)器人控制