Friday, October 12, 2007 8:58 AMHi, I'm having problems subscribing to the encoder of a single motor in NXT.
Using drive = Microsoft.Robotics.Services.Sample.Lego.Nxt.Drive.Proxy, I was able to access the encoder reading of both motors through:
drive.DriveOperations driveNotificationPort = new drive.DriveOperations();
);According to my understanding, I can do this because drive.DriveOperations can post drive.DriverEncodersUpdate items.
With Microsoft.Robotics.Services.Sample.Lego.Nxt.Motor.Proxy, however, there's no MotorEncoderUpdate to receive and the MotorOperations does not post any encoder update items.
If I want to read from only one motor encoder, my current solution would be to wrap it anway in a drive. But I'd really like to know a cleaner way to do this.
Saturday, October 13, 2007 6:59 PM
The Motor service implements the encoder alternate contract. This means that when you start the motor service, you can partner with the encoder and receive notifications from the motor.
One way to discover this is to use VPL. Drop an NXT brick, a motor, and a simple dialog on the page, then subscribe to the UpdateTickCount from the motor and send it to the dialog. Next, choose Menu / Build / Compile as a service, and take a look at the code which is generated:Code Block
usingencoder = Microsoft.Robotics.Services.Encoder.Proxy;Code Block
// Partner: NxtMotor, Contract: http://schemas.microsoft.com/robotics/2006/05/encoder.html
[dssa.Partner("NxtMotor", Contract = encoder.Contract.Identifier, CreationPolicy = dssa.PartnerCreationPolicy.UsePartnerListEntry)]
encoder.EncoderOperations _nxtMotorPort = new encoder.EncoderOperations();
encoder.EncoderOperations _nxtMotorNotify = new encoder.EncoderOperations();
protected override void Start()
// If there was no initial state partner, then the service state will be null.
if (_state == null)
// The state MUST be created before the service starts processing messages.
_state = new DiagramState();
// Subscribe to partners
// Add notifications to the main interleave
ccr.Arbiter.ReceiveWithIterator<ENCODER.UpdateTickCount>(true, _nxtMotorNotify, NxtMotorUpdateTickCountHandler)
Also, don't forget to check out the dll's which are referenced: