利用Microsoft Robotics Studio远程控制机器人
2009-05-21 08:30:05 来源:WEB开发网扩展状态
前面的模式很容易实现并且在大多数情况下可以正常工作,因为状态和操作是通用的,但是,有时候我们还是想为状态添加一些信息或者添加一些操作类型,一个好的例子就是 sonar as bumper 服务,这个服务使用声波传感器代替一个碰撞传感器,这个服务实现了ContactSensorArray服务的Contract,除非你自己想添加自己状态,你需要这样的做的原因是这个服务需要包括一个距离和阈值的数据信息,这些在Contract服务没有给出。
注意你的状态类是继承自ContactSensorArrayState 。
调整实现文件:
1
2 using bumper = Microsoft.Robotics.Services.ContactSensor.Proxy;
3 using brick = Robotics.MyBrickService.Proxy;
4 using submgr = Microsoft.Dss.Services.SubscriptionManager;
5 namespace Robotics.MyRobotSonarAsBumper
6 {
7 [Contract(Contract.Identifier)]
8 [AlternateContract(bumper.Contract.Identifier)]
9 [PermissionSet(SecurityAction.PermitOnly, Name="Execution")]
10 public class MyRobotSonarAsBumperService : DsspServiceBase
11 {
12 [InitialStatePartner(Optional = true)]
13 private MyRobotSonarAsBumperState _state;
14 [ServicePort("/MyRobotSonarAsBumper", AllowMultipleInstances = true)]
15 private MyRobotSonarAsBumperOperations _mainPort = new MyRobotSonarAsBumperOperations();
16 [AlternateServicePort(
17 "/MyRobotBumper",
18 AllowMultipleInstances = true,
19 AlternateContract=bumper.Contract.Identifier
20 )]
21 private bumper.ContactSensorArrayOperations
22 _bumperPort = new bumper.ContactSensorArrayOperations();
23 [Partner(
24 "MyRobotBrick",
25 Contract = brick.Contract.Identifier,
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
更多精彩
赞助商链接