How a Computer Controls An RC Car:

How a computer controls an RC car


Outline (Web technology):

Outline (Phidget technology):


Client / Server technolgy

The basic nuts and bolts of how this setup works is based on what's deemed in the industry as "client-server" technology. In laymans terms, client-server technology is similar to the boss-employee relationship. You have one piece that is in charge, like the boss. In our case, this is the "server". You also have one side taking commands, like the employee. In our case, this is the "client". The client requests a connection to the server and, if the server accepts that connection, then the two can communicate. However, this is where the boss + employee analogy breaks down because once a client + server are connected either one can send commands for the other to do work.

The client could tell the server to do something and, consequently the server can tell the client to do something. This communication process you may have already heard about on page #1 [or whatever, put the link in here]. This is the "protocol" that the client & server speak.

Here is the art of this whole equation. I will show you how we can take what we've learned about webcams and rc cars and combine it with client / server technology and we'll be driving our very own RC car in France when we're done here. [link to live example of this being done]

Webservers and PHP

You should already be familiar with a webserver. It serves webpages just like the one you are viewing right now. Did you know there's a reason why it's called a web "server?" Because there are clients out there, such as your very own web browser, that make requests of this webserver to send webpages out as the servers response.

There are a couple steps in doing what we need to do. We need:

  1. A "client" the webbrowser & a "server" - the webserver, to take commands for the RC car
  2. A Daemon process listening for requests (from the webserver) to send to the RC car
  3. A way for the Daemon process and the RC car to communicate

Once we have these 3 pieces we can control an RC car via a webbrowser. See! It's as easy as 1-2-3! Come with me, and we'll see what's next: [link here to next page, or whatever]

Client webpage

[see this link on how to embed a webcam into a webpage]. The client webpage is what you are viewing when you click [here - live example website]. The code that displays this is [here - code snippet popup]. The client webpage has two functions: 1) display the video stream from the webcam and 2) have control buttons that communicate to the RC car.

Detailed description of how to embed a webcam into a webpage can be found [here]. Briefly, we have a Java application as part of the web page your browser is viewing.

How the controls on the web page work is simply done via AJAX. This is the same technology that powers [link to Google] Google Maps. It's a client/server techonlogy that lets a webpage seemlessly communicate to a webserver without refreshing the web page. AJAX allows us to do all sorts of neat things, many of which are out of the scope of this document.

Our controls send commands to the webserver using AJAX. There are 6 commands our page can send. "Go Forward only" is one of the commands and it tells the car to "Just go forward, don't turn." When you click the button in the webpage, and AJAX request is formed. This request is sent to the webserver. The webserver processes it and either sends a blank response, indicating everything is Ok, or it sends a detailed message of a problem which is displayed to the user.

Let's check that out next:

Server webServer code

Using a language called PHP (Hypertext Preprocessor) the webserver recieves commands from the webpage running on the clients webbrowser. In this case, you are the client, and I am the server.

When you click a button on the webpage that button uses javascript to send a command to the weberserver. The command that is sent depends on the button you click.

I, as the webserver, recieve your request to send a command to the remote control cam-car. If I see that it's a valid request I will act as a "Proxy" for your request and send it along to the daemon program that controls the cam-car.

The "proxy" effect

A "proxy" is something that acts on behalf of something else. Just like an Attorney can close a deal on a house for you without you being present, a webserver can send a command on to somewhere else, without your client webbrowser being directly involved. Hence, the "proxy" effect.

Daemon waiting for messages

One part that we need working for this is a daemon process sitting and waiting for requests from the network. Much like the radio reciever in the RC car does nothing until it hears something, so does the daemon process follow a similar fate.

The network daemon bind to a specific network port, for example port #6446. Just FYI, your web browser and a web server communicate on a well known port, port #80. After the network daemon [come up with a better term for this] binds to this port, it then listens for incoming connections. When a new connection is detected, the daemon accepts the connection and waits to recieve data.

