I can C# your Lego Hexapod...

Sign in to queue

Description

What's more fun than Legos? Robotic Legos? Robotic Legos that you can C# code for!

I've not blogged much about the Microsoft Robotics Developer Studio here, but there's fewer fun things that it. With it you can control not only real robots, like the Lego Mindstorms NXT, but virtual robots as well. Yep, you can program robots today, without owning a single piece of hardware (except your computer of course). That said, today's post show a couple examples of "real world" (well) robot development, courtesy of the Lego Mindstorms NXT, the Microsoft Robotics Developer Studio and Gokulnath's weBLOG

Lego Hexapod Controlled using Microsoft Robotics Developer Studio (MRDS)

At last got some time to complete coding my hexapod to make it walk and sense obstacles. Click here to download the source code.

image

If you are beginner, and want to use MRDS to control your Lego Mindstorms NXT 2.0, refer to my previous posts:

1. Learn how to create DSS Service and use Manifest Editor
2. Lego Bot controlled using MRDS

My Lego Bot

In this article I’m going to explain about creating a fully computer controlled Lego Mindstorms NXT 2.0 Bot (with camera mounted on it) using Microsoft Robotics Developer Studio (MRDS). My previous article Microsoft Robotics Service for LEGO NXT 2.0 should be useful if you haven’t created any service using the Studio.

SNAGHTML130859

image

Let's take a look at a couple snips from the Hexapod source;

image

private IEnumerator<ITask> DoStart()
{
    var ultraSonicSubscribe = this._nxtUltrasonicSensorPort.Subscribe(_nxtUltrasonicSensorNotify);
    var touchSensor1Subscribe = this._nxtTouchSensor1Port.Subscribe(_nxtTouchSensor1Notify);
    var touchSensor2Subscribe = this._nxtTouchSensor2Port.Subscribe(_nxtTouchSensor2Notify);

    yield return (Choice)ultraSonicSubscribe;
    yield return (Choice)touchSensor1Subscribe;
    yield return (Choice)touchSensor1Subscribe;

    // Activate independent tasks
    Activate<ITask>(
        Arbiter.Receive<sonarsensor.SonarSensorUpdate>(true, _nxtUltrasonicSensorNotify, SonarSensorUpdateHandler),
        Arbiter.Receive<touchsensor.TouchSensorUpdate>(true, _nxtTouchSensor1Notify, TouchSensor1UpdateHandler),
        Arbiter.Receive<touchsensor.TouchSensorUpdate>(true, _nxtTouchSensor2Notify, TouchSensor2UpdateHandler)
    );

    // Start operation handlers and insert into directory service.
    StartHandlers();
}

 

private void SonarSensorUpdateHandler(sonarsensor.SonarSensorUpdate updateReadings)
{
     if (updateReadings.Body.Distance <= 25 && isRotata)
     {
         RotateMotor(Direction.Back);
     }
     else if (updateReadings.Body.Distance > 25 && isRotata)
     {
         RotateMotor(Direction.Front);
     }
}

private void TouchSensor1UpdateHandler(touchsensor.TouchSensorUpdate sensorReadings)
{
     if (sensorReadings.Body.TouchSensorOn)
     {
         RotateMotor(Direction.Front); 
     }
}

If you're interested in robotics and have hardware or not, the MRDS and these posts might be a cool place for you to start your journey...

 

Here’s a few more links you might find interesting:

The Discussion

Add Your 2 Cents