Interactive Skype-Controlled Mindstorms NXT Car

4 01 2012

After a long wait, I’m back baby! To start the year off with a bang, here’s a Mindstorms NXT car that can be controlled using Skype – by anyone, anywhere, any-when (between today, 1/1/2012 and 1/18/2012).

If you want to get going right away, here is the link for driving this car: http://www.goo.gl/7LLaU.

This is going to be a pretty lengthy post, so I’ve broken it up into the following categories: Introduction/ General ExplanationHardware, Program-mingComputer Tweaks, and How YOU Can Drive This Car. Click any of the categories to jump forward to it.


Introduction/ General Explanation

I’ve been creating websites for a while now, and I was trying to think of a way to combine it with Mindstorms NXT, and this project is the result of that. The webpage is fairly simple – it’s got three arrows (one forward, two to the sides) and a start and a stop button. Clicking the start arrow will begin a Skype conversation with my computer, after which the user should share their screen; the NXT standing in front of my computer (called “Jeeves”) can then “see” the webpage the user is viewing.

That’s where the cool part kicks in – when the user clicks any one of the arrows or the stop button, the page will change to a different shade of gray. This shade of gray is then picked up by Jeeves, who turns it into a Bluetooth message for the other NXT (called “Alfred”). The car then drives in the direction the user tells it to, while remaining within a fenced off area where the webcam can see it.

So, the user can drive a LEGO Mindstorms NXT car, from the comfort of his or her home, without having to install any kind of software (provided that they have Skype).

Hardware – the Car

The car was fairly simple to build – it’s got two motors on the sides with the wheels attached directly (no gears), and a big ball caster attached at the back. It looks quite a bit like my line follower, actually, except for the fact that the caster is a lot bigger because the car needs to be able to drive over the power cable and because it’s on a carpet. Also, it’s got front bumpers so you all can’t break anything while driving it, a color sensor that turns on when the robot is in use, or has been in use the past minute, and a rechargeable battery that’s always plugged in. Some pictures:

The first one is a side view, and the second one is an upside down view.

Hardware – the Receiver

The receiver was a bit more tricky to build because it needed to be a specific height so its light sensor could “see” the right area of the user’s screen. The structure itself is fairly simple – the light sensor is on a big pole attached to the NXT, and it’s got a rechargeable battery that’s always plugged in at the bottom. Here’s a picture of it (without the battery; hence the delay):

Programming

For all of the coding in this project, I’ll provide a basic description of how it works, and then a download link in case you’re interested in trying to build this project yourself sometime. The first two pieces of code (for the car and the receiver) were made using RobotC, and the third (for the website) is in HTML. All of the code will be on Sourceforge.

Programming – the Car

There’s a small function for turning the motors’ PID control on or off  at the beginning of the program to get rid of the peeping noise the motors make when the car is not moving.

In the main task, here’s what happens: the variables are created, the Bluetooth is turned on, and the timer is cleared. In the main while-loop, the last received message is stored, so the robot can later use that information( along with the timer) determine whether it’s been active the last minute and decide to turn the signal light on or off. Then, the robot reads the message last sent to it and plugs it into a switch. Depending on which message it received from the receiver (ah, the irony), it will move the motors. At the end of the while loop, there is a 50 millisecond wait to save battery power.

Click here for the code (first version).

UPDATE: Since the robot is now wireless, the code has changed to support some more sensors for plugging itself in. Read more about these changes here:

http://wp.me/p10flW-l9.

Click here for the code (second version w/ wireless charging capabilities).

Programming – the Receiver

The receiver also starts by initializing its variables and turning on Bluetooth, after which it connects itself with the other NXT – also using Bluetooth. The program then enters its main while loop, in which there is a series of if/ else switches designed to determine what shade of gray the screen is. The if/ else switches then plug this message into the “messageToSend” variable, which is sent out afterwards. The loop ends with a 100 millisecond wait, again to preserve battery.

Click here for the code.

Programming – the Website

There isn’t really much to explain about this one, so I’ll just give you the download link. Please note that the images on the page aren’t included, so you won’t be able to view it correctly in your browser. Screenshot below.

Click here for the code.

Computer Tweaks

There were quite a few tweaks I had to make to my computer, so I decided to list them here in case, again, you want to build this project yourself someday. Keep in mind that I might be missing/ forgetting some things, so if you ever have a problem just leave a comment below.

  • Turned off sleeping mode on both my screen and the computer itself;
  • Skype:  in the general > video settings menu, I changed the first option (“Automatically receive video and screen sharing from…”) to “anyone”;
  • Skype: in the privacy > privacy settings menu, I changed everything to anyone. I also checked all the boxes;
  • Skype: in the calls > call settings menu, I changed “Allow calls from…” to “anyone”, and again checked all the boxes;
  • Skype: in the IM & SMS > IM settings menu, I changed “Allow IMs from…” to “anyone”;

