利用Microsoft Robotics Studio远程控制机器人


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)处理主端口的消息,备用端口处理备用端口的消息。

现在为备用端口的消息添加消息处理方法:
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 ));

注意你需要为主端口和备用端口的相同的消息实现不同处理方法,比如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消息处理方法中,需要将子类转换为父类(ContactSensorArrayState),因为在将状态对象序列化时,是序列化它实际的对象类型,假如你想获取基类型的序列化对象,但是实际获得的却是子类对象,所以状态类显式实现了Clone()方法进行类型转换,而不是利用隐式转换!!
最后

说实话,俺没怎么接触过硬件,虽然学的是硬件相关的专业,文章是MSDN里的一篇《Robotics Tutorial 6 (C#) - Remotely Connected Robots》,最近学这个东东,英文看完眼睛疼,而且看完英文就好像什么都没记住一样,我想翻译出来会好些吧?虽然本文没有什么思想之类的东西……,语言也不太顺畅,如果你没接触过Microsoft Robotics Studio ,看起了可能比较难,这个博客=》laneser 对Robotics Studio研究的比较深,可惜只是他不再更新了。

噢耶!You Potential!Our Passoin!

 

Tags:机器人控制