Lego Mindstorm RCX

The RCXBrick
class provides an easy to use API to control Lego RCX brick by manipulating its motors
and reading its sensor's values. Also it provides some additional functionality like playing sounds,
getting information about robot's batteries, etc.
// create an instance of RCX brick
RCXBrick rcx = new RCXBrick( );
// connect to the device
if ( rcx.Connect( RCXBrick.IRTowerType.USB ) )
{
// set forward direction of motor A
rcx.SetMotorDirection( RCXBrick.Motor.A, true );
// set power of motor
rcx.SetMotorPower( RCXBrick.Motor.A, 1 );
// turm motor on
rcx.SetMotorOn( RCXBrick.Motor.A, true );
// ...
// turn off motors A, B and C
rcx.SetMotorOn( RCXBrick.Motor.ABC, false );
// get first sensor's value
short value;
if ( rcx.GetSensorValue( RCXBrick.Sensor.First,
out value ) )
{
// ...
}
// ...
}
Lego Mindstorm NXT

Similarly to RCX, the framework provides classes to control Lego NXT. Although the robotics kit represents
the new generation of Lego kits, the API is made simple as for RCX to make it easy to program. However the API
is a bit different, since this kit's features are a bit different as well. Using the
NXTBrick class
it is really easy to start controlling NXT robot over Bluetooth through configured virtual serial port:
// create an instance of NXT brick
NXTBrick nxt = new NXTBrick( );
// connect to the device
if ( nxt.Connect( "COM8" ) )
{
// run motor A
NXTBrick.MotorState motorState = new NXTBrick.MotorState( );
motorState.Power = 70;
motorState.TurnRatio = 50;
motorState.Mode = NXTBrick.MotorMode.On;
motorState.Regulation = NXTBrick.MotorRegulationMode.Idle;
motorState.RunState = NXTBrick.MotorRunState.Running;
motorState.TachoLimit = 1000;
nxt.SetMotorState( NXTBrick.Motor.A, motorState );
// get input value from the first sensor
NXTBrick.SensorValues sensorValues;
if ( nxt.GetSensorValue( NXTBrick.Sensor.First,
out sensorValues ) )
{
// ...
}
// ...
}