I’m also keeping the Skype window open 24/7, so my background won’t confuse the light sensor.

How YOU Can Drive This Car

Here’s how:

  • Go to http://www.goo.gl/7LLaU
  • Make sure your window is maximized
  • Click the “Start” button
  • Go through the dialog windows you get (there will be more on IE and Firefox than on Google Chrome)
  • Wait for my video to start (this can take up to 20 seconds)
  • Open the “call menu” at the top bar
  • Click “Share Your Screen” – it’s about 3/4th of the way down the menu
  • Click “Share Full Screen”
  • You should now be brought back to the webpage with the arrows. Once you see the car stop, use the arrows to drive it around.
  • To stop, hover your mouse over the little screen where you see the car, and click the red phone button

This project has successfully been tested on the following operating systems:

  • Windows 7

With the following browsers (newest version as of 12/31/2011):

  • Google Chrome (tested best)
  • Firefox
  • Internet Explorer
If you try this project on anything not mentioned above, it’d rock if you could leave a comment stating what you used below so I can add supported  (and not supported) browsers and OS’s. Thanks!

Conclusion

So there you have it: a LEGO Mindstorms NXT car that you can drive using Skype. If you like this project and want to see more, subscribe to my YouTube page and this blog for the latest updates. Once this project ends, I’ll put some statistics on how many people tried this project up down here. Feel free to use anything on this page (the robots, the code, the website, etc.) non-commercially, as long as you give credit where it’s due.

To read more about my Skype car, click here.

Disclaimer: The Skype name, associated trade marks and logos, the Skype “Call Me” button and the “S” logo are trade marks of Skype.





Dexter industries WiFi Sensor Demo by Mightor: Spin Pretzel

9 05 2011

EDIT: the live stream will be taken down on May 15th 2011.

Since the Dexter Industries WiFi sensor is coming out (soon?), Mightor is writing a RobotC driver/ library for it. And the proof of concept video is AWESOME. It features Pretzel, one of his NXTs, which(/who) you can see at this live stream. The cool part is that you can command its(/her) motor, just by going to a webpage and putting a speed into the URL! From his blog:

I am currently streaming a live feed of my NXT on UStream.  You can easily control the motor on my NXT using URLs like:

The
power to the motor can range from –100 to 100, with 0 being “brake”. Be nice to the poor little NXT and observe these simple guidelines:

  • Don’t try to feed it garbage, nobody will think you’re a l33t h4xor if you crash the NXT and if I track you down, I will send my NXT powered, hellfire missile armed quadrocopter to your house. It’s fully autonomic but it has some bugs, so waving a white flag may be perceived as a threat instead and it will act accordingly.
  • It may crash and it may not respond as quickly as you’d like but give it time and don’t hammer it.
  • If the light on the left is not ON then it’s not running.
  • Don’t bother leaving messages in the comments or mail telling me it has crashed. I’ll check periodically to see if it is still responding and restart it if necessary.

It’s a very small webserver programmed in ROBOTC running on the NXT. It uses the new Dexter Industries WiFi sensor for the NXT. You can download the code right here: [LINK]. You’ll need to download my driver suite too as it uses the common.h file from there.  The code is rough and mostly undocumented. Usual caveats apply. This program and driver will be part of the driver suite.

Try it!

The following image cannot be displayed: Pretzel, as seen in the live stream





Coming (soon?) from Dexter Industries: WiFi for the NXT

25 03 2011

Earlier today, Dexter Industries, the folks responsible for the dFlex, NXTBee, dSolar and much more, released a preview to some of their upcoming products. One of those was a WiFi sensor for the NXT (!!), to “let the NXT communicate with the internet”. This’d open up a million of possibilities for NXT to PC communication, NXT to NXT communication, data storage, data sharing (live?), etc, etc, etc.

WiFi blocks for the NXT have been made before though, but they’ve never been for sale (as far as I know).  Sjef Fransen, for example, has done something similar for “Lego Beyond Toys“, see picture below.

It’s unknown when it’ll come out.





NXTBee’s invasion

9 02 2011

New from Dexter Industries: the NXTBee has arrived! From their website:

The Dexter Industries NXTBee’s are now up for sale. We have some example code to get you started in RobotC, and we’re working on NXT-G blocks for the sensors.

