1 / 15

CS Department Lab-Cams Embedded Systems in Practice

CS Department Lab-Cams Embedded Systems in Practice. Implemented by: The Embedded Systems Group. Components of the system. Dedicated labcam web-server - “erson” Intel Embedded Development board connected to the Net - “isky”

vinnie
Télécharger la présentation

CS Department Lab-Cams Embedded Systems in Practice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS Department Lab-CamsEmbedded Systems in Practice Implemented by: The Embedded Systems Group

  2. Components of the system • Dedicated labcam web-server - “erson” • Intel Embedded Development board connected to the Net - “isky” • Intel 8051 micro-processor which is used to control the stepper motors on the cameras • 2 Digital Cameras purchased from Digikey • ChillCam S/W that takes pictures

  3. Steps in the viewing process • User clicks on labcam link and is transferred to erson. • User has the option to either view activity in B256 or B265 and the appropriate page is displayed after clicking on the link. • The picture of the lab taken with the aid of ChillCam software is now displayed

  4. Steps in moving Camera • Clicking on the left/right button runs a cgi-script (a client networking program) on the web server. • The client program contacts a server program running on isky and indicates the user’s desired movement of the camera • The server communicates this information to the 8051 which then moves the camera.

  5. Web Server/Web Page Design Details • Since we wanted to be able to control the stepper motor through the Net, we had to create a CGI program to accomplish this task. • CGI programs introduce security concerns, and hence we were unable to obtain permission to run our CGI on the main web-server. This necessitated setting up our own dedicated web server to handle anything related to the digital cameras. • It was necessary to decide which language we wanted to use to implement the client application. Since we were familiar with Berkeley sockets programming using C, this became the language of choice. • The following encoding scheme was used to indicate the desired camera and motion: • ‘a’ ==> Move camera in B256 right • ‘b’ ==> Move camera in B256 left • ‘c’ ==> Move camera in B265 right • ‘d’ ==> Move camera in B265 left

  6. The HTML Code for the B256 Labcam page <FONT COLOR="#0000FF"> <H1 ALIGN=CENTER>The Fabulous B256 Cam!</H1> </FONT> <CENTER> <IMG SRC="/cgi-bin/send_image.pl?image=img2.jpg" ALIGN=CENTER BORDER=5> </CENTER> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%" NOSAVE ALIGN=CENTER> <TR NOSAVE> <TD NOSAVE ALIGN=CENTER> <FORM method="post" action="../cgi-bin/client.cgi?b"> <input type="Submit" value="<<"> </form> </TD> <TD NOSAVE ALIGN=CENTER> <B>Camera Controls</B> </TD> <TD NOSAVE ALIGN=CENTER> <FORM method="post" action="../cgi-bin/client.cgi?a"> <input type="submit" value=">>"> </form> </TD> </TABLE>

  7. Client networking application Design Details • Erson is an Apache web-server running under Linux. Hence the client application had to be written for the Unix environment • We had a variety of communications methods to pick from: serial, firewire, ethernet, token-ring, etc. Ethernet became the chosen medium due to its prevalence and the fact that we were able to install an ethernet card on the development board. A variety of protocols could have been used, but we selected TCP/IP as the means of communications since it is supported in linux and we were familiar with writing networking applications using TCP/IP. • Thus the client program utilizes Berkeley socket programming to transmit the CGI argument passed to it to isky. The program uses TCP as opposed to UDP to insure that the data is transmitted. Due to the robustness of TCP, the command (a single character encoding the camera and desired direction of motion) is simply sent to the server. The application does not due any of its own error checking and hence a packet format is not necessary.

  8. Portions of Code for Client Net App. (client.cc) if(strcmp(argv[1], "d") == 0) { //First, open up a dialogue with isky fd = connectTCP(host, port); // NOTE how we must output a web page… this is required // of any CGI script. if(fd == -1) { //We can't talk with isky! cout<<"Content-Type: text/html"<<endl<<endl; cout<<"<HTML>"<<endl; cout<<"<HEAD><TITLE>Error!</TITLE></HEAD>"<<endl; cout<<"<BODY>"<<endl; cout<<"<H1>Error!</H1>"<<endl; cout<<"<P>Server is busy."<<endl; cout<<"Please try again a little later."<<endl; cout<<"</BODY>"<<endl; cout<<"</HTML>"<<endl; return 0; } //We have a connection write(fd, "d", 1); //We're done talking to isky close(fd); }

  9. Client.cc continued // Now that we've successfully moved the camera, we will output the // correct page. if (strcmp(argv[1], "a") == 0 || strcmp(argv[1], "b") == 0) { // MUCH CODE REMOVED cout<<"Content-Type: text/html"<<endl<<endl; cout<<"<HTML>"<<endl; cout<<"<HEAD><TITLE>The Fabulous B256 Cam!</TITLE>"<<endl; cout<<"<IMG SRC=\"../cgi-bin/send_image.pl?image=img2.jpg\" ALIGN=CENTER BORDER=5>"<<endl; cout<<"</CENTER>"<<endl; cout<<"<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=\"100%\" NOSAVE ALIGN=CENTER>"<<endl; cout<<"<TR NOSAVE>"<<endl; cout<<"<TD NOSAVE ALIGN=CENTER>"<<endl; cout<<"<FORM method=\"post\" action=\"../cgi-bin/client.cgi?b\">"<<endl; cout<<"<input type=\"Submit\" value=\"<<\">"<<endl; cout<<"</form>"<<endl; } return 0; }

  10. Server Net Application Design Details • The drivers for the digital cameras were written for Windows 95, and since we weren’t interested in writing our own device drivers (not worth the effort given our actual goal), we decided to use Windows 95. We also used an Embedded Development Board donated by Intel to assess its usefulness in actual embedded applications. It allowed us to hook up an ethernet card for communications as well as the parallel port required for communication with the digital camera itself. • Since we had to use Windows 95 on the Intel Embedded Development Board, it was necessary to implement the server application in the windows environment. • We decided to implement the server using windows sockets in C since we were familiar with programming in this paradigm. It would have been possible to implement the server in a variety of other languages: Java, Perl, even C++ in windows using MFC. • The server constantly “listened” for communication from the client application. Once the command has been received from the client, it is communicated to the 8051 microprocessor using serial transmission. • Serial transmission under windows is performed by opening a file for the specific COM Port, and associating that file handle with a COM Port state. Serial transmission can then be facilitated by simply writing to the handle representing the COM Port, like any normal file.

  11. Server Application code (server.cpp) bool PerformCommand(char cmd, Port& p) { // make the new move if (cmd == 'a') if (currPos1 < POS_LIMIT) currPos1++; if (p.Write(move_command, 1) == false ) return false; return true; } int main() { // MUCH CODE deleted for clarity while( 1 ) { // accept incomingSocket = accept(s, 0, 0); if( incomingSocket != INVALID_SOCKET ) { if( recv(incomingSocket, buf, 1, 0) != 0 ) { MessageBeep(-1); if( PerformCommand(buf[0], p) == false ) { cout << "unable to execute user's command." << endl; } closesocket(incomingSocket); } } } }

  12. Server Application code (port.cpp) Port::Port(unsigned port, unsigned baud) : DefaultTimeout(1000) { char buf[32]; DCB commState; sprintf(buf, "COM%i", port); if( (handle = CreateFile(buf, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0)) == INVALID_HANDLE_VALUE ) { handle = 0; } else { GetCommState(handle, &commState); commState.BaudRate = baud; commState.Parity = NOPARITY; } } unsigned Port::Write(const void* buf, unsigned szBuf) { DWORD check = 0; if( handle ) { WriteFile(handle, buf, szBuf, &check, 0); } return check; }

  13. Stepper Motor Circuit Details • We decided to use a stepper motor to allow the movement of the camera since we wanted the movement to occur in “steps” instead of continuously (as in DC motors). • We decided to use an 8051 microprocessor to control the stepper motor due to the cheap cost of the processor and ease of use (possible to program it in C using the Keil compiler). It is always possible to design a custom circuit to accomplish any given task, but this makes the task quite difficult and time consuming (even expensive in this case). • Furthermore, it would have been possible to control the stepper motor directly, however we used an ASIC to control the clockwise and counter-clockwise motion of the stepper motor (the MC3479P chip). This is because it is much easier to control the IC than the motor itself, and furthermore a hardware solution is generally much faster than a software implementation. You are already familiar with the details of controlling a stepper motor using this chip from your stepper motor lab. • Similarly, you are familiar with the exact methods used to perform serial communication using the 8051 from your lab exercise on this subject (utilizing the LT1130CN chip to perform a conversion from RS232 to TTL voltage levels).

  14. Stepper Motor Circuit Details Continued • We decided that it would be possible to control both of the camera’s using a single 8051, and hence settled on the communication scheme between the Intel development board and the 8051 described earlier (ie: ‘a’, ‘b’,. ‘c’, and ‘d’ representing both a particular camera and a specified movement direction). We could just as easily have used 2 microprocessors to accomplish the task, but this would obviously have been a waste of resources. • Thus controlling the movement of the digital camera simply involves the combination of the principles learned in 2 of your labs (once the server, isky, is aware of the user’s desired camera movement)

  15. 8051 microprocessor code sbit CommonDirection = P2^0; sbit B256Clk = P2^1; sbit B265Clk = P2^2; #define CLOCKWISE 0 #define COUNTER_CLOCKWISE 1 #define B256_RIGHT 'a' #define B256_LEFT 'b' #define B265_RIGHT 'c' #define B265_LEFT 'd' void main() { for(;;) { switch(ReceiveSerial()) { case B256_LEFT : CommonDirection = CLOCKWISE; B256Clk = 1; Delay(250); B256Clk = 0; break; case B256_RIGHT : CommonDirection = COUNTER_CLOCKWISE; B256Clk = 1; Delay(250); B256Clk = 0; break; } } }

More Related