Raúl
Moderador
 Moderador
| Mensajes: 432 |  | Karma: 6
|
Re:simulated sonar, states and operations - 2008/08/28 15:08
Well, what you probably want is to subscribe to the sonar service and get notifications when its states changes, i.e. get the new sonar readings when they robot has moved (or something moved in front of the sonar).
In order to do that, you should use the generic contract for sonar and declare a parter of your service, something like this:
| Code: | // Raul - Sonar generic contract
using pxsonar = Microsoft.Robotics.Services.Sonar.Proxy;
...
[Partner("Sonar", Contract = pxsonar.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExisting)]
pxsonar.SonarOperations _sonarPort =
new pxsonar.SonarOperations();
pxsonar.SonarOperations _sonarNotify =
new pxsonar.SonarOperations();
...
// Within your start() method, maybe within an Interleave:
Arbiter.ReceiveWithIterator<pxsonar.Replace>(true, _sonarNotify, OnSonarReplaceHandler),
|
Have a look to the service tutorials if you have doubts about how the subscription works. Then, you could find useful to have a look to my code in ExplorerSimSonar that uses the Simulated Sonar.
Remember that you _mainport is for your own service opeations. For sonar notifications you declare another port as shown above.
Post edited by: Raúl, at: 2008/08/28 15:09
Raúl Arrabales Moreno. conscious-robots.com/raul |