Goodbye slow, short, and unreliable communications over bluetooth. Hello easy, fast, far-reaching, and awesome communications between the Mindstorm NXT’s and other devices with XBees.

It’ll be for sale in three editions: regular, naked and pro. The regular one gives you:

  • Fast, long-distance wireless communications.
  • Communicate Far: Send data over 300 feet.
  • Communicate Fast: High speed communication between NXT’s.
  • Communicate Wide: Talk to multiple NXTs and other devices and robots.
  • Communicate Easily: Minimal configuration with advanced options for secure and mesh networking.

NXTBee Regular

In addition, the NXTBee naked has:

  • Fast, long distance wireless communication the NXT.
  • Just the adapter. No radio included.
  • Configurable for XBee and XBee PRO.
  • Slide an XBee or XBee PRO radio into the sockets and go!

NXTBee Naked

And, finally, the NXTBee PRO adds:

  • Fast, long distance and easy-to-use XBee PRO adapter and radio for the NXT.
  • Communicate Far: Send data over 1.2 KM.
  • Communicate Fast: High speed communication between NXT’s.
  • Communicate Wide: Talk to multiple NXTs and other devices and robots.
  • Communicate Easily: Minimal configuration with advanced options for secure and mesh networking.

NXTBee Pro

The three models (regular, naked and pro) will be available as singles, costing $55.01, $33,02 and $78.00, respectively, as well as being sold in pairs, for about double those prices. More info:





Light Sensor as Switchable Light

9 01 2011

One very cool feature of the NXT 2.0 is that the color sensor can be used as light (beacon). But, as it turns out, that effect can be achieved wit the NXT 1.0 light sensor as well (in RobotC, at least). Why? the color sensor can be set to a different mode (active or inactive) within the program, and not just when configuring the sensor ports. When the sensor is used in its inactive mode, it reads the regular light value, while the active mode reads the reflected light. To read the reflected light, the NXT turns the red LED (the lower glass thing) on, and to read the regular light, it turns it off.

In order to use this function, one needs to configure the light sensor using #pragma config(Sensor…, setting it as either “sensorLightActive” (light turned on) or “SensorLightInactive” (light turned off), whichever one is needed first. Then, anywhere within the code insert “SensorType[lightSensor] = sensorLightActive;” or ”SensorType[lightSensor] = sensorLightInactive;”, where the part between the square brackets is equal to the name specified within the pragma part. Here’s an example

#pragma config(Sensor, S1,     lightSensor,         sensorLightActive)//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
task main(){
  int i;
  nxtDisplayCenteredTextLine(2, "Light turned");
  for(i=0; i<49; i++){
    SensorType[lightSensor] = sensorLightActive;
    nxtDisplayCenteredBigTextLine(4, "ON");
    wait10Msec(i);
    SensorType[lightSensor] = sensorLightInactive;
    nxtDisplayCenteredBigTextLine(4, "OFF");
    wait10Msec(i);
  }
}

It’s really useful, as it can be used for super quick communication between two NXTs, as the light can be turned off in a few milliseconds.





NXT communication using HiTechnic Magnetic Field Sensor

26 12 2010

A few days ago, the HiTechnic Magnetic field sensor arrived at my doorstep. Ever since, I was thinking about what to use it for, and this is the result: an automatic binary encoder, sender, receiver and decoder used to synchronize two NXT motors. The video below shows the procedure:

HiTechnic Magnetic SensorSo, the robot starts by setting the bias for the magnetic sensor before it’s near the magnet. Once the user adjusts the red stick to an acceptable angle (between 0 and 255 degrees – program is paused if angle is wrong) for the motors to sync to, that angle is translated into an eight-bit binary code. Then, the third motor compares its own position to the way it’s supposed to be – if a bit (boolean variable) is true, the black stud has to be up (0 degrees), and when the bit is false, the red stud has to be up (180 degrees). If necessary, the motor adjusts the position. At the same time, the magnetic field sensor “reads” the magnet, getting either a positive or negative number. If the received number is positive, it makes a bit true; if it’s negative, it makes that same bit false. Once it has all eight bits, it translates it back into a target for the other motor to go to, thus synchronizing the motors. At the very end, the third motor checks its position and makes sure it ends up having the black pin (north of the magnet) up.

More information:

Thanks to:

  • Mightor for creating both a driver and example program for the magnetic field sensor
  • HiTechnic for creating the magnetic field sensor







Follow

Get every new post delivered to your Inbox.

Join 34 other followers