Geeks With Blogs

News
View Szymon Kobalczyk's profile on LinkedIn

Szymon Kobalczyk's Blog A Developer's Notebook

For my next project I decided to try to upgrade my SERB robot that I showed here last year to use Netduino. This robot was designed by great inventors from oomlout and you can buy it as a nicely packaged kit from them. However because the design is open source you can also download the project files and if you have access to a laser cutter order all the acrylic pieces there. It is also very easy to build following the instructable (you can find few more photos from my build here).

Netduino Controlled Servo Robot

The original SERB robot uses Arduino as its brain, so it was quick upgrade to Netduino thanks to the same form factor and pin layout. On the above photo you can see the Netduino is mounted on the back below the prototyping shield. Oomlout’s instructable suggests to use separate 9V battery for the board, but I found that it works just fine using only 4xAA batteries to power whole setup (Netduino, Servos and Xbee).

Robot drive system

The robot is driven by pair of continuous rotation servos. You can buy such servos from various hobby electronics and robotics shops, but most ordinary servos can be modified this way. Some require to remove potentiometer and replace it with resistor divider, while with others you can leave potentiometer in place but release it from rotating and hold it in centered position. You can do it even with tiny servos. Either way you get a very cheap high torque reversible DC gearmotor. And the best part is that you can control it just as any other servo using PWM, with no need for additional motor driver circuits. Thus I could use the Netduino Servo class that was already written by Chris Seto (I only adjusted the pulse range so it matches default values from Arduino Servo library).

But with all good said above, the one drawback with using a servo is that we don’t have a much control over it’s speed. For most values it will jump right to the max speed. I made few test measuring how far my robot would drive at various power levels (by setting servo from 0 to 90 degrees). As you can see on the graph below for values above 20 it will always drive at maximum speed. However for values from 0 to 16 the speed increase is almost linear thus in my code I’m scaling the speed values to this range. I’m also using a timer to ramp up the speed in smaller increments so the robot doesn’t accelerate or stop to fast. Please keep in mind that this works well with the particular model of servos I’m using (Futaba S3001) but you might need to adjust it for your robot.

image

I encapsulated the code used to drive the robot in the Serb class located in the NetduinoSerbDemo project. It controls both motors and provides helper classes for various commands. The class RandomTest implements a simple random movement pattern using these commands.

Joystick

Now that we know that the basic drive operations work we can build some applications on top of it. Before we make the robot go around in full autonomous mode (which requires adding few more sensors so robot can navigate in its small world) lets drive it manually with remote control. It would be nice to have some kind of joystick for it, wouldn’t it? Sure you could use the Sparkfun’s joystick shield (which you need to modify a little bit). But since I don’t have one at hand for this project I’m going to use a Nintentdo Wii Nunchuck (besides oomlout uses the same in another instructable).

You see, smart people found out that Nintendo accessories are communicating with Wiimotes using the I2C bus, so it’s quite easy to interface with them from the microcontroller once you know the protocol. There is also available a handy adapter called WiiChuck that plugs directly to Arduino. In the end it’s a cheap way to get a good quality device with analog stick, two buttons and an accelerometer. I bought mine for under $10 – it’s not original but works just fine.

The I2C pins on Netduino are in the same place as on Arduino (SDA on analog pin4, and  SCL on analog 5), but Arduino can be also set to provide required power on neighboring pins (analog pin 2 for ground, and analog pin 3 for +5V). It seems that this can’t be done on Netduino so I had to plug the adapter to the breadboard and wire it properly instead.

_MG_1206

The second project called NetduinoSerbRemote contains the WiiChuck class with my implementation of .NET MF driver for Wii Nunchuck. It is based on the oryginal code by Tod E. Kurt, but I extended it with information found on WiiBrew, Arduino and other forums. For example it implements motion calculations to calibrate the accelerometer output (found in the oomlout version). It also has new I2C device initialization procedure that should disable encryption (this might improve compatibility with some wireless Nunchucks).

