HOW-TO: Make a Remote Controlled vehicle with an SBC

Post Reply
Robert

HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by Robert »

I've been receiving a lot of emails, calls, and forum messages regarding using SBCs for remote control vehicles. So much so, that I figured a small how-to and demonstration would be good.

For this example, I will use the Phidget SBC tank. The tank is described here: http://www.phidgets.com/phorum/viewtopi ... =13&t=3142

And a video demonstration of the tank in action is here: http://www.youtube.com/watch?v=tpBKQmQCaPM

GETTING STARTED
To get started, obviously we need an SBC, and we need something to communicate with it. I'm going to assume that you want to control this with a Laptop or a Desktop computer. We need them to communicate with each other wirelessly. The easiest way to do this is over WIFI, because the SBC comes packaged with a USB WIFI adapter.


NETWORKING
There are several ways that you can set up the wireless connection. The first, easiest, and most common way to do it is to have your SBC connect to your home network via a wireless access point. This is called "Infrastructure mode". This would usually be accomplished using your internet router with built in wifi access point, but it could also be a wireless ethernet bridge. When the SBC is associated with your access point, you can then communicate with it from your desktop connected to the network, or a laptop also connected to the access point. This is useful if the devices you want to control will always be in or near your home.

The second, more difficult way to set it up is called "ad-hoc mode". In this mode, there are no access points. You would have a wireless adapter on your laptop, talking directly to the wireless adapter on the SBC. This is useful if you wanted to have a remote control vehicle independent of your home network. You could take it and your laptop to a friend's house, or out into a remote location and play with it. The downside to this type of connection is currently, the SBC's web interface does not allow you to set up ad-hoc connections. You would have to do it through the linux command line.

HOW TO SET UP AD-HOC NETWORKING ON THE SBC
This example is between the SBC, and a Windows XP machine. Others machines will be slightly different.

PC Configuratoin:
First You will now need to set up a static IP address on your computer's wireless adapter. Open your control panel, go to network connections, right click on the wireless network connection, and select properties. Scroll down the connection items to TCP/IP at the bottom, then select properties.

Now, enter a static IP address in for the adapter. In this example I am using 192.168.100.1

Once that is done, click "OK" or "Close" on the bottom to save the settings and leave.

SBC Configuration:
Go to the wireless settings page on the SBC, and clear out any saved networks that may be on there (You may delete them, or simply disable them).