In our case, the daemon is waiting for a connection to be proxied through the webserver - the webserver making the actual connection. In this instance we have flipped the tables on the webserver and we have made the webserver act as a "client" and the network daemon is acting as the "server."

So, the daemon recieves data and processes it. In our specific case, the data recieved is commands that need to be passed along to the RC car. For this, the daemon serves multiple purposes:

  1. recieving data from the webserver (and processing it) and
  2. controlling the relays on the phidget board.

When the daemon recieves a specific command from the webserver the daemon knows that it needs to open or close one of the relays on the phidget board. This functionality - to communicate with the phidget board - is built in to the network daemon itself.

Phidget control interface

A Phidget board is a specialized piece of hardware that is built specifically to communicate with a USB port on a computer, and to listen to commands from that computer on how to operate the relays found on the phidget board. The phidget board I've selected is a 0/0/4 Phidget Interface Kit, available here. This board controls four relays. Each relay is either open, or closed, depending on whether it's been told (by the controlling computer) to be open or closed.

Think of how a lightbulb works - a lightbulb uses the very same principle that one of the relays on the phidget board uses. That is to say that a light is on when the circuit is complete and all wires are connected. Or, it is off when the circuit is open and there is not a complete connection made.

To summarize, the phidget board is taking commands from the computer. That computer is telling the phidget board to open or close one of the relays on the board. All we need now is a computer program that knows how to talk to the phidget board, and knows when to open or close one of the relays on the phidget board. This is one of the function of the daemon process described above!

Now here comes the fun stuff!

Sodering the two together

One of the last steps we need to do is to connect the phidget board to the radio control transmitter. If you remember, the RC transmitter is what actually tells the RC Car how to move; forward, backward, left, or right. So, how do we do this?

First, we take the RC transmitter apart. The details of how the RC controller work are detailed in the section "How an RC Car works."
To learn how the RC transmitter works, go there. We are concerned here about how to wire this bitch to the Phidget board. So, that's where we need to get a "pinout" [some sort of link?] diagram to figure out what wires need to go where. Fortunately, I've already figure all this out for you. Just check this [hyperlink to a popup window with a .pdf of the wiring diagram] link out.

We need to soder wires onto the RC Transmitter board at this point. Fortunately, the other end slides easily into the phidget board which has a screw terminal that clamps the other end - no sodering needed. Nice! 8 wires to go an we're almost there!

The details of learning to soder are beyond this article. Just show them where to soder, with pictures in the page.

Putting it all together

Ok, let's review. We've got an RC car. We've got a phidget board, a network daemon, and a webserver. Add to that one client webbrowser, and we're ready to rock. Come on!

How this entire contraption works is beyond me. Just kidding! It's almost as simple as 1-2-3, but not quite. Say, 1-2-3-4 and you've got it.

Let's go over the system from one end, then the other. Let's begin with you, the person wanting to control the car sitting here [link to live webcam.].

Step 1 - pull up the webpage [hyperlink]. This makes a request to the webserver, pulling up the embedded webcam alongside AJAX controls that control the car. You, excitedly, click a link labeled "Go Forward!" [link to it bitch]

Step 2 - An AJAX command goes to the webserver with a label of "go forward bitch" in it. The webserver sees this as a valid request and "proxies" this request, sending it to the next step in the system - along to the network daemon.

Step 3 - the network daemon, deep in a slumber, gets slapped upside the ethernet cable. Not surprisingly, it wakes up! It has work todo. What is it? "Go forward," I hear. I know, I'll flip this relay here and that relay there, that's all I know to do. ZZzzzzz....

Step 4 - the phidget board relay snap closed. the electricity buzzes, vibrating the crystal on the RC transmitter board. The RC reciever, sitting on the car, picks up the signal, closes its circuits to the motors, and VVVrrrm! The car is off!

Simple, huh? Sooo....

What's next?

Click here to read how to setup a webcam!