After creating the WiiChuck instance, you simply call the GetData method, and it will return true if it succeeded, or false otherwise.  Then you can get the extracted values from properties representing position of analog stick, buttons, and accelerometer. For the robot I’m simply mapping the joystick position to directly to speed and direction. Another mode is activated when you press and hold the Z button. Then it will use values from accelerometer instead of the joystick.

Remote control

Looking at the previous photos some of you might already guessed that I’m going to use XBee radios for communication from my remote to the robot. In fact this is the easiest way to add wireless communication between two microcontrollers. It uses serial ports, thus you only need to connect the corresponding UART pins to the radios to get it working.

Note that there are several models of XBee modules on the market. Some provide many advanced capabilities including mesh networking. But if you are going to use them only to transmit data from one device to another you should get an older version now called XBee 802.15.4 (series 1) that can be easily configures for point-to-point networking. I got mine from Adafruit with corresponding adapters that make it easy to plug the module on breadboard or directly to the USB FTDI-TTL-232 cable. You can learn much more from Lady Ada’s website and from Tom Igoe’s book Making Things Talk.

In this project I decided to use UART1 on both Netduinos, so I put a wire from Netduino digital pin 0 to TX pin on XBee, and from pin 1 to RX (and of course connected it to +5V and ground as well). For communication I adapted the simple protocol used in yet another instructable from oomlout. Each message begins with header ‘AAA’, followed by single letter command code, and optional parameter. Thus messages are always 5 bytes long. Here are currently implemented command codes:

private static class Command
{
   public const char Unknown = '?';
   public const char Forward = 'F';
   public const char Backward = 'B';
   public const char Left = 'L';
   public const char Right = 'R';
   public const char SetPower = 'P';
   public const char Stop = 'S';
   public const char SetSpeedLeft = 'X';
   public const char SetSpeedRight = 'Y';
}

On the Netduino acting as the remote the values are read from Wii Nunchuck, mapped to SetSpeedLeft and SetSpeedRight commands, and send to serial port. On the other side the SerbRemoteClient class parses incoming data, and interprets these commands accordingly. I hope the code will be easy to follow for everyone.

The solution also contains a very simple WPF application that I used for testing. To use this app I connected one of the XBee modules to PC via with FTDI USB cable. The name and baud rate of the serial port can be set in the app.config file.

Here is the source code for this project:

Posted on Tuesday, August 31, 2010 7:24 PM Development , Robotics , Electronics , .NET Micro Framework | Back to top


Comments on this post: .NET Micro Framework – Netduino Controlled Servo Robot

# re: .NET Micro Framework – Netduino Controlled Servo Robot
Requesting Gravatar...
Very cool. Thanks for posting this.
Left by George M on Sep 01, 2010 5:16 PM

# re: .NET Micro Framework – Netduino Controlled Servo Robot
Requesting Gravatar...
Thanks, looks like a fascinating project. I've started to miss the whiff of the soldering iron. Sigh..
Left by Ricardo G on Sep 20, 2010 5:55 AM

# re: .NET Micro Framework – Netduino Controlled Servo Robot
Requesting Gravatar...
You have created one of the coolest looking robots i have ever seen, neat idea on the joystick control!
Left by Matt on Mar 14, 2011 4:34 AM

# re: .NET Micro Framework – Netduino Controlled Servo Robot
Requesting Gravatar...
Thanks for your source code for the Wiichuck. It worked perfectly. I ran my Wiichuck directly from Analog pins 2,3,4,5 without any issue. The Wii nunchuck is designed to run from 3V (2xAA bateries) not 5V as would be supplied by an Aduino output pin.
Left by Mike Paauwe on Jul 18, 2011 1:59 PM

# re: .NET Micro Framework – Netduino Controlled Servo Robot
Requesting Gravatar...
Thanks for this code - it's great. Just a couple of minor tweaks and I've got it working for .Net Gadgeteer
Left by Jim on Jan 30, 2013 2:41 PM

Your comment:
 (will show your gravatar)


Copyright © Szymon Kobalczyk | Powered by: GeeksWithBlogs.net