Title: CS Department Lab-Cams Embedded Systems in Practice
1CS Department Lab-CamsEmbedded Systems in
Practice
- Implemented by
- The Embedded Systems Group
2Components 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
3Steps 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
4Steps 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 users desired
movement of the camera - The server communicates this information to the
8051 which then moves the camera.
5Web 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 gt Move camera in B256 right
- b gt Move camera in B256 left
- c gt Move camera in B265 right
- d gt Move camera in B265 left
6The HTML Code for the B256 Labcam page
ltFONT COLOR"0000FF"gt ltH1 ALIGNCENTERgtThe
Fabulous B256 Cam!lt/H1gt lt/FONTgt ltCENTERgt ltIMG
SRC"/cgi-bin/send_image.pl?imageimg2.jpg"
ALIGNCENTER BORDER5gt lt/CENTERgt ltTABLE
BORDER0 CELLSPACING0 CELLPADDING0 WIDTH"100"
NOSAVE ALIGNCENTERgt ltTR NOSAVEgt ltTD NOSAVE
ALIGNCENTERgt ltFORM method"post"
action"../cgi-bin/client.cgi?b"gt ltinput
type"Submit" value"ltlt"gt lt/formgt lt/TDgt ltTD
NOSAVE ALIGNCENTERgt ltBgtCamera
Controlslt/Bgt lt/TDgt ltTD NOSAVE
ALIGNCENTERgt ltFORM method"post"
action"../cgi-bin/client.cgi?a"gt ltinput
type"submit" value"gtgt"gt lt/formgt lt/TDgt lt/TABLE
gt
7Client 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.
8Portions of Code for Client Net App. (client.cc)
if(strcmp(argv1, "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! coutltlt"Content-Type
text/html"ltltendlltltendl coutltlt"ltHTMLgt"ltltend
l coutltlt"ltHEADgtltTITLEgtError!lt/TITLEgtlt/HEAD
gt"ltltendl coutltlt"ltBODYgt"ltltendl
coutltlt"ltH1gtError!lt/H1gt"ltltendl
coutltlt"ltPgtServer is busy."ltltendl
coutltlt"Please try again a little later."ltltendl
coutltlt"lt/BODYgt"ltltendl
coutltlt"lt/HTMLgt"ltltendl return 0
//We have a connection write(fd, "d",
1) //We're done talking to isky
close(fd)
9Client.cc continued
// Now that we've successfully moved the camera,
we will output the // correct page. if
(strcmp(argv1, "a") 0 strcmp(argv1,
"b") 0) // MUCH CODE REMOVED
coutltlt"Content-Type text/html"ltltendlltltendl
coutltlt"ltHTMLgt"ltltendl coutltlt"ltHEADgtltTITLEgtThe
Fabulous B256 Cam!lt/TITLEgt"ltltendl coutltlt"ltIMG
SRC\"../cgi-bin/send_image.pl?imageimg2.jpg\"
ALIGNCENTER BORDER5gt"ltltendl
coutltlt"lt/CENTERgt"ltltendl coutltlt"ltTABLE BORDER0
CELLSPACING0 CELLPADDING0 WIDTH\"100\" NOSAVE
ALIGNCENTERgt"ltltendl coutltlt"ltTR
NOSAVEgt"ltltendl coutltlt"ltTD NOSAVE
ALIGNCENTERgt"ltltendl coutltlt"ltFORM
method\"post\" action\"../cgi-bin/client.cgi?b\"
gt"ltltendl coutltlt"ltinput type\"Submit\"
value\"ltlt\"gt"ltltendl coutltlt"lt/formgt"ltltendl
return 0
10Server Net Application Design Details
- The drivers for the digital cameras were written
for Windows 95, and since we werent 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.
11Server Application code (server.cpp)
bool PerformCommand(char cmd, Port p) // make
the new move if (cmd 'a') if (currPos1 lt
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(buf0
, p) false ) cout ltlt "unable
to execute user's command." ltlt endl closeso
cket(incomingSocket)
12Server Application code (port.cpp)
PortPort(unsigned port, unsigned baud)
DefaultTimeout(1000) char buf32 DCB
commState sprintf(buf, "COMi", 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 PortWrite(const void buf,
unsigned szBuf) DWORD check 0 if(
handle ) WriteFile(handle, buf, szBuf,
check, 0) return check
13Stepper 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).
14Stepper Motor Circuit Details Continued
- We decided that it would be possible to control
both of the cameras 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 users desired
camera movement)
158051 microprocessor code
sbit CommonDirection P20 sbit B256Clk
P21 sbit B265Clk P22 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 B256Cl
k 1 Delay(250) B256Clk 0 break