Next, we need to open a command shell into the SBC. Enable SSH login from the SBC's control panel if you haven't already done so. Next, you need an SSH client. I recommend PuTTY for windows. The server name is (the sbc's hostname).local. Example phidgetsbc.local. The username and password are root, and whatever you set the password to be.

Once you're at the command prompt, we need to enter in a few commands. This will set up the wireless adapter. Note that I'm using "test" as the SSID, and 1234567890 as the network key. You can use whatever you want here. The important part is the ip address is on the same subnet as the one we set up for the computer. Here I have chosen 92.168.100.2

Code: Select all

ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc
iwconfig wlan0 essid 'test'
iwconfig wlan0 key 1234567890
ifconfig wlan0 up
ifconfig wlan0 192.168.100.2
Once that is done, go back to your computer, and browse for wireless networks. You should see "test" as a network. Connect to it, and enter in the key (1234567890 in this case). You will connect to the SBC. You should be able to ping between the computers now.

What if I want these settings to remain when I reboot the SBC?

Let's make a small script to run all of these commands.
First, remount the root filesystem in read/write mode:

Code: Select all

mount -o remount rw /
Now, I'm going to use vi to edit the file:

Code: Select all

vi /wireless
(for those unfamiliar with vi, to insert text, we now type "i" to put vi into insert mode, and start typing.
Copy the following code into the file:

Code: Select all

#!/bin/sh
ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc
iwconfig wlan0 essid 'test'
iwconfig wlan0 key 1234567890
ifconfig wlan0 up
ifconfig wlan0 192.168.100.2
press excape to exit insert mode, and then type ":wq" to write, and quit. After that's done, we must make the script executable:

Code: Select all

chmod +x /wireless
Now, we must edit the startup script to run this rather than wpa_supplicant. This script is located at /etc/udev/rules.d/70-usb-wifi.rules

comment out the line:

Code: Select all

ACTION=="add", RUN+="/sbin/start-stop-daemon --start  -background --pidfile /var/run/network/bogus --startas /sbin/wifi -- start $env{INTERFACE}"
and replace it with the following:

Code: Select all

ACTION=="add", RUN+="/wireless"

Now, your ad-hoc network will come up every time you reboot your machine.

SOFTWARE
Once the networking is set up, the rest is a breeze. The software will depend on your application, but is pretty straight forward. The interface kit on the SBC as well as any phidget plugged into the SBC can be accessed, and programmed against just like they were connected to your local computer. If you've ever used the webservice to control phidgets remotely, this will be second nature to you. If you haven't, it's ok, it's almost exactly the same as using a local phidget.

Below is a snippet of code showing the initialization of the software I used in the video to control the tank. It's written in C#, but should be pretty easy to follow for anyone who understands other languages.

By passing the open command a server name, it tells the library to open a phidget on another computer. Notice how I connect to the interface kit on my own computer "Robert". I could just call open(serialnumber) instead, but I have my reasons.

Code: Select all

//Open the interface kit on my computer for the joystick
ifkit = new InterfaceKit();
ifkit.Attach += new AttachEventHandler(ifkit_Attach); //ifkit_Attach is function that is called on attach
ifkit.Detach += new DetachEventHandler(ifkit_Detach); //ifkit_Detach is function that is called on detach
ifkit.Error += new ErrorEventHandler(ifkit_Error); //called on error
ifkit.InputChange += new InputChangeEventHandler(ifkit_InputChange);
ifkit.OutputChange += new OutputChangeEventHandler(ifkit_OutputChange);
ifkit.SensorChange += new SensorChangeEventHandler(ifkit_SensorChange);
ifkit.open(97575, "Robert");

//The interface kit on the SBC. Notice how I just specify the SBC's name (phidgetsbc-tank), and the serial number to connect to it across the wireless network
tankifkit = new InterfaceKit();
tankifkit.Attach += new AttachEventHandler(tankifkit_Attach);
tankifkit.Detach += new DetachEventHandler(tankifkit_Detach);
tankifkit.open(1000023, "phidgetsbc-tank");

//The high current motor controller for the drive motors
tankDrive = new MotorControl();
tankDrive.Attach += new AttachEventHandler(tank_Attach);
tankDrive.Detach += new DetachEventHandler(tank_Detach);
tankDrive.Error += new ErrorEventHandler(tank_Error);
tankDrive.open(99999, "phidgetsbc-tank");

//The low voltage motor controller for the turret
turret = new MotorControl();
turret.Attach += new AttachEventHandler(turret_Attach);
turret.Detach += new DetachEventHandler(turret_Detach);
turret.Error += new ErrorEventHandler(turret_Error);
turret.InputChange += new InputChangeEventHandler(turret_InputChange);
turret.open(27972, "phidgetsbc-tank");
Once that's done, I can control the phidgets normally.

The syntax is slightly different depending on the language. For example, in C, you would use openremote(). Refer to the api reference documentation for the proper syntax for your language.

ISSUES: NETWORK DROPOUTS
If you lose network connection while the vehicle is driving, it will quite happily keep driving forever. My tank controlling software used to flash an LED plugged into one of the outputs once per second to show me that I had a connection. I used to have a small program running on the SBC that would check the output, and if it didn't see it change in a second, would shut down the motors. I lost the program, and haven't re-created it, but it's pretty simple to do.

ISSUES: NETWORK LATENCY
The SBC runs a USB 1.1 bus. That gives it 12mbit of bandwidth for ALL USB devices on the SBC. That includes all of the phidgets, the webcam, and wifi. If there's too much happening at once, things will start to get delayed. This usually isn't a problem, you can normally get away with a webcam, wifi, and a few phidgets provided that you aren't hammering it with commands.

The webcam does uses a lot of bandwidth. If things start to become un-resposive, lower the resolution of your camera first.

The wifi adapter also uses a lot of bandwidth. If you are having issues, you can swap out the usb wifi adapter with a wireless ethernet bridge connected to the network jack on the SBC. This frees up a lot of USB bandwidth. The tank is currently using a D-Link DWL-G730AP http://www.dlink.com/products/?pid=346 . You can find similar types of adapters second hand for really cheap. Wireless B adapters typically sell for $10-20 on ebay. Another benefit to using a wireless bridge, because they usually have their own web interface for configuring the wireless settings, it's really easy to set one up ad-hoc directly to a laptop.

QUESTIONS
Q: A webcam is cool, but I want to have two, or three cameras on my robot so that I can look all around!
A: You can plug in multiple webcams if you would like, but remember they use a lot of USB bandwidth. If you do want to run several webcams, I highly recommend eliminating the USB wifi adapter, and running a wireless ethernet bridge. I've had good success running two cameras at either reduced resolution, or reduced framerate, and I've run 4 webcams with reduced resolution and framerate. If you additional cameras aren't coming online, the others are using too much bandwidth.

Q: Where can I get one of those joysticks? That looks perfect for controlling my vehicle!
A: It's a Productwell RKJXK3401 joystick. http://www.productwell.com/Products/Spe ... XK3401.pdf
I wish you all the best luck in trying to get one. :D




I will expand this post out as people start asking questions about it, so feel free to post any questions you may have.
Last edited by Robert on Fri Apr 23, 2010 12:55 pm, edited 1 time in total.
Capricorn
Fresh meat
Posts: 2
Joined: Fri Apr 02, 2010 8:03 pm
Contact:

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by Capricorn »

Robert, That's really helpful to me, thanks for putting it all together and posting it. In my case I was considering how well this would work for a model boat (large, about 10' and 120 lbs so space and weight are not bit issues). This boat will have many accessories in addition to the motors and steering. An RC radio with the add on's for operating all the accessories is a substantial cost, and not as flexible as the type you describe. But I'm not quite sure this would be workable, outdoors and all.

It would definitely be in the ad-hoc mode which sounds more complicated. In any case I'll be looking forward to giving it a try. Cap
Robert

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by Robert »

Outdoors actually works better because there aren't any obstacles to degrade performance of the wireless signal. I would be a little worried if it cut out, and the boat was way out in the water somewhere though. Maybe it needs a long string to pull it back :)
Robert

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by Robert »

I've added a quick and dirty how-to on how you get ad-hoc networking working on the SBC.
andrenilsen

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by andrenilsen »

Cool! Thanks! That will help me with my robot project.
But one quick question, if I connect a laser to the output on the SBC, and I have another similar robot, which sensor do I use to player some kind of laser tag with them? Is a "precision light sensor" efficient enough?

EDIT: But it would have been fun to build some kind of airsoft robot, but automatic weapon systems are illegal to build where I come from.
Robert

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by Robert »

A laser pointed at a precision light sensor should give you a satisfactory result. Keep in mind that the sensing element on the light sensor is quite small, and so is the laser beam. They would have to be lined up pretty good to get a reading.
andrenilsen

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by andrenilsen »

I guess it would be better if I align some mirrors around the precision light sensor, so whenever the laser hits one of the mirrors it will be reflected onto the sensor. I am thinking of the kind of mirrors which are
in front of a flashlight, like here:
http://images.ifguk.co.uk/products/553/553-large1.jpg
Robert

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by Robert »

A parabolic reflector. Yes, that could work quite well.
danhoskin
Phidgetsian
Posts: 5
Joined: Wed Jan 16, 2008 6:05 pm

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by danhoskin »

I'm stuck at the point where we try to get the settings to stick:

press excape to exit insert mode, and then type ":wq" to write, and quit. After that's done, we must make the script executable:

It says that the file is read-only, what am I missing?
Robert

Re: HOW-TO: Make a Remote Controlled vehicle with an SBC

Post by Robert »

You're missing the part where you needed to put the filesystem into read/write mode.

And when I say that you're missing it, I mean that I forgot to mention it.

Code: Select all

mount -o remount rw /
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests