WEB开发网
开发学院软件开发C语言 利用Microsoft Robotics Studio远程控制机器人 阅读

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

 2009-05-21 08:30:05 来源:WEB开发网   
核心提示: 首先,添加自定阅操作到类型文件(type file):1 public class MyBrickServiceOperations : PortSet2 <3 DsspDefaultLookup,4 DsspDefaultDrop,5 Get,6 //IMPORTANT: Beca

首先,添加自定阅操作到类型文件(type file):

 1 public class MyBrickServiceOperations : PortSet
 2 <
 3 DsspDefaultLookup,
 4 DsspDefaultDrop,
 5 Get,
 6 //IMPORTANT: Because SelectiveSubscribe inherits from Subscribe, it must go on top.
 7 SelectiveSubscribe,
 8 Subscribe
 9 > {}
10 //The standard subscription
11 public class Subscribe : Subscribe
12 <
13 SubscribeRequestType,
14 PortSet
15 <
16 subscriberesponsetype
17 >
18 > {}
19 //The custom subscription
20 public class SelectiveSubscribe : Subscribe
21 <
22 MySubscribeRequestType,
23 PortSet
24 <
25 SubscribeResponseType,
26 Fault
27 >
28 > { }
29 [DataContract]
30 public class MySubscribeRequestType : SubscribeRequestType
31 {
32 //The list of sensors to subscribe to
33 [DataMember]
34 public List Sensors;
35 }
36 

现在添加handler到实现文件(implementation file)

 1 // General Subscription
 2 [ServiceHandler(ServiceHandlerBehavior.Exclusive)]
 3 public IEnumerator SubscribeHandler(Subscribe subscribe)
 4 {
 5 base.SubscribeHelper
 6 (
 7 subMgrPort,
 8 subscribe.Body,
 9 subscribe.ResponsePort
10 );
11 yield break;
12 }
13 // Custom Subscription
14 [ServiceHandler(ServiceHandlerBehavior.Exclusive)]
15 public IEnumerator SelectiveSubscribeHandler(SelectiveSubscribe subRequest)
16 {
17 submgr.InsertSubscription selectiveSubscription = new submgr.InsertSubscription
18 (
19 new submgr.InsertSubscriptionMessage
20 (
21 subRequest.Body.Subscriber,
22 subRequest.Body.Expiration,
23 0
24 )
25 );
26 selectiveSubscription.Body.NotificationCount = subRequest.Body.NotificationCount;
27 List subscribeFilter = new List();
28 //items in this loop are OR'ed together in the subscription
29 foreach (string s in subRequest.Body.Sensors)
30 {
31 LogInfo("Adding subscription for: " + s.ToUpper());
32 //you can achieve an AND behavior by adding a list of strings in the new QueryType
33 subscribeFilter.Add(new submgr.QueryType(s.ToUpper()));
34 }
35 selectiveSubscription.Body.QueryList = subscribeFilter.ToArray();
36 subMgrPort.Post(selectiveSubscription);
37 yield return Arbiter.Choice
38 (
39 selectiveSubscription.ResponsePort,
40 delegate(dssp.SubscribeResponseType response)
41 {
42 subRequest.ResponsePort.Post(response);
43 },
44 delegate(Fault fault)
45 {
46 subRequest.ResponsePort.Post(fault);
47 });
48 yield break;
49 }
50 selectiveSubscription.Body.NotificationCount = subRequest.Body.NotificationCount;
51 List subscribeFilter = new List();
52 //items in this loop are OR'ed together in the subscription
53 foreach (string s in subRequest.Body.Sensors)
54 {
55 LogInfo("Adding subscription for: " + s.ToUpper());
56 //you can achieve an AND behavior by adding a list of strings in the new QueryType
57 subscribeFilter.Add(new submgr.QueryType(s.ToUpper()));
58 }
59 selectiveSubscription.Body.QueryList = subscribeFilter.ToArray();
60 subMgrPort.Post(selectiveSubscription);
61 yield return Arbiter.Choice
62 (
63 selectiveSubscription.ResponsePort,
64 delegate(dssp.SubscribeResponseType response)
65 {
66 subRequest.ResponsePort.Post(response);
67 },
68 delegate(Fault fault)
69 {
70 subRequest.ResponsePort.Post(fault);
71 }
72 );
73 yield break;
74 }
75 

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:利用 Microsoft Robotics

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接