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
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 /
Code: Select all
vi /wireless
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
Code: Select all
chmod +x /wireless
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}"
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");
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.
I will expand this post out as people start asking questions about it, so feel free to post any questions you may have.