| Robotics I 91.548-201 Mid-Term Project | ||
| Mobile WebCam -- Jim McCarthy | ||
|
Abstract: The Mobile WebCam is a video camera whose output is displayed on a website (view the website) over the Internet. Additionally, through the same website that displays what the camera is looking at, controls are provided allowing the user to “look around” by adjusting the cameras position up/down and left/right. I worked on this project with my friend Tom Ogden. Without his help and insight this project would not been completed in anything resembling a timely fashion (and I wouldn’t have learned nearly as much)! Reason for project: My motivation for choosing this project is two-fold. First I'm attracted to the incorporation of a wide variety range of technologies, from low-level assembly language to programming in BASIC, writing my first bit of Java code, and creating a web page. Making all of these technologies interact to create a successful result is interesting to me. Secondly once a way is established to manipulate real objects (more than just virtual objects and files) over the internet many possibilities arise. Many real world possibilities exist in this space, this project may lend itself to some kind of monitoring or security application but with some different hardware you could remotely change the heat in your house, turn appliances on/off, etc., etc.
A High Level View of How the Mobile WebCam Works: The camera is mounted on a stand that allows it to move left/right and up/down. Each direction is controlled by a servo motor – that is one servo controls left/right (x-direction) movement and a second servo controls up/down (y-direction) movement. These servos take direction from a Basic Stamp Chip mounted on a small circuit board in the base of the camera (see pictures above). The Basic Stamp Chip is connected on one side to the servos and on another side to the host computer via serial line. So the host computer is in charge of sending signals over the serial line that indicate how user would like the camera aimed. The custom web server we built serves up the Mobile WebCam web site and the user can see what the camera sees by accessing this site. Our web site also allows the user to input coordinates to position the Mobile WebCam. This whole process can be thought of as a sort of two-way street: One side of the street is the user visiting the Mobile WebCam web site and inputting coordinates for the camera to be moved to. The coordinates are put into an HTML form and our web server has been customized to understand what to do with data the user inputs. The web server sees that data has been input and writes the data to the serial port. After the data leaves the host computers serial port its next stop is the Basic Stamp Chip that controls the servos that position the camera. The Basic Stamp Chip is running code that understands what to do with the data it receives and moves the servos accordingly. The control path for camera movement: 1) The user inputs coordinates to the forms on the web page 2) These coordinates are sent (in the form of a request) to the WebServer 3) The WebServer understands that it has been told to reposition the webcam. 4) The WebServer opens the serial line (connected to the Basic Stamp Chip), 5) Parses the request (to get the coordinates) and writes the coordinates to COM1 6) The Basic Stamp Chip gets the coordinates and moves the servos appropriately The other side of the street is the image starting at the camera and ending up getting posted to the Mobile WebCam web site. The image originates at the camera, is sent over a USB connection and WebCam32 saves a copy of that image every second. The Mobile WebCam web site runs a Java applet (called JavaCam.java) that knows where to find the file that WebCam32 is saving and posts it to the web site. The applet gets that file every second and posts what it finds to the website. The result is the choppy video we see on the Mobile WebCam web site, that is being updated every second. The control path for images: 1) Whatever the camera is aimed at is saved every second as a file (image.jpg) by WebCam32 2) An applet on the HTML page displays what it finds in image.jpg and updates the web page from that file every second. (applet source code) More detail on our solutions: The Basic Stamp Chip: The Basic Stamp Chip is in acts as a type of relay, transforming its serial line input (from the host computer) into servo motor movements (that move the camera). The Basic stamp chip needs to be programmed to do this and we accomplish this by writing code and downloading it through a modified serial line onto the the Basic Stamp Chip. The Basic Stamp Chip comes with an interpreter on it. What What this means is that instead of going through the labor of programming the basic stamp in assembly language, an intermediate, BASIC-type language can be used instead. This makes programming the Basic Stamp much easier. Below I'll explain some of the code that runs on the Basic Stamp Chip: First we center the camera (all servos) on start up: ' set servo to center for servo = 0 to 3 for x = 1 to 30 pulsout servo,150 pause 30 next x write servo, 150 next servo Then we wait for data to arrive on the serial line: serin 7,N2400,servo,pos,speed Notice that the serial line is set to 2400 baud! Once we get a new position for one of the servos we read the current position for that servo: read servo, lastpos If the position is out of range we adjust it to be either the minimum or maximum: directpos: if pos < 90 then set90 if pos > 210 then set210 goto calcspeed Provided the input position is within range we proceed to calcspeed which checks the input speed. If its out of range it gets adjusted to be either the min or max speed otherwise we proceed directly to dospeedpulse: calcspeed: if speed >= 0 then speedchk2 speed = 0 speedchk2: if speed <= 50 then dospeedpulse speed = 50 Here we're just trying to decide if we should move "backward" or "forward" to get to our new position: dospeedpulse: if lastpos >= pos then backwards forwards: 'debug "forwards" 'debug speed for x = lastpos to pos step 1 pulsout servo,x pause speed next x goto savepos backwards: 'debug "backwards" 'debug speed for x = lastpos to pos step -1 pulsout servo,x pause speed next x goto savepos Last we save our new position to memory: savepos: if servo > 3 then start write servo, pos goto start And that's all the Basic Stamp has to do to translate its serial line input into servo and camera movements! (Link to Basic Stamp Code). The WebServer: An ordinary, "off the shelf", webserver wouldn't know enough to recognize the coordinates sent by the website, or know that they were inteded to be sent out the serial port. Our solution to this problem was to find a webserver we could edit to do what we wanted. Luckily we were able to find an open source web server, written in Java on the Sun Microsystems website. We downloaded the source code to this web server, compiled, and ran it. Once we were satisfied that it worked properly we began adding code to it that would open a serial port and send data through it. The code to open the serial ports came from Professor Martins website. Assignment 3 from last semesters Computer Architecture class involved opening serial ports. So we borrowed code from that website called Serial.java and changed it to open serial ports for writing (instead of reading), and then adjusted the speed we want to open the serial port at to be 2400 baud. We added code to the web server that called on Serial.java to open a serial port at startup and code (below) that sends data through that port when necessary.The altered web server now takes two parameters: (1) the serial port your camera is connected to (COM1, or COM2, or ...) and (2)the port you want the web server to talk to the internet through. So starting the web server looks like this: WebServer COM2 8080 The code below was part of what we added to the webserver, it shows how we parse webpage requests. Basically if the request is for more than just a page (i.e. it has parameters) we assume that the parameters are coordinates for the WebCam. So we parse the request using the StringTokenizer function, removing the necessary coordinates. Then the coordinates get sent out the open serial port: /***** JPMcC edited below *****/ StringTokenizer st = new StringTokenizer(fname, "?"); fname = st.nextToken(); if(st.hasMoreTokens()){ String str; byte[] args; args = new byte[3]; StringTokenizer suby = new StringTokenizer(st.nextToken("&"), "="); System.out.println(suby.nextToken()); Integer y = new Integer(suby.nextToken()); StringTokenizer subx = new StringTokenizer(st.nextToken("&"), "="); System.out.println(subx.nextToken()); Integer x = new Integer(subx.nextToken()); StringTokenizer subs = new StringTokenizer(st.nextToken("&"), "="); System.out.println(subs.nextToken()); Integer s = new Integer(subs.nextToken()); args[0] = s.byteValue(); args[1] = y.byteValue(); args[2] = x.byteValue(); System.out.println("Writing to serial line..."); try { /***** send speed, position, and speed bytes out serial port -- JPMcC *****/ SerLine.put(args); } catch (Exception e) { e.printStackTrace(); } SerLine.flush(); /***** Make sure all chars get out before exiting -- JPMcC *****/ System.out.println("done."); Link to Final Web Server Design The WebCam32/JavaCam Software: The WebCam32 application that we used was purchased from a company called Surveyor. You can visit their website at http://www.surveyor.com/. The JavaCam applet (JavaCam.java) we use was also provided by Surveyor, but JavaCam.java is freely downloadable (from the Surveyor website). These two programs work together to provide the image you see on the Mobile WebCam website. The way they work is this: WebCam32 is started, is provided with a path and file name (to save images to), told how often to record what it sees (1 second in our case), and now WebCam32 records whatever the camera is looking at, once per second, indefinitely, to the path and file name you provided. The image is saved as a .jpg file. WebCam32 remembers its settings when it is shut down, so this set up procedure is only required once. There is no record of what the camera was seeing a few minutes ago, the only record is of what was seen 1 second ago. WebCam32 is very adjustable and you can configure how often it records an image to a file but 1 second is the smallest interval you can set it for. JavaCam is an applet that simply reads from a file every second and displays what it finds to a website. So while the Mobile WebCam is on, WebCam32 is saving an image of whatever the camera is aimed at every second (for example lets assume WebCam32 is saving the image to a file called image.jpg), meanwhile the JavaCam applet is reading from that same file (image.jpg) and posting what it finds to the website. Problems: On the camera movement: Ideally we would have liked to build a device like Kallol and Akshay built. They created a small system that is web addressable using a Texas Instruments MSP 430 Microprocessor connected to a CS8900 interface to the internet. If we had that as a base we could have had a Cricket connected to the MSP 430 and had the servos that control the camera act as cricket bus devices. Unfortunately, we conceded that we didn’t have the time to make a project this ambitious possible. We stuck with the design that used a basic stamp chip to control the servos, and may transition to making the servo motors cricket bus devices for the end of the semester. On the translating web page input into serial commands: At first control of the camera movement was done using a Visual Basic program, but we couldn’t find a plug-in for that to go into a web server. Then we had an implementation that used cgi and My Personal Web Server, but we ran into problems with My Personal Web Server running (or more correctly, not running) on Win2k (our host machine). This forced us to start looking for new ways to solve the problem of making input from the web page translate into action on the serial port of the cameras host computer. Luckily, we found a java based web server on the Sun Microsystems website that was downloadable and came with source code. Once we were able to compile and run the web server we began to edit it so that it would handle input from the web site, parse the information, open a serial port, and send the data out in the proper order. This turned out to be a solution we are very happy with. Problems/Potential Future Enhancements: First I would like to replace the Basic Stamp that controls the servos and the motion of the camera with a Cricket. Second I would like to change the user interface to the Mobile WebCam. Mostly I would like to improve the interface so that the user has a better idea what the current coordinates of the camera are. Without knowing what the current positioning of the camera is, choosing new coordinates is a process of trial and error. This could be accomplished by simply making sure the last set of coordinates submitted are posted to the website. That way the user can see his current position. One suggested solution is a type of graphic slider the user moves with a mouse whose movements cause camera movement. Another suggestion was having a grid drawn on the web page and depending where the user clicks his mouse on the grid the camera moves accordingly. These and other potential solutions will have to be sorted through to find the one that fits best. Additionally, one of the parts of the Mobile WebCam that Tom and I didn't write is the software that records what the camera is aimed at to a .jpg file every second. I'd also be interested in working on writing my own version of that software. If I can adjust the refresh rate of the frames the output to the user would look less choppy and more like streaming video. I'm reasonably sure that streaming video software can be purchased from http://www.surveyor.com/, but I don't know of any free streaming video software packages that would suit this need. |
||