Anda di halaman 1dari 91

SEARCH AND RESCUE ROBOT: A Final Report Detailing How Four OSU

Senior Design II Students Designed a Working


Search and Rescue Robot Prototype

Presented to:
Dr. Teague, Class Administrator
Dr. Fierro, Group Mentor

Monday, December 8, 2003

Ben Lee
Kazi Islam
Josh Wheeler
Julius Marpaung
EXECUTIVE SUMMARY
The search and rescue robot is probably one of the most talked about technologies in today’s
world. These days, when the world is full of natural calamities, terrorist attacks, and unfortunate
incidents, the search and rescue robot is standing shoulder to shoulder with humanity.

A search and rescue robot can have many features. One of the most important features that our
search and rescue robot has is a camera that is mounted on top of our robot. This camera can be
used to see where our vehicle is going and visually assess the environment. The robot has
sensors to send continuous streams of data in terms of humidity, temperature, and pressure. This
particular search and rescue robot can be driven using the keyboard arrow keys, by entering the
direction and duration of time that the vehicle should move in this direction, or by using voice
commands.

This search and rescue robot costs just under $400.00. There are several features that can be
added to a search and rescue robot according to the intended use of the robot. Up to 15 sensors
could be utilized on our current search and rescue robot without changing which microcontroller
is used. This would allow up to 11 more sensors to be added to the current search and rescue
robot. Adding a sensor that detects explosive vapors in the air would make our robot better
equipped for detecting bombs, and our robot’s size and shape make it perfect to maneuver in
these types of situations.

There are many groups who are interested in search and rescue robots. The Department of
Intelligence for the U.S government is working closely with groups of robotic engineers all over
the country in developing the search and rescue robot. Therefore, they could be a primary target
to market our product. Also, fire departments from all over the country, as well as other rescue
organizations, could be interested in our robot.

The search and rescue robot is no longer a luxury item. Instead, it is a resource that can be used
by many. Overall, the findings in this report show that there are ample reasons to develop search
and rescue robots and much work remains to be done. Due to the rise of war all around the
world, natural disasters such as earthquakes and tornadoes, and various types of terrorist attacks
nationally, as well as internationally, development of search and rescue robots are essential.

Page ii
ABSTRACT
The search and rescue robot has a suite of sensors as well as a video camera to accurately assess
a given environment. The sensors used for this search and rescue robot take data with respect to
temperature, relative humidity, and barometric pressure. The sensor values are sent to a
microcontroller (PIC16F876), which takes the analog voltage values and converts them into 10-
bit digital values. The PIC then sends each digital value to the TXM-916-ES transmitter. This
transmitter sends the value wirelessly to the RXM-916-ES receiver. The receiver then sends the
data to the MAX232 chip, which changes the voltage values from 0 (for low) to -9 and 5 (for
high) to +9 volts. This was necessary to allow the values to be read into the serial port of the
base computer. The base computer then changes the three 10-bit sensor values back to analog
voltages. After the conversion back to analog, the base computer then applies each of the analog
voltages to the appropriate equations (specified in the data sheets) to provide the correct
temperature, humidity, and pressure readings. Once the correct readings have been determined,
the base computer then outputs these values to the screen at a user-defined refresh rate. The
graphical user interface also allows the user to log the given sensor data, either automatically at
the user-defined refresh rate or manually at the user’s request.

The next step in designing the search and rescue robot was to control the robot from the
computer. Originally, the robot was going to be controlled via the remote control that was
provided with the vehicle. The team decided that the vehicle should be controlled from the
computer, which would allow us to have more control of the robot. Using reverse engineering,
the existing circuitry from the vehicle was used to control the robot. The team then added code
to the program that would allow the user to control the robot in three different ways. First, the
arrow keys on the keyboard can be used to maneuver the robot. Second, the user has the option
to select the direction of motion and specify the duration of time that the robot should move in
this direction. Third, the robot can be controlled by speaking a specific set of voice commands
into a microphone.

The initial project proposal stated that the search and rescue robot should be able to wirelessly
transmit data from a sensor array (temperature, humidity and pressure) and wirelessly transmit a
real-time video feed from the vehicle. The search and rescue robot was to be controlled by the
user to allow the user to move the vehicle in and around the area in which the user wishes to
collect information. The final results of the project meet and exceed all specifications that were
laid out in the project proposal.

Page iii
TABLE OF CONTENTS
EXECUTIVE SUMMARY ........................................................................................................................................ ii
ABSTRACT ............................................................................................................................................................... iii
LIST OF TABLES.......................................................................................................................................................v
LIST OF FIGURES................................................................................................................................................... vi
INTRODUCTION .......................................................................................................................................................1
BACKGROUND OF PROBLEM ....................................................................................................................................1
STATEMENT OF PROBLEM .......................................................................................................................................2
TECHNICAL DESCRIPTION ..................................................................................................................................3
SENSOR DATA ACQUISITION, TRANSMISSION, AND RECEPTION..............................................................................3
Sensors (Kazi Islam)........................................................................................................................................3
Interface (Ben Lee)..........................................................................................................................................6
Radio Frequency Transmission (Josh Wheeler)..............................................................................................7
Base Computer Station (Julius Marpaung) .....................................................................................................7
VIDEO TRANSMISSION AND RECEPTION (JOSH WHEELER) ......................................................................................7
CONTROL OF CAR....................................................................................................................................................8
On-Board Vehicle Reception and Control (Ben Lee) ......................................................................................8
Control of Hand-Held Remote Control Board via the Parallel Port (Ben Lee) ..............................................8
Control of Parallel Port on the Base Computer Station (Julius Marpaung)...................................................9
RESULTS................................................................................................................................................................11
PROBLEMS ENCOUNTERED ....................................................................................................................................11
BELIEVABILITY OF RESULTS .................................................................................................................................13
MODIFICATIONS TO THE ORIGINAL PROJECT .........................................................................................................13
SUMMARY AND CONCLUSIONS ........................................................................................................................14
REFERENCES ..........................................................................................................................................................16
APPENDIX A – TABLES AND FIGURES.............................................................................................................17
APPENDIX B – SARR OPERATION MANUAL ..................................................................................................21
SETUP ....................................................................................................................................................................21
SENSOR MEASUREMENTS ......................................................................................................................................21
CONTROL OPERATION ...........................................................................................................................................25
SHUTDOWN ...........................................................................................................................................................26
APPENDIX C – SARR SERVER/CLIENT OPERATION MANUAL.................................................................27
SERVER SETUP AND OPERATION ...........................................................................................................................27
CLIENT SETUP AND OPERATION ............................................................................................................................27

Page iv
LIST OF TABLES
TABLE 1: ARROW KEY CONTROL COMMANDS ..............................................................................................................9
TABLE 2: VOICE CONTROL COMMANDS .......................................................................................................................10
TABLE 3: RANGE SPECIFICATIONS ..............................................................................................................................11
TABLE 4: VIDEO SPECIFICATIONS ...............................................................................................................................11
TABLE 5: POWER CONSUMPTION.................................................................................................................................11
TABLE A-1: PIN DESIGNATIONS FOR THE HTM1505-ND ...........................................................................................18
TABLE B-1: ARROW KEY CONTROL COMMANDS ........................................................................................................25
TABLE B-2: VOICE CONTROL COMMANDS ...................................................................................................................26

Page v
LIST OF FIGURES
FIGURE 1: RH / VOLTAGE RELATIONSHIP OF THE HTM1505-ND.................................................................................4
FIGURE 2: TEMPERATURE / RESISTANCE RELATIONSHIP OF THE HTM1505-ND ..........................................................4
FIGURE 3: INTERNAL BLOCK DIAGRAM OF ASDX030A24R.........................................................................................5
FIGURE 4: PERFORMANCE CHARACTERISTICS OF THE ASDX030A24R .......................................................................6
FIGURE 5: SCHEMATIC OF HANDHELD CONTROLLER IMPLEMENTATION .......................................................................9
FIGURE A-1: HUMIDITY AND TEMPERATURE SENSOR (HTM1505-ND)......................................................................17
FIGURE A-2: PRESSURE SENSOR (ASDX030A24R)....................................................................................................17
FIGURE A-3: PIN-OUT DIAGRAM OF HTM1505-ND....................................................................................................17
FIGURE A-4: PIN OUT DIAGRAM OF ASDX030A24R..................................................................................................18
FIGURE A-5: DETAILED SCHEMATIC OF INTERFACE ....................................................................................................18
FIGURE A-6: DETAILED PIC PROGRAM FLOWCHART ..................................................................................................19
FIGURE A-7: SIMPLIFIED FLOWCHART OF THE SENSOR DISPLAY PORTION OF THE SARR PROGRAM .........................20
FIGURE B-1: SARR WINDOW IMMEDIATELY AFTER OPENING ....................................................................................22
FIGURE B-2: TRANSMITTER RECEIVER SYNCHRONIZATION WINDOW.........................................................................22
FIGURE B-3: SAMPLE LOG FILE ..................................................................................................................................23
FIGURE B-4: SARR TUTORIAL WINDOW ....................................................................................................................24
FIGURE B-5: ABOUT US WINDOW ...............................................................................................................................25
FIGURE C-1: SARR SERVER WINDOW ........................................................................................................................27
FIGURE C-2: CLIENT LOGIN WINDOW .........................................................................................................................28
FIGURE C-3: SARR CLIENT WINDOW.........................................................................................................................29

Page vi
INTRODUCTION

The following report was written to describe the efforts of four students enrolled in ECEN 4023
to accomplish a given design task. The proposed task was listed as a candidate project for the
class on the course website [1]. The description shown there is below.

1. Wireless Mobile Sensor

In this project students are to design a wireless mobile sensor. The design consists of
three main components: (1) a mobile platform, (2) a suite of sensors, and (3) a wireless
communication link. Mobile robots/sensors are currently being used in many
applications ranging from space exploration, to battlefield assessment, to search and
rescue operations. The mobile robot designed under this project will be able to scan its
environment using vision and gather environmental information such as temperature,
humidity, barometric pressure, and possibly other values of interest. The vehicle will be
able to move based on commands sent over a wireless link from a remote user terminal.
Measured values, video, and status will be returned and displayed on the user terminal in
real time over the wireless link.

The original idea of the project began in the concluding weeks of ECEN 4013. Three of the
team members proposed a wireless mobile sensor that would measure the temperature, humidity,
and pressure. As time progressed, the idea evolved into a search and rescue robot. A camera
was needed to provide drivability for the car. When the teams were assigned for the course, the
above description was given as a pattern to follow. Dr. Rafael Fierro, the team’s “Project
Mentor”, held meetings with the team to finalize the project requirements, which were later laid
out in the Project Proposal. In these meetings it was decided that, due to the complexity of the
project, a working remotely-controlled car would be purchased to use for the design. In addition,
the video sending and receiving equipment would be purchased as a complete unit.

After delivering the Project Proposal, the team began designing. The final prototype includes a
radio-controlled car equipped with a camera and temperature, humidity, and pressure sensors.
The car sends video and sensor information to the base computer, while the base computer
controls the car. All this is done wirelessly. The base computer program has many features
including logging capability, fixed-duration control commands, and voice activated control, all
while receiving real-time video and sensor data.

Background of Problem
Although the prototype has a relatively small range of operation and was not made to handle
rough terrain, the idea provides a layout for many applications. Two main applications of the
design that would require some small alterations of the prototype are search and rescue
operations and bomb detection systems.

Page vii
First, the purpose of the search and rescue aspect would be to send the robot into places where
people do not have access, because of rugged terrain or harsh conditions, and bring something
back. The object of retrieval could be information in the form of video and sensor data, or it
could be actual objects, in which case the car would need to be equipped with adequate
mechanical retrieval devices. This would allow rescue workers to work effectively and
efficiently.

Second, the prototype could be altered to detect bombs in parking lots. With an additional
camera on board, perhaps with pan and tilt capabilities, the vehicle could be driven through
parking lots to search for explosive devices under cars. Applications for this technology are
numerous. It would be valuable at crowded sporting events that may be high risk for terrorist
attack, where several replicas could be employed on random parking lot checks. Also, it could
be used at high security checkpoints for military or other governmental departments. While
some personnel are checking drivers’ identifications, other personnel could be operating the
search and rescue robot in order to check the drivers’ cars for explosives.

Statement of Problem
As stated in the project proposal, the search and rescue robot should send temperature, humidity,
and barometric pressure values from the environment in which the robot is introduced back to a
base computer. The search and rescue robot could ideally be used in places that would not be
safe for a human to enter. Due to the nature of the design, a wireless camera is needed to allow
the user to see real-time video of the area in question, which would then allow the user to assess
the potentially dangerous situation accurately. With the real-time video installed, the user would
be able to maneuver the robot using only the video, rather than needing a direct line of sight to
the robot.

The next aspect of the search and rescue robot would be the wireless transmission of the sensor
data to the user. The user should be able to login at a base computer and have reliable real-time
information from the sensors, as well as the camera. This information must be real-time to allow
the user to make quick decisions about a possibly harsh environment, such as a fire or rapidly
decreasing temperatures. The user must be able to maneuver the robot into a harsh environment,
while avoiding obstacles, take data from the environment, and then maneuver out of the
environment. So, complex control commands would also be helpful.

Page viii
TECHNICAL DESCRIPTION

Sensor Data Acquisition, Transmission, and Reception


This section describes the final implementation of the mobile sensor unit. How the individual
components function and why design decisions were made are topics in this section.

Sensors (Kazi Islam)


According to the design specifications, the objective was to show our sensor data of temperature,
humidity, and pressure. One chip was used to get humidity and temperature readings, while
another one was used to measure pressure. A picture of each is found in Appendix A, Figures
A-1 and A-2.

Temperature and Humidity Sensor (HTM1505-ND):


The part number for the sensor that was used is HTM1505-ND. The sensor is manufactured by
Humirel, and was purchased from Digikey for $20.00. This sensor was selected based on its
characteristics, such as its maximum output voltage, operating temperature, humidity range, and
the % error after it is calibrated by the manufacturer, which is listed below.

Specifications of HTM1505-ND
The specifications of this sensor are found in [2]. The HTM1505-ND has a solid patented
structure. As the design project is a search and rescue robot, it is necessary for the body structure
of this sensor to be able to be in any place under any hazardous situation. It has high resistance to
chemicals, and it is capable enough to work in acidic, salty, or any other harsh chemical
environment. This particular sensor is not light sensitive, which was an important goal for our
project as light should not be an issue for a search and rescue robot. The temperature range for
this particular sensor reads from -30°C to +85°C, and the humidity range for this sensor is 1% to
99% RH. The maximum supply voltage is 5 Volts DC, and the accuracy of both the humidity
and temperature readings after calibration is ±5% at 10% to 95% RH at 23°C or room
temperature. This device is not protected against reversed polarity, so it is always good to check
the connection of the pins before connecting this sensor to any electronic device. A detailed
schematic and table of the pin-out designations has been included in Appendix A, as Figure A-3
and Table A-1.

The HTM1505 is a humidity and temperature transducer designed to get accurate measurements.
Basically, a direct interface with a micro-controller is made possible with the module’s linear
voltage output for humidity and direct NTC outputs for temperature. Temperature in this sensor
is measured with respect to resistance, and humidity is measured with respect to voltage.

Page ix
Humidity vs. Voltage
100

Relative Humidity (% RH)


90
80
70
60
50
40
30
20
10
0
1 1.5 2 2.5 3 3.5 4
Output Voltage (V)

Figure 1: RH / Voltage Relationship of the HTM1505-ND

The above graph shows that the plot of voltage vs. relative humidity is a linear curve, as it was
expected.

Temperature vs. NTC Resistance

90
Temperature (deg C)

70

50

30

10

-10

-30
0 20 40 60 80 100 120
Resistance (k-Ohms)

Figure 2: Temperature / Resistance Relationship of the HTM1505-ND

The plot of resistance vs. temperature shows that the greater the temperature, the lesser the
resistance is for this particular sensor. Both of these graphs are obtained from data or equations
given in the data sheets.

Page x
Pressure Sensor (ASDX030A24R)
The part number of the pressure sensor that was used is ASDX030A24R. The sensor is
manufactured by Invensys Sensor Systems, which has become a part of Honeywell Sensing and
Control, and was purchased from Digikey for $30.00. This sensor was selected based on its
characteristics such as its maximum output voltage, operating mode, lifetime, and the % error
after it is calibrated by the manufacturer, which is listed below.

Specifications of ASDX030A24R
The specifications of this sensor are found in [3]. The ASDX030A24R has a solid patented
structure. As the design project is a search and rescue robot, it is necessary that the body
structure of this sensor is capable enough to be in any place under any hazardous situation. It has
high resistance to chemicals, and it is capable enough to work in acidic, salty, or any other harsh
chemical environment. This particular sensor is not light sensitive, and that was an important
goal for our project as light should not be an issue for a search and rescue robot. The operating
temperature range for this particular sensor is -20°C to +105°C, and it can measure from 0 PSI to
30 PSI. The maximum supply voltage is 5.25 volts DC, and the maximum output current is 2
mA from source. The accuracy to measure pressure after calibration is ±2% at capable
surroundings. The ASDX030A24R is not protected against reversed polarity, so it is always
good to check the connection of the pins before connecting this sensor to any electronic device.

A schematic of the pin-out designations has been included in Appendix A, Figure A-4.
According to the Figure 3, to work properly this particular sensor needs at least 220nF between
the supply voltage and GND. This 220nF capacitor is not internally built and the user needs to
provide it while designing the circuit and using this sensor. We used a 1uF capacitor between
the supply voltage and GND for our application. Faults in accuracy of this pressure sensor are
due to the combined errors of offset and span calibrations, linearity, pressure hysteresis, and
temperature effects.

Figure 3: Internal Block Diagram of ASDX030A24R

Page xi
Performance characteristic of this sensor is shown in Figure 4. This figure shows the error band
multiplier from -20°C to +105°C, as the operating temperature range for this sensor is from -
20°C to +105°C.

Figure 4: Performance Characteristics of the ASDX030A24R

Interface (Ben Lee)


The interface requires analog to digital conversions (ADCs) to be performed on the analog
voltage output of the sensors. This data must then be sent in serial format through the transmitter
and receiver to the base computer.

The PIC16F876 was chosen to perform the interfacing. It designates five pins for 10-bit ADCs.
With the sensor ranges listed in the Sensors section, 10-bit conversions allow for an accuracy of
0.107 °C, 0.029 PSI, and 0.096 %RH. This provides more accuracy than the sensors are capable
of.

Five pins are designated for ADCs, but unless more than one timer is used, only one pin may be
read at a time with accuracy. Because of this, a single pin (pin A0) was used to read in the
analog sensor values, while four other pins switched between temperature, humidity, pressure,
and the supply voltage (used for low battery detection). N-channel MOSFETs were
implemented as switches, and pins B2, B4, B5, and B6 were used to control the gates. When no
switch was on the ADC input was tied low through a 2.2 kΩ pull-down resistor. A detailed
schematic of the interface circuit board has been included in Appendix A as Figure A-5.

Once the PIC has stored the 10-bit sensor values as integers, they are converted to strings, and
appended to an array. The format of the string array is, “X,ABCD,”. The letter, X, can be a P,
T, or H, standing for pressure, temperature, and humidity respectively. The letters, ABCD,
represent a 10-bit decimal integer holding the sensor information of the preceding letter X.

The time that it takes to acquire each sensor value and send the string is less than 4.33 ms.
Therefore, all three sensors will be updated every 13 ms, but each sensor is sent separately. The
time value is calculated from the 19200 baud rate (~ 52 µs per bit). The string contains 7

Page xii
character bytes. Three sensors are sent, and a delay of 1ms is employed for each sensor in order
to get accurate ADC values.

Pin C6 on the PIC will be used to send the sensor data serially to the transmitter. Pins B0 and B1
will be used to light a “Power On” LED and a “Low Battery” LED, respectively.

The PIC has been programmed using the hex file obtained from the PIC-C compiler. The
programming was in the PIC-C language, which is an adaptation of the C language for use with
PICs. The hex file was then loaded onto the PIC through a boot loader. Using the boot loader
required loading a preliminary hex file onto the PIC through a PIC StartPlus Programmer. A
detailed flowchart of the interfacing program is shown in Appendix A in Figure A-6.

After the serial data has been recovered by the receiver, it must be passed through a MAX232
chip before being imported into the base computer’s serial port. The MAX232 chip changes the
values for logic ‘0’ and logic ‘1’, from 0 V and +5 V, to -9 V and +9 V, respectively.

Radio Frequency Transmission (Josh Wheeler)


The transmitter and receiver purchased for this project are the TXM-916-ES and RXM-916-ES
modules made by Linx Technologies. They operate at a frequency of 916 MHz, which lies
within the amateur radio band (902 MHz to 928 MHz). The transmitter is able to communicate
with the receiver at a distance of 130 feet in optimal conditions. The transmitter and receiver had
to be mounted on separate double-sided printed circuit boards. This was necessary because the
transmitter and receiver needed a ground plane on the bottom side of the board for optimal
performance.

Base Computer Station (Julius Marpaung)


The Computer will receive all three data packages from the vehicle every thirteen milliseconds.
The computer receives the data in the following string, “T,Value,H,Value,P,Value,”, which is
read through the serial port. The value after each sensor is the corresponding 10-bit digital value.
The computer then changes the digital values back into the analog values. Then a conversion is
made from voltage to temperature, pressure, and humidity using equations provided in each
sensor’s data sheets. The user can define how fast the program refreshes the incoming data by
using the “Refresh Rate” menu. Also, the program is equipped with a logging capability. The
users may log sensor data automatically at a rate of 13 ms, 100 ms, 500 ms, or 1 s, or the users
may log data manually by pressing the “Get Data” button when a data point is desired. A
simplified flowchart is shown in Appendix A, Figure A-7.

Video Transmission and Reception (Josh Wheeler)


The video camera system that we used is the XCam2 Wireless Video Camera (Model XX11A).
The XCam2 is a very small wireless camera that sends a real time color video image to the PC.
The camera has a built-in 2.4 GHz video sender. The performance capabilities for the XCam2
can be seen in the Results section on page 11 of this report. The camera module converts video
into wireless radio frequency signals and transmits them to the video receiver. The camera

Page xiii
comes with a battery pack, which is mounted on the vehicle along with the camera. The video
receiver we used for our camera is the X10 series receiver (Model VR36A). The receiver
converts the signals back to video signals, which are to be sent to a TV or VCR. However, to
retrieve the signal from the PC we also needed a USB video capture adapter. The adapter allows
the receiver to send the signal directly to the USB port of the PC. We then use the XRay Vision
software, which was provided with the camera, to view the real-time video feed in ‘Preview’
mode.

Control of Car
Although the vehicle was purchased as a working remote control car, the team decided to control
the car from the parallel port of the base computer. This would allow a more integrated system,
and less confusion. Plus, the computer could then be used to achieve complex control
commands. This section explains the implementation of the control mechanisms.

On-Board Vehicle Reception and Control (Ben Lee)


The control reception device on-board the vehicle has not been changed from the original remote
control car. This decision was made for ease of implementation, but it afforded a few
disadvantages. 1) The control system in the car does not allow for variable speeds or turning
radii. 2) Operating at 49 MHz took up additional space in the frequency band and created
interference with the 916 MHz sensor transmissions. 3) The range of the vehicle transmission is
far below the range of the sensors and video transmission, which limits the overall range of the
system.

Control of Hand-Held Remote Control Board via the Parallel Port (Ben Lee)
The original handheld remote control contained one internal PCB. This PCB allows only one
forward/backward speed and one left/right turning radius. The board worked by making physical
connections between copper traces on the board when the user slid a connector across these
traces. The handheld box contained mechanical levers used to make the connections on the
board. There was one connection for forward, backward, left, and right. In addition, due to the
placement of the traces, the forward and backward connections could not be made at the same
time, and the right and left connections could not be made at the same time.

In order to model the mechanical control of the device with the parallel port, n-channel
MOSFETs are used to switch the connections on and off. The parallel port controls the gates of
the MOSFETs (Backward, Forward, Left, and Right) as shown below in Figure 5.

Page xiv
Handheld PCB

Backward

Forward

Right Left

Figure 5: Schematic of Handheld Controller Implementation

Control of Parallel Port on the Base Computer Station (Julius Marpaung)


The user sends the appropriate values to the parallel port to control the robot three ways: 1) by
using the arrow keys from the keyboard, 2) by sending a duration command, or 3) by using the
voice activation commands.

To use the arrow keys a user may press any combination of ↑, ↓, ←, and →. However, to protect
the handheld PCB against unrealizable operations (such as forward/backward), some
combinations produce no results. Below, Table 1 shows the possible arrow key combinations
and their results.

Table 1: Arrow Key Control Commands

Command Function
↑ Move the robot Straight Forward
↓ Move the robot Straight Backward
↑ and ← Move the robot Forward Left
↑ and → Move the robot Forward Right
↓ and ← Move the robot Backward Left
↓ and → Move the robot Backward Right
All Other Combinations Do Nothing

The user can also move the robot by specifying the direction of the robot and the time duration of
the movement. The time must be given as an integer with units of milliseconds. The user can
choose one of six movement options available: straight forward, forward left, forward right,
straight backward, backward left, and backward right. The program will not allow the user to

Page xv
choose more than one option at a time so that the program does not give unusable results. Once
the user specifies the direction of the robot and the duration of the movement, he/she must press
the “Run” button. This button will then carry the desired instruction out, while disabling the
duration movement options and the arrow key controls. After the program finishes doing the
desired task, it will stop the robot and re-enable the duration movement options and arrow key
controls. To stop the robot while the computer is carrying out a time duration command, the user
can press the “Stop” command button. The “Stop” button will cancel the duration command and
enable the duration movement options and arrow key controls again.

The user can also use the voice commands to move the robot. Visual Basic software was used to
realize the voice commands. Voice command programming tips were found from [4]. To
operate in voice command mode, the arrow keys and duration commands must be disabled by the
appropriate voice command. Table 2 lists the commands that can be used to operate the vehicle
and the corresponding results.

Table 2: Voice Control Commands

Command Function
Enable Voice Command Enables voice command control of car; deactivates other control types
Disable Voice Command Disables voice command control of car; activates other control types
Straight Forward Move the robot Straight Forward indefinitely
Forward Left Move the robot Forward Left indefinitely
Forward Right Move the robot Forward Right indefinitely
Straight Backward Move the robot Straight Backward indefinitely
Backward Left Move the robot Backward Left indefinitely
Backward Right Move the robot Backward Right indefinitely
Stop Stop the robot

Page xvi
RESULTS
The project results include the following: 1) the vehicle prototype, 2) the receiver black box, 3)
the video receiving equipment, and 4) the base computer, server, and client software. The
vehicle is equipped with a wireless video camera, a mobile sensor unit, and a speed control
receiver. The receiver black box communicates to the base computer through the serial and
parallel ports, while the video receiver communicates through the USB port. The search and
rescue robot (SARR) software displays and records sensor values, while allowing the user to
directly control the vehicle. Some important specifications of the final project model are listed in
Tables 3 through 5.

Table 3: Range Specifications

Module Range (ft)


Sensors 130
Video 130
Remote Control (with Sensors) 10
Remote Control (without Sensors) 30

Table 4: Video Specifications

Specification Result
Resolution 310 TV lines
Area Size 510 x 492
Shutter Speed 1/60th to 1/15000th second
Field of View 38.5°
Minimum Illumination 3 Lux

Table 5: Power Consumption

User Consumption
Sensors, Microcontroller, and Transmitter (9V) 240 mW
Receiver Module Positive Battery (9V) 470 mW
Receiver Module Negative Battery (9V) 90 nW

Problems Encountered
During the design process several issues emerged that created difficulties for the team. This
section lists these problems, some attempted solutions, and how well these solutions worked for
the project.

Page xvii
At the beginning of the project, the search for a relatively small wireless video camera that
provided good resolution and a fast transfer rate led to very expensive products. The team soon
learned that some trade-offs would be inevitable, if the team expected to maintain the original
proposed budget of $400. The trade-offs associated with the X10 camera are a slower transfer
rate, a smaller screen size, and a limited field-of-view. Despite these limitations, the X10
worked well for the project prototype.

However, the slower-than-expected video transfer rate sometimes caused the camera to black out
when the car was in motion. The team decided that this was unacceptable. Since a faster camera
was too expensive, the car would have to be slowed down. The speed controller onboard the car
was designed by the manufacturer for simple on/off speed control. Pulse width modulation
(PWM) was implemented from the base computer to allow the user to control the speed of the
car, but due to a deficiency in the speed controller, PWM was abandoned. Whenever a forward
pulse of short duration was sent, the car would move backward. Therefore, all control
commands using PWM resulted in backward motion, because all pulses are of short duration.
This deficiency can be seen, even now. When the user quickly taps the forward arrow key, the
car will jump backward a very short distance. In the final prototype the vehicle was slowed
down by decreasing the voltage to the drive motor.

Next, the microcontroller, or PIC, had limitations on the number of ADCs that it could perform
due to the limited number of timers. To solve this problem a switching circuit was introduced,
so that one pin and one timer could be used to measure all sensor voltages. This solution has
been described further in the Technical Description.

A very significant problem that was encountered was interference between the sensor
transmission and the control reception onboard the vehicle. The transmitter for the sensors
overpowered the control receiver of the car. The team did not anticipate this problem due to the
large difference in operating frequencies. The sensor transmitter operates at 916 MHz, and the
car control receiver operates at 49 MHz. The team was able to partially correct this problem by
reducing the output power of the sensor transmitter. Also, improvements in the control
transmitting antenna on the receiver black box provided some additional distance. Another
attempted solution included using high and low pass filters on the transmitter and receiver
onboard the car, but this offered very little improvement. As a result of this problem, the range
of the car (with the sensors operating) was limited to about one third of its potential.

Because the video software was purchased independently, it runs in its own window. The team
did not find a way to incorporate the video signal into the main program window. Therefore, the
video information cannot be viewed using the server/client program. If the video format could
have been altered to a format recognizable by Windows Media Player, this task could have been
accomplished. However, no solution to this problem was realized.

Finally, the prototype has been designed with three internal power supplies: one for the car
motors and speed controller, one for the camera, and one for the sensor transmission circuit. In
addition, two of these battery supplies are somewhat difficult to replace. This would be a simple
problem to fix, but due to time limitations the team has not implemented any solution to this
problem.

Page xviii
Believability of Results
In order to verify the accuracy of the sensor readings, three instruments were borrowed from
different academic departments at Oklahoma State University. A thermometer was used to
verify temperature measurements, a sling cyclometer was used to verify humidity measurements,
and a barometer was used to verify pressure measurements. In all three cases the measurements
were within the boundaries of error specified on the data sheet of each sensor and listed in the
Technical Description.

Modifications to the Original Project


The team made several improvements over the original project requirements. First, the car can
be driven from the base computer (or client computer) station. Originally, a handheld remote
control device was to be used. Because of this improvement, additional ways of controlling the
car have been implemented, such as time-duration commands and voice activated commands.
Further discussion of how this was accomplished is explained in the Technical Description.
Also, a detailed explanation of how to operate the vehicle controls can be found in Appendix B.

Second, the team has included a server/client program that allows a remote user (the client) to
login to the base computer station (the server), view real-time sensor information, and access the
vehicle control commands. Although the team did not find a way to implement the video into
the server/client program, the realization of remote user access for control and sensor
information is a big step toward a very useful accessory. An explanation of how to operate the
server/client program can be found in Appendix C.

Finally, the SARR software includes additional features that are useful when receiving sensor
data. The user can change the refresh rate of the screen and log segments of sensor and video
data. Further discussion of how this was implemented is explained in the Technical Description,
while a more detailed explanation of how to operate these features can be found in Appendix B.

Page xix
SUMMARY AND CONCLUSIONS
The project requirements stated that the search and rescue robot must be able to maneuver into
an environment and send information from that environment back to the user/operator. The
robot was expectd to wirelessly send temperature, humidity and pressure values, as well as
video, back to the base computer. The user/operator should be able to steer the robot through
obstacles while viewing only the video.

The team felt that the search and rescue robot contained four major sections: sensors,
microprocessor, transmitter/receiver, and base computer. The project was split into these four
sections and divided among the group members. The tasks assigned to each group member,
along with other tasks that arose along the way, are as follows:

• Kazi Islam -- Sensors


• Ben Lee -- Microprocessor/Interfacing & Remote Control Hardware
• Julius Marpaung -- Base Computer/User Interface & Remote Control Software
• Josh Wheeler -- Transmitter/Receiver, Video, & Hardware Mounting

The sensor array chosen for the project consisted of a temperature sensor, a pressure sensor, and
a humidity sensor. These sensors were to read real time data from the environment and make it
possible to send up-to-date information to the user at a base computer. Along with this sensor
array a wireless video camera was needed to provide a real time stream, which will allow the
user/operator to steer the car through various obstacles, without actually being in the area, while
attempting to gain information about the possibly hazardous environment.

The microprocessor was needed to perform analog to digital conversions on each of the three
sensor values. The microprocessor then packaged the data to be sent in a serial format (RS232)
to the base computer via the transmitter/receiver. Each package consists of an identifier (T, H, or
P) followed by a 10-bit decimal integer in string format. The microprocessor updates all three
sensor packages every 13 ms.

The transmitter takes this information and sends it wirelessly to the receiver which is located at
the base computer. The base computer then converts the 10-bit integer to a floating point
number representing the analog voltage. Then the base computer applies each analog voltage to
the appropriate equation to allow the data to be displayed with proper units. The base computer
also allows the user to maneuver the car via the arrow keys, by specifying direction and duration
of a command, or by the voice command box. In addition, the user has the option to log the data
automatically at a selected refresh rate or to manually log data at a specific instance. This gives
the user the ability to collect data from a given environment.

The final product consists of a sensor array and a video camera which is mounted on the robot.
The sensor information is sent to a black box that is connected to the computer via the serial port
of the base computer. The information is collected, interpreted, and sent to the screen
continuously by the base computer. The parallel port of the base computer is also connected to
the black box and is used to control the robot. The robot may be controlled by identifying the

Page xx
direction and duration of time that the robot should move in the specified direction, by using the
arrow keys, or by using a selection of voice commands.

Several improvements would have been implemented if the team had more time for the project.
The video screen could have been incorporated into the graphical user interface that is used to
control the robot and to output sensor information. This would allow the video screen to be
accessed in the server/client program. Also, a bi-directional transceiver could be used to control
the robot as well as send the sensor information. The bi-directional transceiver would solve the
interference problems between the sensor transmitter and the car’s receiver. Also, using the bi-
directional transceiver would allow commands to be sent to the PIC. Then the PIC could be used
to control the motors, which would allow for the removal of the original vehicle control unit, and
would provide the capacity for more control over the movement of the vehicle. Another possible
future improvement would be to combine both added battery supplies into one external battery
pack, which could be mounted on the outside of the vehicle. This would allow the user to access
the batteries without taking the vehicle apart.

In using the transmitter/receiver pair along with the sensor array that was mounted on the vehicle
we were able to provide a real-time mobile sensor unit. The video camera, which was also
mounted on the vehicle, allows the user to view the actual environment in which the vehicle is
navigating. The user is able to view and log the data that is being collected at the base computer.

Page xxi
REFERENCES
[1] Dr. Keith A. Teague, “Senior Design II,” August 2003, http://ecen4023.okstate.edu

[2] Humirel, “Humidity Temperature Sensors,” September 2003,


http://www.humirel.com/product/fichier/HTM1505.pdf

[3] Honeywell Sensing and Control, “Honeywell Sensing and Control - Pressure Sensors,”
September 2003, http://content.honeywell.com/sensing/prodinfo/pressure_all

[4] Microsoft Corporation, “Microsoft Help and Support,” Spring 2003,


http://support.microsoft.com

Page xxii
APPENDIX A – TABLES AND FIGURES
This appendix contains a variety of tables and figures referenced in the report, but not included
directly in the report.

Figure A-1: Humidity and Temperature Sensor (HTM1505-ND)

Figure A-2: Pressure Sensor (ASDX030A24R)

Figure A-3: Pin-out Diagram of HTM1505-ND

Page xxiii
Table A-1: Pin Designations for the HTM1505-ND
Pin Function
Pin 1 NTC-Temperature
Pin 2 GROUND
Pin 3 Vcc- Voltage supply
Pin 4 Vout- Humidity

Figure A-4: Pin out Diagram of ASDX030A24R

+5 V +5 V +5 V

Out from temperature sensor 10 k-Ohms

Vpp PIC16F876 B7 1 uF

Connect A0 B6
to PIN B2
A1 B5

Out from humidity sensor A2 B4


100 k-Ohms
A3 B3

Connect A4 B2
to PIN B4
A5 B1

Out from pressure sensor Vss B0

Osc1/ ClkIn Vdd 2.2 k-Ohms 2.2 k-Ohms

Connect Osc2/ ClkOut Vss


+9 V
to PIN B6
C0 C7

C1 C6
2X Ohms
C2 C5

Connect C3 C4
X Ohms to PIN B5 Serial Output
20 MHz
to Transmitter

15 pF 15 pF

Figure A-5: Detailed Schematic of Interface

Page xxiv
Turn on Turn off all
Power LED Sensor FETs

Convert Value to
Select Temperature Delay 1 Read Temperature De-select Temperature Send String
Temperature String
Sensor by turning on ms for Voltage and Assign Sensor by turning off out to
and Append to
Temperature FET accuracy to 10-bit Value Temperature FET Transmitter
String Array

Convert Value to
Select Pressure Delay 1 Read Pressure De-select Pressure Send String
Pressure String and
Sensor by turning on ms for Voltage and Assign Sensor by turning off out to
Append to String
Pressure FET accuracy to 10-bit Value Pressure FET Transmitter
Array

Convert Value to
Select Humidity Delay 1 Read Humidity De-select Humidity Send String
Humidity String and
Sensor by turning on ms for Voltage and Assign Sensor by turning off out to
Append to String
Humidity FET accuracy to 10-bit Value Humidity FET Transmitter
Array

Does Turn on FET to Delay 1 Read Battery Turn off FET


counter = n * 32 Yes read 1/2 Supply ms for Voltage and Assign for Voltage
? Voltage (9V) accuracy to 10-bit Value Divider

No

Turn on Does Value


Low Battery Yes correspond to
LED less than 3 V ?

No

Figure A-6: Detailed PIC Program Flowchart

Page xxv
Start Program

Open Serial Port

Process the data


coming in from
the serial port into
sensor readings

Show the sensor


readings on the
User Interface

No

Quit Program?

Yes

Stop the
Program and
Close the
serial port

Figure A-7: Simplified Flowchart of the Sensor Display Portion of the SARR Program

Page xxvi
APPENDIX B – SARR OPERATION MANUAL
The setup, operation, and shutdown of the Search and Rescue Robot (SARR) is explained in the
following manual.

Setup
1. Users should have a computer equipped with one serial, parallel, and USB port, along with
Visual Basic 6.0 and X10 software installed.
2. Use a DB9 cable with one male and one female end to connect the serial port of the computer
and receiver black box. Use a DB25 cable with two male connectors to connect the parallel
port of the computer and receiver black box.
3. The user is given the option to use batteries or a power supply to power the receiver black
box.
a. To use batteries, flip the switch on the receiver black box to select the “Battery On”
option.
b. To use a power supply, feed +9 V, 0 V, and -9 V into the banana cable inputs, labeled
correspondingly.
The receiver black box is now ready to receive the input signal from the car and transmit
control commands from the computer.
4. To setup the receiver for the camera, connect the video receiver to the USB port of the
computer, and plug its adapter into any 120 VAC outlet. Turn on the switch located on the
side of the receiver.
5. There are 2 switches on the rear of the car. One of them labeled “Car”, and the other labeled
“Sensors and Camera”. To turn on the car, flip the switch to the ON position. The car is now
ready to receive the commands from the computer. To turn on the Sensors and Camera, flip
the switch to the ON position. The camera is transmitting now.
6. Run the X10 software from the desktop.

Sensor Measurements
Once the user finishes setting up the hardware, he/she can run the SARR program.

1. Start the program by double clicking the SARR.exe icon.


2. Initially, the program will look like Figure B-1. Choose the “Open Serial Port” option from
the “File” menu. A “Transmitter Receiver Synchronization” window will pop up and stay
for ten seconds, as shown in Figure B-2. This is performed to ensure that the receiver has
had ample settling time. The “Transmitter Receiver Synchronization” window will close
itself after ten seconds, and the “Refresh Rate” menu and the “Log” menu will be enabled.

Page xxvii
Figure B-1: SARR Window immediately after opening

Figure B-2: Transmitter Receiver Synchronization Window

3. The user must choose the desired refresh rate of 13 ms, 100 ms, 500 ms, or 1000 ms to view
the sensor data. Once the user chooses the desired refresh rate, the program will periodically
output the incoming data to the screen.
4. The user can also log the incoming data, both manually and automatically.
a. To start logging data, the user must create a file where the data will be stored by
choosing the “Create File” option from the “Log” menu.
b. After a file has been created, the user can now choose whether to log the data
manually or automatically.

Page xxviii
c. To log the data manually, choose the option “Start Log” from the “Manual Log”
option under the “Log” menu. Toggle to the “Manual Retrieval” option on the
program. The “Get Data” command button will be enabled, allowing the user to log
the data anytime he/she wishes.
d. To log the data automatically, go to the option “Automatic Log” under “Log” menu
and choose one of the recording periods provided. These are the same values as the
refresh rates. The program will automatically start logging data immediately.
e. To stop logging the data, simply choose the option “Stop Log” from the “Log” menu.
A sample log file is shown in Figure B-3.

Figure B-3: Sample Log File

5. There are two options available on the “Help” menu: “Tutorial” and “About Us”.
a. Clicking the tutorial option will open a new window that briefly discusses how to use
the program. Figure B-4 shows the tutorial window for the SARR program.

Page xxix
Figure B-4: SARR Tutorial Window

b. The “About Us” option will pop up a new window introducing the members of this
team, as shown if Figure B-5.

Page xxx
Figure B-5: About Us Window

Control Operation
The user may control the robot one of three ways: 1) by using the arrow keys from the keyboard,
2) by sending a time-duration command, or 3) by using the voice activation commands.

1. To use the arrow keys a user may press any combination of ↑,↓,←, and →, to produce the
results listed in Table B-1.

Table B-1: Arrow Key Control Commands

Command Function
↑ Move the robot Straight Forward
↓ Move the robot Straight Backward
↑ and ← Move the robot Forward Left
↑ and → Move the robot Forward Right
↓ and ← Move the robot Backward Left
↓ and → Move the robot Backward Right
All Other Combinations Do Nothing

Page xxxi
2. The user can also move the robot by specifying the direction of the robot and the time
duration of the movement.
a. Enter the time as an integer with units of milliseconds in the duration box.
b. Next, choose one of the six movement options available: straight forward, forward
left, forward right, straight backward, backward left, and backward right.
c. Then press the “Run” button.
d. To stop the robot in motion, press the “Stop” button.
3. The user can also use the voice commands to move the robot. To operate in voice command
mode, the arrow keys and duration commands must be disabled by the appropriate voice
command. Table B-2 lists the commands that can be used to operate the vehicle and the
corresponding results.

Table B-2: Voice Control Commands

Command Function
Enable Voice Command Enables voice command control of car; deactivates other control types
Disable Voice Command Disables voice command control of car; activates other control types
Straight Forward Move the robot Straight Forward indefinitely
Forward Left Move the robot Forward Left indefinitely
Forward Right Move the robot Forward Right indefinitely
Straight Backward Move the robot Straight Backward indefinitely
Backward Left Move the robot Backward Left indefinitely
Backward Right Move the robot Backward Right indefinitely
Stop Stop the robot

Shutdown
1. To close the serial port, simply choose the option “Close Serial Port” from the “File” menu.
2. To close the program, a user can choose the option “Quit” from the “File” menu or click the
X on the top right of the window. If the user closes the main window without closing the
serial port, the serial port will be closed automatically. Also, if the user closes the main
window while a log is being recorded, the program will automatically save the data written to
the file.
3. Finally, turn off the power supply for the receiver black box or flip the battery switch to the
off position on the receiver black box.
4. Turn off both switches on the car.
5. Turn off the switch on the video receiver.

Page xxxii
APPENDIX C – SARR SERVER/CLIENT OPERATION MANUAL
The setup, operation, and shutdown of the Search and Rescue Robot (SARR) Server and Client
programs are explained in the following manual.

Server Setup and Operation


To use the SAR server program, run SARserver.exe. After loading, the program will do nothing
until a client is connected. Users cannot move the robot using the server but they can still see the
data coming in from the robot using the desired refresh rate and they may log the data once a
client is connected. The program notifies the user at the bottom of the screen if a user is
connected. Please refer to Appendix B on how to use the “Refresh Rate” and “Log” menus.
Figure C-1 shows the appearance of the SARR Server Window.

Figure C-1: SARR Server Window

Client Setup and Operation


To use the SAR client program, the SAR server program must first be setup. Then the
SARclient.exe program may be executed. After loading, the program will prompt the user for a
user name, password, and the Server IP address. After entering the information, the users should

Page xxxiii
then press the “Login” button. This will allow the SARR client program to connect to the
desired SARR server and verify the user name and password. Figure C-2 displays the Client
Login Window.

Figure C-2: Client Login Window

If the user name and password is valid, then the client program will open. The client program
differs from the original program in only one area. There are no open and close serial port
commands. These features have been replaced by “Relogin” and “Close Connection”. Choosing
“Relogin” from the “Client” menu will disconnect the server and client, and the user will have to
specify the Server IP address, user name, and password again. Choosing “Close Connection”
will disconnect the server and client, but will not initiate a re-login. To open a connection to the
server, the users must choose the option “Relogin” from the “Client” menu. Figure C-3 displays
the SARR Client Window.

Page xxxiv
Figure C-3: SARR Client Window

Please refer to Appendix B for further instruction on the SARR operation.

Page xxxv
APPENDIX D – BASE COMPUTER CODE (VISUAL BASIC)
Option Explicit

Dim dblTemp As Double, dblPress As Double, dblHumi As Double


Dim dblTemp1 As Double, dblTemp2 As Double, dblTempC As Double, dblTempF As
Double
Dim dblHumidity1 As Double, dblHumidityRH As Double
Dim dblPressure1 As Double, dblPressurePSI As Double, dblPressureAtm As
Double
Dim strmydata As String, strmydata1 As String
Dim strmyarray() As String, strmyarray1() As String
Dim intnumberofdata As Integer, intdatacounter As Integer
Dim intpackagecheck As Integer, intpackagecheck1 As Integer
Dim dblManualTemp As Double, dblManualHumi As Double, dblManualPress As
Double
Dim strManualTempunit As String, strManualHumiunit As String,
strManualPressunit As String
Dim strLog As String
Dim bLogManual As Boolean, bLogAutomatic As Boolean, bFileOpen As Boolean
Dim iFile As Integer
Dim bisup As Boolean, bisdown As Boolean, bisleft As Boolean, bisright As
Boolean
Dim intx As Integer, intxup As Integer, intxdown As Integer
Dim intGear As Integer, intxleft As Integer, intxright As Integer
Dim bForward As Boolean, bMoveCheck As Boolean
Dim intCountHeat As Integer, intCountHeat1 As Integer, intCountHeatLoop As
Integer
Dim strVoiceCommand As String, strVoiceCommand1 As String, start As String,
strVoiceColor As String, bVoiceCommand As Boolean

Private Sub Form_Load()

Out Val("&H378"), Val(1)


MSComm1.CommPort = 1

If MSComm1.PortOpen = True Then


MSComm1.PortOpen = False
End If

MSComm1.Settings = "19200,N,8,1"
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.InputLen = 0

bForward = True
bMoveCheck = True
bisup = False
bisdown = False
bisleft = False
bisright = False
intx = 0
intxup = 1
intxdown = 2
intxleft = 4

Page xxxvi
intxright = 8

intCountHeat = 0
intCountHeat1 = 100
intCountHeatLoop = 0

TimerRefresh.Enabled = False
TimerLog.Enabled = False
cmdGetManualData.Enabled = False
strmydata = ""
bLogManual = False
bFileOpen = False
bLogAutomatic = False
bVoiceCommand = False
Me.mnuRefresh.Enabled = False
Me.mnuLog.Enabled = False
Me.Height = Screen.Height
Me.Move 0, 0
Me.OptionCelcius.Value = True
Me.OptionReal.Value = True
Me.KeyPreview = True

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

'This Sub is to close the serial port, stop the car and close the data log
once
'the program Is closed

If MSComm1.PortOpen = True Then


MSComm1.PortOpen = False
End If

Out Val("&H378"), Val(1)

If bFileOpen Then
Close #iFile
End If

End Sub

Private Sub mnuAbout_Click()


'This Sub is to show Form 3 which is about this team
Form3.Show
End Sub

Private Sub mnuCreateFile_Click()


'This Sub is to create a log file

If bFileOpen Then
Close #iFile
End If

On Error Resume Next


Me.CommonDialog1.InitDir = App.Path
Me.CommonDialog1.DefaultExt = ".log"

Page xxxvii
Me.CommonDialog1.FileName = "Log1.log"
Me.CommonDialog1.Filter = "Log File (*.log)|*.log|All Files (*.*)|*.*"
Me.CommonDialog1.FilterIndex = 0
Me.CommonDialog1.CancelError = True
Me.CommonDialog1.ShowSave

If Err.Number = 0 Then
If Len(Me.CommonDialog1.FileName) > 0 Then

iFile = FreeFile
Open Me.CommonDialog1.FileName For Output As #iFile
bFileOpen = True
End If
Else
Err.Clear
End If
On Error GoTo 0

End Sub

Private Sub mnuManualStartLog_Click()

'This Sub is to manually log the data


If bFileOpen = True Then
bLogManual = True
bLogAutomatic = False
TimerLog.Enabled = False
End If

End Sub

Private Sub mnuStopLog_Click()

'This Sub is to stop the data log


TimerLog.Enabled = False

If bLogManual = True Then


bLogManual = False
End If

If bLogAutomatic = True Then


bLogAutomatic = False
End If

End Sub

Private Sub mnuLog10ms_Click()

'This Sub is to automatically log the data every 10 ms


If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 10
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = True

Page xxxviii
mnuLog100ms.Checked = False
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog100ms_Click()

'This Sub is to automatically log the data every 100 ms


If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 100
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False
mnuLog100ms.Checked = True
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog500ms_Click()

'This Sub is to automatically log the data every 500 ms


If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 500
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False
mnuLog100ms.Checked = False
mnuLog500ms.Checked = True
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog1000ms_Click()

'This Sub is to automatically log the data every 1000 ms


If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 1000
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False

Page xxxix
mnuLog100ms.Checked = False
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = True

End If

End Sub

Private Sub mnuTutorial_Click()


'This Sub is to show Form 5 which is a tutorial form
Form5.Show
End Sub

Private Sub TimerLog_Timer()


'This Sub is the timer to log the data

If bLogManual = False And bLogAutomatic = True And bFileOpen = True Then

If Me.OptionCelcius.Value = True Then


dblManualTemp = FormatNumber(dblTempC, 3)
strManualTempunit = " C"
ElseIf Me.OptionFahrenheit.Value = True Then
dblManualTemp = FormatNumber(dblTempF, 3)
strManualTempunit = " F"
End If

dblManualHumi = FormatNumber(dblHumidityRH, 3)
strManualHumiunit = " %RH"

If Me.OptionPSI.Value = True Then


dblManualPress = FormatNumber(dblPressurePSI, 3)
strManualPressunit = " PSI"
ElseIf Me.OptionAtm.Value = True Then
dblManualPress = FormatNumber(dblPressureAtm, 3)
strManualPressunit = " Atm"
End If

strLog = Now & "," & "Temperature: " & dblManualTemp & strManualTempunit &
"," & "Humidity: " & dblManualHumi & strManualHumiunit & "," & "Pressure: " &
dblManualPress & strManualPressunit

Print #iFile, strLog

End If

End Sub

Private Sub mnuOpenPort_Click()


'This Sub is to open the serial port

Me.mnuOpenPort.Checked = True
Me.mnuClosePort.Checked = False
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
Form4.Show
Me.TimerProgress.Enabled = True
Me.mnuFile.Enabled = False

Page xl
End If

End Sub

Private Sub TimerProgress_Timer()


'This Sub is to synchronize Transmitter Receiver

Unload Form4
Me.TimerRefresh.Enabled = True
Me.TimerProgress.Enabled = False
Me.mnuFile.Enabled = True
Me.mnuRefresh.Enabled = True
Me.mnuLog.Enabled = True
End Sub

Private Sub mnuClosePort_Click()


'This Sub is to close the serial port

Me.mnuOpenPort.Checked = False
Me.mnuClosePort.Checked = True

If MSComm1.PortOpen = True Then


MSComm1.PortOpen = False
End If

TimerRefresh.Enabled = False
Me.TimerRefresh.Interval = 0
TimerLog.Enabled = False

Me.mnuRefresh.Enabled = False
Me.mnuLog.Enabled = False
mnuNoRate.Checked = True
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False

'Real Time
Me.lblTemp1.Enabled = True
Me.txtTemp1.Enabled = True
Me.txtTemp1.Text = ""
Me.lblTemperature1.Enabled = True
Me.lblHum1.Enabled = True
Me.txtHum1.Enabled = True
Me.txtHum1.Text = ""
Me.lblHumidity1.Enabled = True
Me.lblPress1.Enabled = True
Me.txtPress1.Enabled = True
Me.txtPress1.Text = ""
Me.lblPressure1.Enabled = True

'Manual Time
Me.lblTemp2.Enabled = True
Me.lblHum2.Enabled = True
Me.lblPress2.Enabled = True
Me.txtTemp2.Enabled = True

Page xli
Me.txtTemp2.Text = ""
Me.txtHum2.Enabled = True
Me.txtHum2.Text = ""
Me.txtPress2.Enabled = True
Me.txtPress2.Text = ""
Me.lblTemperature2.Enabled = True
Me.lblHumidity2.Enabled = True
Me.lblPressure2.Enabled = True

'Log Output
Me.lblLogTemp.Enabled = True
Me.lblLogHumi.Enabled = True
Me.lblLogPress.Enabled = True
Me.txtTemp3.Enabled = True
Me.txtTemp3.Text = ""
Me.txtHum3.Enabled = True
Me.txtHum3.Text = ""
Me.txtPress3.Enabled = True
Me.txtPress3.Text = ""
Me.lblTemperature3.Enabled = True
Me.lblHumidity3.Enabled = True
Me.lblPressure3.Enabled = True

End Sub

Private Sub mnuQuit_Click()


'This Sub is to close the program whenever the user choose the "Quit" option
'from the "File" menu

If MSComm1.PortOpen = True Then


MSComm1.PortOpen = False
End If

If bFileOpen Then
Close #iFile
End If

Unload Me

End Sub

Private Sub mnuNoRate_Click()


'This sub is to disable the Refresh Rate

TimerRefresh.Interval = 0
mnuNoRate.Checked = True
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh10_Click()


'This sub is to refresh the data every 13 ms

Page xlii
If TimerRefresh.Enabled = True Then
TimerRefresh.Interval = 13
mnuNoRate.Checked = False
mnuRefresh10.Checked = True
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End If
End Sub

Private Sub mnuRefresh100_Click()


'This sub is to refresh the data every 100 ms

If TimerRefresh.Enabled = True Then


TimerRefresh.Interval = 100
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = True
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End If
End Sub

Private Sub mnuRefresh500_Click()


'This sub is to refresh the data every 500 ms

If TimerRefresh.Enabled = True Then


TimerRefresh.Interval = 500
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = True
mnuRefresh1000.Checked = False
End If
End Sub

Private Sub mnuRefresh1000_Click()


'This sub is to refresh the data every 1000 ms

If TimerRefresh.Enabled = True Then


TimerRefresh.Interval = 1000
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = True
End If
End Sub

Private Sub TimerRefresh_Timer()


'This Sub is the timer to refresh the data

Displayme
End Sub

Private Sub MSComm1_OnComm()


'This Sub is to receive the data from the serial port

Page xliii
strmydata = MSComm1.Input

strmyarray = Split(strmydata, ",")


intpackagecheck = UBound(strmyarray)

If intpackagecheck > 0 Then

If intnumberofdata < 3 Then

strmydata1 = strmydata1 & strmydata


intnumberofdata = intnumberofdata + 1

End If

If intnumberofdata = 3 Then

strmydata1 = Trim(strmydata1)
strmyarray1 = Split(strmydata1, ",")
intpackagecheck1 = UBound(strmyarray1)
intnumberofdata = 0
Calculatedata
strmydata1 = ""

End If

End If

End Sub

Private Sub Calculatedata()


'This Sub is to decode the values

If intpackagecheck1 > 5 Then

Do While intdatacounter < 6

If strmyarray1(intdatacounter) = "T" Then


dblTemp = Val(strmyarray1(intdatacounter + 1))
End If

If strmyarray1(intdatacounter) = "H" Then


dblHumi = Val(strmyarray1(intdatacounter + 1))
End If

If strmyarray1(intdatacounter) = "P" Then


dblPress = Val(strmyarray1(intdatacounter + 1))
End If

intdatacounter = intdatacounter + 1

Loop

End If

PackSensor
intdatacounter = 0

Page xliv
End Sub

Private Sub PackSensor()


'This sub is to calculate the data from the serial port and change it to
'the sensor values

dblTemp1 = ((dblTemp + 55) * 5) / 1024


dblTemp2 = (dblTemp1 * 10000) / (5 - dblTemp1)
dblTempC = ((dblTemp2 ^ 6) * (10 ^ -27)) - ((dblTemp2 ^ 5) * 6 * (10 ^ -22))
+ ((dblTemp2 ^ 4) * (10 ^ -16)) - ((dblTemp2 ^ 3) * (10 ^ -11)) + ((dblTemp2
^ 2) * 4 * (10 ^ -7)) - (dblTemp2 * 0.0091) + 81.622
dblTempF = ((dblTempC * 9) / 5) + 32
dblHumidity1 = (dblHumi * 5) / 1024
dblHumidityRH = (0.0331 * dblHumidity1 * 1000) - 26.906
dblPressure1 = (dblPress * 5) / 1024
dblPressurePSI = 7.75 * (dblPressure1 - 0.5)
dblPressureAtm = 0.068 * dblPressurePSI

End Sub

Private Sub Displayme()


'This Sub is to display the data into the User Interface

If Me.OptionReal.Value = True Then

cmdGetManualData.Enabled = False

'Real Time
Me.lblTemp1.Enabled = True
Me.txtTemp1.Enabled = True
Me.lblTemperature1.Enabled = True
Me.lblHum1.Enabled = True
Me.txtHum1.Enabled = True
Me.lblHumidity1.Enabled = True
Me.lblPress1.Enabled = True
Me.txtPress1.Enabled = True
Me.lblPressure1.Enabled = True

'Manual Time
Me.lblTemp2.Enabled = False
Me.lblHum2.Enabled = False
Me.lblPress2.Enabled = False
Me.txtTemp2.Enabled = False
Me.txtHum2.Enabled = False
Me.txtPress2.Enabled = False
Me.lblTemperature2.Enabled = False
Me.lblHumidity2.Enabled = False
Me.lblPressure2.Enabled = False
Me.txtTemp2.Text = ""
Me.txtHum2.Text = ""
Me.txtPress2.Text = ""

'Log Output
Me.lblLogTemp.Enabled = False
Me.lblLogHumi.Enabled = False
Me.lblLogPress.Enabled = False

Page xlv
Me.txtTemp3.Enabled = False
Me.txtHum3.Enabled = False
Me.txtPress3.Enabled = False
Me.lblTemperature3.Enabled = False
Me.lblHumidity3.Enabled = False
Me.lblPressure3.Enabled = False

If Me.OptionCelcius.Value = True Then


Me.lblTemperature1.Caption = "deg C"
Me.txtTemp1.Text = FormatNumber(dblTempC, 1)
ElseIf Me.OptionFahrenheit.Value = True Then
Me.lblTemperature1.Caption = "deg F"
Me.txtTemp1.Text = FormatNumber(dblTempF, 1)
End If

Me.txtHum1.Text = FormatNumber(dblHumidityRH, 1)

If Me.OptionPSI.Value = True Then


Me.lblPressure1.Caption = "PSI"
Me.txtPress1.Text = FormatNumber(dblPressurePSI, 1)
ElseIf Me.OptionAtm.Value = True Then
Me.lblPressure1.Caption = "Atm"
Me.txtPress1.Text = FormatNumber(dblPressureAtm, 1)
End If

ElseIf Me.OptionManual.Value = True Then

If bFileOpen = True And bLogManual = True And bLogAutomatic = False Then

cmdGetManualData.Enabled = True

End If

'Real Time
Me.lblTemp1.Enabled = False
Me.txtTemp1.Enabled = False
Me.lblTemperature1.Enabled = False
Me.lblHum1.Enabled = False
Me.txtHum1.Enabled = False
Me.lblHumidity1.Enabled = False
Me.lblPress1.Enabled = False
Me.txtPress1.Enabled = False
Me.lblPressure1.Enabled = False

'Manual Time
Me.lblTemp2.Enabled = True
Me.lblHum2.Enabled = True
Me.lblPress2.Enabled = True
Me.txtTemp2.Enabled = True
Me.txtHum2.Enabled = True
Me.txtPress2.Enabled = True
Me.lblTemperature2.Enabled = True
Me.lblHumidity2.Enabled = True
Me.lblPressure2.Enabled = True

'Log Output
Me.lblLogTemp.Enabled = True

Page xlvi
Me.lblLogHumi.Enabled = True
Me.lblLogPress.Enabled = True
Me.txtTemp3.Enabled = True
Me.txtHum3.Enabled = True
Me.txtPress3.Enabled = True
Me.lblTemperature3.Enabled = True
Me.lblHumidity3.Enabled = True
Me.lblPressure3.Enabled = True

If Me.OptionCelcius.Value = True Then


Me.lblTemperature2.Caption = "deg C"
Me.lblTemperature3.Caption = "deg C"
Me.txtTemp2.Text = FormatNumber(dblTempC, 1)
ElseIf Me.OptionFahrenheit.Value = True Then
Me.lblTemperature2.Caption = "deg F"
Me.lblTemperature3.Caption = "deg F"
Me.txtTemp2.Text = FormatNumber(dblTempF, 1)
End If

Me.txtHum2.Text = FormatNumber(dblHumidityRH, 1)

If Me.OptionPSI.Value = True Then


Me.lblPressure2.Caption = "PSI"
Me.lblPressure3.Caption = "PSI"
Me.txtPress2.Text = FormatNumber(dblPressurePSI, 1)
ElseIf Me.OptionAtm.Value = True Then
Me.lblPressure2.Caption = "Atm"
Me.lblPressure3.Caption = "Atm"
Me.txtPress2.Text = FormatNumber(dblPressureAtm, 1)
End If

End If

HeatBar

End Sub

Private Sub HeatBar()


'This sub is to show the temperature bar

If dblTempC >= -30 And dblTempC < -20 Then


intCountHeat = 0

ElseIf dblTempC >= -20 And dblTempC < -10 Then


intCountHeat = 1

ElseIf dblTempC >= -10 And dblTempC < 0 Then


intCountHeat = 2

ElseIf dblTempC >= 0 And dblTempC < 10 Then


intCountHeat = 3

ElseIf dblTempC >= 10 And dblTempC < 20 Then


intCountHeat = 4

ElseIf dblTempC >= 20 And dblTempC < 30 Then


intCountHeat = 5

Page xlvii
ElseIf dblTempC >= 20 And dblTempC < 30 Then
intCountHeat = 6

ElseIf dblTempC >= 30 And dblTempC < 40 Then


intCountHeat = 7

ElseIf dblTempC >= 40 And dblTempC < 50 Then


intCountHeat = 8

ElseIf dblTempC >= 50 And dblTempC < 60 Then


intCountHeat = 9

ElseIf dblTempC >= 60 And dblTempC < 70 Then


intCountHeat = 10

ElseIf dblTempC >= 70 And dblTempC < 80 Then


intCountHeat = 11

End If

If intCountHeat <> intCountHeat1 Then

Do While intCountHeatLoop < intCountHeat + 1

Me.lblHeat(intCountHeatLoop).Visible = True
intCountHeatLoop = intCountHeatLoop + 1
Loop
intCountHeat1 = intCountHeat

End If

intCountHeatLoop = 0

End Sub

Private Sub cmdGetManualData_Click()


'This Sub is to put the data reading into the log file manually

If bLogManual = True And bLogAutomatic = False And bFileOpen = True And


Me.OptionManual.Value = True Then

If Me.OptionCelcius.Value = True Then


dblManualTemp = FormatNumber(dblTempC, 1)
Me.txtTemp3.Text = FormatNumber(dblTempC, 1)
strManualTempunit = " C"
ElseIf Me.OptionFahrenheit.Value = True Then
dblManualTemp = FormatNumber(dblTempF, 1)
Me.txtTemp3.Text = FormatNumber(dblTempF, 1)
strManualTempunit = " F"
End If

dblManualHumi = FormatNumber(dblHumidityRH, 1)
Me.txtHum3.Text = FormatNumber(dblHumidityRH, 1)
strManualHumiunit = " %RH"

If Me.OptionPSI.Value = True Then

Page xlviii
dblManualPress = FormatNumber(dblPressurePSI, 1)
Me.txtPress3.Text = FormatNumber(dblPressurePSI, 1)
strManualPressunit = " PSI"
ElseIf Me.OptionAtm.Value = True Then
dblManualPress = FormatNumber(dblPressureAtm, 1)
Me.txtPress3.Text = FormatNumber(dblPressureAtm, 1)
strManualPressunit = " Atm"
End If

strLog = Now & "," & "Temperature: " & dblManualTemp & strManualTempunit &
"," & "Humidity: " & dblManualHumi & strManualHumiunit & "," & "Pressure: " &
dblManualPress & strManualPressunit

Print #iFile, strLog

End If

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)


'This Sub is to Check Arrow Keys whenever it pressed down

If bMoveCheck = True Then

If KeyCode = vbKeyUp And bisup = False Then


bisup = True
intx = intx + intxup
End If

If KeyCode = vbKeyDown And bisdown = False Then


bisdown = True
intx = intx + intxdown
End If

If KeyCode = vbKeyLeft And bisleft = False Then


bisleft = True
intx = intx + intxleft
End If

If KeyCode = vbKeyRight And bisright = False Then


bisright = True
intx = intx + intxright
End If

GearTransition

End If

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)


'This Sub is to Check Arrow Keys whenever it pressed up

If bMoveCheck = True Then

If KeyCode = vbKeyUp Then


bisup = False

Page xlix
intx = intx - intxup
End If

If KeyCode = vbKeyDown Then


bisdown = False
intx = intx - intxdown
End If

If KeyCode = vbKeyLeft Then


bisleft = False
intx = intx - intxleft
End If

If KeyCode = vbKeyRight Then


bisright = False
intx = intx - intxright
End If

GearTransition

End If

End Sub

Private Sub GearTransition()


'This Sub is to stop the car briefly whenever it moved from forward to
backward
'or the other way around, so that the motor of the car is not hurt

If (bisup And bisdown) Or intx = 0 Then


Out Val("&H378"), Val(1)
Exit Sub
End If

intGear = intx And 1

If (intGear = 1 And bForward = False) Or (intGear = 0 And bForward = True)


Then
Out Val("&H378"), Val(1)
Outkey
Else
Outkey
End If

End Sub

' From Data Port


' Arrow up = bit 0 high = 1
' Arrow down = bit 1 high = 2
' Arrow left = bit 2 high = 4
' Arrow right = bit 3 high = 8

Private Sub Outkey()


'This Sub is to move the robot using the parallel port

'Straight Forward
If intx = 1 Then

Page l
Out Val("&H378"), Val(13)
bForward = True
Exit Sub
End If

'Forward Left
If intx = 5 Then
Out Val("&H378"), Val(9)
bForward = True
Exit Sub
End If

'Forward Right
If intx = 9 Then
Out Val("&H378"), Val(5)
bForward = True
Exit Sub
End If

'Straight Backward
If intx = 2 Then
Out Val("&H378"), Val(14)
bForward = False
Exit Sub
End If

'Backward Left
If intx = 6 Then
Out Val("&H378"), Val(10)
bForward = False
Exit Sub
End If

'Backward Right
If intx = 10 Then
Out Val("&H378"), Val(6)
bForward = False
Exit Sub
End If

End Sub

Private Sub cmdCircleDuration_Click()


'This Sub is to move the robot without the arrow key by pressing the "Run"
button
'after specifying the duration time

If Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0 And


Me.OptionCircleLeft.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False

Page li
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Out Val("&H378"), Val(9)
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionCircleRight.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Out Val("&H378"), Val(5)
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionStraightForward.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Out Val("&H378"), Val(13)
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionStraightBackward.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Out Val("&H378"), Val(14)
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionBackwardLeft.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False

Page lii
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Out Val("&H378"), Val(10)
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionBackwardRight.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Out Val("&H378"), Val(6)
Me.TimerCircleDuration.Enabled = True

End If

End Sub

Private Sub TimerCircleDuration_Timer()


'This Sub is to stop the car after the specified duration time is over

Out Val("&H378"), Val(1)


Me.TimerCircleDuration.Enabled = False
Me.txtCircleDuration.Enabled = True
Me.OptionDuration.Enabled = True
Me.OptionTurns.Enabled = True
Me.cmdCircleDuration.Enabled = True
Me.cmdCircleTurns.Enabled = False
bMoveCheck = True
intx = 0
End Sub

Private Sub cmdCircleStop_Click()


'This sub is to force the car to stop before the specified duration time is
over

Me.TimerCircleDuration.Enabled = False
Me.TimerCircleTurns.Enabled = False
Out Val("&H378"), Val(1)
If Me.OptionDuration.Value = True Then
Me.txtCircleDuration.Enabled = True
Me.cmdCircleDuration.Enabled = True
ElseIf Me.OptionTurns.Value = True Then
Me.txtCircleTurns.Enabled = True
Me.cmdCircleTurns.Enabled = True
End If
Me.OptionDuration.Enabled = True
Me.OptionTurns.Enabled = True
bMoveCheck = True

End Sub

Page liii
Private Sub VoiceCommand_PhraseFinish(ByVal flags As String, ByVal beginhi As
String, ByVal beginlo As Long, ByVal endhi As Long, ByVal endlo As Long,
ByVal Phrase As String, ByVal parsed As String, ByVal results As Long)
'This Sub is to activate the voice command and move the car by the voice
command

On Error GoTo start:

If Phrase = "Reset" Then


strVoiceCommand = ""

Else
If Phrase <> "" Then
strVoiceCommand = strVoiceCommand & " " & Phrase
End If
End If

strVoiceCommand1 = Trim(strVoiceCommand)

If strVoiceCommand1 = "Enable Box" Then


Me.txtVoice.Visible = True
strVoiceCommand = ""
End If

If strVoiceCommand1 = "Disable Box" Then


Me.txtVoice.Visible = False
strVoiceCommand = ""
End If

If strVoiceCommand1 = "Enable Voice Command" Then


bMoveCheck = False
FrmRobotMovement.Enabled = False
Frame1.Enabled = False
strVoiceCommand = ""
bVoiceCommand = True
End If

If strVoiceCommand1 = "Disable Voice Command" Then


bMoveCheck = True
FrmRobotMovement.Enabled = True
Frame1.Enabled = True
strVoiceCommand = ""
bVoiceCommand = False
End If

If bVoiceCommand = True Then

If strVoiceCommand1 = "Straight Forward" Then


Out Val("&H378"), Val(13)
strVoiceCommand = ""
End If

If strVoiceCommand1 = "Forward Left" Then


Out Val("&H378"), Val(9)
strVoiceCommand = ""
End If

Page liv
If strVoiceCommand1 = "Forward Right" Then
Out Val("&H378"), Val(5)
strVoiceCommand = ""
End If

If strVoiceCommand1 = "Straight Backward" Then


Out Val("&H378"), Val(14)
strVoiceCommand = ""
End If

If strVoiceCommand1 = "Backward Left" Then


Out Val("&H378"), Val(10)
strVoiceCommand = ""
End If

If strVoiceCommand1 = "Backward Right" Then


Out Val("&H378"), Val(6)
strVoiceCommand = ""
End If

If strVoiceCommand1 = "Stop" Then


Out Val("&H378"), Val(1)
strVoiceCommand = ""
End If

End If

Me.txtVoice.Text = strVoiceCommand1

start:
If Err.Number <> 0 Then
MsgBox ("Error " & Err.Number & " , " & Err.Description)
End If
End Sub

Page lv
APPENDIX E – SARR SERVER CODE (VISUAL BASIC)
Option Explicit

'For the output window


Dim dblTemp As Double, dblPress As Double, dblHumi As Double
Dim dblTemp1 As Double, dblTemp2 As Double, dblTempC As Double, dblTempF As
Double
Dim dblHumidity1 As Double, dblHumidityRH As Double
Dim dblPressure1 As Double, dblPressurePSI As Double, dblPressureAtm As
Double
Dim strmydata As String, strmydata1 As String
Dim strmyarray() As String, strmyarray1() As String
Dim intnumberofdata As Integer, intdatacounter As Integer
Dim intpackagecheck As Integer, intpackagecheck1 As Integer
Dim dblManualTemp As Double, dblManualHumi As Double, dblManualPress As
Double
Dim strManualTempunit As String, strManualHumiunit As String,
strManualPressunit As String
Dim strLog As String
Dim bLogManual As Boolean, bLogAutomatic As Boolean, bFileOpen As Boolean
Dim iFile As Integer

'For the server part


Dim Msgfromclient() As String
Dim Usera As String, Passa As String, msg As String
Dim Msgarray As Integer, Checkuserpass As Integer
Dim bConnection As Boolean

Private Sub Form_Load()

Out Val("&H378"), Val(1)


MSComm1.CommPort = 1

If MSComm1.PortOpen = True Then


MSComm1.PortOpen = False
End If

MSComm1.Settings = "19200,N,8,1"
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.InputLen = 0

TimerRefresh.Enabled = False
TimerLog.Enabled = False
cmdGetManualData.Enabled = False
strmydata = ""
msg = ""

bConnection = False
bLogManual = False
bFileOpen = False
bLogAutomatic = False

Me.Height = Screen.Height

Page lvi
Me.Move 0, 0

Me.OptionCelcius.Value = True
Me.OptionReal.Value = True
Me.KeyPreview = True

Usera = "caesar"
Passa = "caesar"
Checkuserpass = 0

tcpServer.LocalPort = 3456
tcpServer.Listen

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

ClosePort
tcpServer.Close
msg = ""
Unload Form2
Unload Form3
Unload Form5

End Sub

Private Sub mnuAbout_Click()


Form3.Show
End Sub

Private Sub mnuCreateFile_Click()

If bFileOpen Then
Close #iFile
End If

On Error Resume Next


Me.CommonDialog1.InitDir = App.Path
Me.CommonDialog1.DefaultExt = ".log"
Me.CommonDialog1.FileName = "Log1.log"
Me.CommonDialog1.Filter = "Log File (*.log)|*.log|All Files (*.*)|*.*"
Me.CommonDialog1.FilterIndex = 0
Me.CommonDialog1.CancelError = True
Me.CommonDialog1.ShowSave

If Err.Number = 0 Then
If Len(Me.CommonDialog1.FileName) > 0 Then

iFile = FreeFile
Open Me.CommonDialog1.FileName For Output As #iFile
bFileOpen = True
End If
Else
Err.Clear
End If
On Error GoTo 0

Page lvii
End Sub

Private Sub mnuManualStartLog_Click()

If bFileOpen = True Then


bLogManual = True
bLogAutomatic = False
TimerLog.Enabled = False
Me.OptionManual.Value = True

End If

End Sub

Private Sub mnuStopLog_Click()

TimerLog.Enabled = False

If bLogManual = True Then


bLogManual = False
End If

If bLogAutomatic = True Then


bLogAutomatic = False
End If

End Sub

Private Sub mnuLog10ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 10
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = True
mnuLog100ms.Checked = False
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog100ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 100
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False
mnuLog100ms.Checked = True

Page lviii
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog500ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 500
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False
mnuLog100ms.Checked = False
mnuLog500ms.Checked = True
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog1000ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 1000
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False
mnuLog100ms.Checked = False
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = True

End If

End Sub

Private Sub mnuTutorial_Click()


Form5.Show
End Sub

Private Sub TimerLog_Timer()

If bLogManual = False And bLogAutomatic = True And bFileOpen = True Then

If Me.OptionCelcius.Value = True Then


dblManualTemp = FormatNumber(dblTempC, 3)
strManualTempunit = " C"
ElseIf Me.OptionFahrenheit.Value = True Then
dblManualTemp = FormatNumber(dblTempF, 3)
strManualTempunit = " F"

Page lix
End If

dblManualHumi = FormatNumber(dblHumidityRH, 3)
strManualHumiunit = " %RH"

If Me.OptionPSI.Value = True Then


dblManualPress = FormatNumber(dblPressurePSI, 3)
strManualPressunit = " PSI"
ElseIf Me.OptionAtm.Value = True Then
dblManualPress = FormatNumber(dblPressureAtm, 3)
strManualPressunit = " Atm"
End If

strLog = Now & "," & "Temperature: " & dblManualTemp & strManualTempunit &
"," & "Humidity: " & dblManualHumi & strManualHumiunit & "," & "Pressure: " &
dblManualPress & strManualPressunit

Print #iFile, strLog

End If

End Sub

Private Sub OpenPort()

If MSComm1.PortOpen = False Then


MSComm1.PortOpen = True
End If

TimerRefresh.Enabled = True
TimerSendClient.Enabled = True

End Sub

Private Sub ClosePort()

TimerSendClient.Enabled = False

If MSComm1.PortOpen = True Then


MSComm1.PortOpen = False
End If

If bFileOpen Then
Close #iFile
End If

TimerRefresh.Enabled = False
TimerLog.Enabled = False

'Real Time
Me.lblTemp1.Enabled = True
Me.txtTemp1.Enabled = True
Me.txtTemp1.Text = ""
Me.lblTemperature1.Enabled = True
Me.lblHum1.Enabled = True
Me.txtHum1.Enabled = True
Me.txtHum1.Text = ""

Page lx
Me.lblHumidity1.Enabled = True
Me.lblPress1.Enabled = True
Me.txtPress1.Enabled = True
Me.txtPress1.Text = ""
Me.lblPressure1.Enabled = True

'Manual Time
Me.lblTemp2.Enabled = True
Me.lblHum2.Enabled = True
Me.lblPress2.Enabled = True
Me.txtTemp2.Enabled = True
Me.txtTemp2.Text = ""
Me.txtHum2.Enabled = True
Me.txtHum2.Text = ""
Me.txtPress2.Enabled = True
Me.txtPress2.Text = ""
Me.lblTemperature2.Enabled = True
Me.lblHumidity2.Enabled = True
Me.lblPressure2.Enabled = True

'Log Output
Me.lblLogTemp.Enabled = True
Me.lblLogHumi.Enabled = True
Me.lblLogPress.Enabled = True
Me.txtTemp3.Enabled = True
Me.txtTemp3.Text = ""
Me.txtHum3.Enabled = True
Me.txtHum3.Text = ""
Me.txtPress3.Enabled = True
Me.txtPress3.Text = ""
Me.lblTemperature3.Enabled = True
Me.lblHumidity3.Enabled = True
Me.lblPressure3.Enabled = True

End Sub

Private Sub mnuQuit_Click()

'ClosePort
Unload Me

End Sub

Private Sub mnuNoRate_Click()

TimerRefresh.Enabled = False
mnuNoRate.Checked = True
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh10_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 13
mnuNoRate.Checked = False

Page lxi
mnuRefresh10.Checked = True
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh100_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 100
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = True
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh500_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 500
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = True
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh1000_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 1000
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = True
End Sub

Private Sub TimerRefresh_Timer()

Displayme

End Sub

Private Sub MSComm1_OnComm()

strmydata = MSComm1.Input

strmyarray = Split(strmydata, ",")


intpackagecheck = UBound(strmyarray)

If intpackagecheck > 0 Then

If intnumberofdata < 3 Then

strmydata1 = strmydata1 & strmydata


intnumberofdata = intnumberofdata + 1

End If

Page lxii
If intnumberofdata = 3 Then

strmydata1 = Trim(strmydata1)
strmyarray1 = Split(strmydata1, ",")
intpackagecheck1 = UBound(strmyarray1)
Calculatedata
intnumberofdata = 0
strmydata1 = ""

End If

End If

End Sub

Private Sub Calculatedata()

If intpackagecheck1 > 5 Then

Do While intdatacounter < 6

If strmyarray1(intdatacounter) = "T" Then


dblTemp = Val(strmyarray1(intdatacounter + 1))
End If

If strmyarray1(intdatacounter) = "H" Then


dblHumi = Val(strmyarray1(intdatacounter + 1))
End If

If strmyarray1(intdatacounter) = "P" Then


dblPress = Val(strmyarray1(intdatacounter + 1))
End If

intdatacounter = intdatacounter + 1

Loop

End If

PackSensor
intdatacounter = 0

End Sub

Private Sub PackSensor()

dblTemp1 = ((dblTemp + 55) * 5) / 1024


dblTemp2 = (dblTemp1 * 10000) / (5 - dblTemp1)
dblTempC = ((dblTemp2 ^ 6) * (10 ^ -27)) - ((dblTemp2 ^ 5) * 6 * (10 ^ -22))
+ ((dblTemp2 ^ 4) * (10 ^ -16)) - ((dblTemp2 ^ 3) * (10 ^ -11)) + ((dblTemp2
^ 2) * 4 * (10 ^ -7)) - (dblTemp2 * 0.0091) + 81.622
dblTempF = ((dblTempC * 9) / 5) + 32
dblHumidity1 = (dblHumi * 5) / 1024
dblHumidityRH = (0.0331 * dblHumidity1 * 1000) - 26.906
dblPressure1 = (dblPress * 5) / 1024

Page lxiii
dblPressurePSI = 7.5 * (dblPressure1 - 0.5)
dblPressureAtm = 0.068 * dblPressurePSI

End Sub

Private Sub Displayme()

If Me.OptionReal.Value = True Then

cmdGetManualData.Enabled = False

'Real Time
Me.lblTemp1.Enabled = True
Me.txtTemp1.Enabled = True
Me.lblTemperature1.Enabled = True
Me.lblHum1.Enabled = True
Me.txtHum1.Enabled = True
Me.lblHumidity1.Enabled = True
Me.lblPress1.Enabled = True
Me.txtPress1.Enabled = True
Me.lblPressure1.Enabled = True

'Manual Time
Me.lblTemp2.Enabled = False
Me.lblHum2.Enabled = False
Me.lblPress2.Enabled = False
Me.txtTemp2.Enabled = False
Me.txtHum2.Enabled = False
Me.txtPress2.Enabled = False
Me.lblTemperature2.Enabled = False
Me.lblHumidity2.Enabled = False
Me.lblPressure2.Enabled = False
Me.txtTemp2.Text = ""
Me.txtHum2.Text = ""
Me.txtPress2.Text = ""

'Log Output
Me.lblLogTemp.Enabled = False
Me.lblLogHumi.Enabled = False
Me.lblLogPress.Enabled = False
Me.txtTemp3.Enabled = False
Me.txtHum3.Enabled = False
Me.txtPress3.Enabled = False
Me.lblTemperature3.Enabled = False
Me.lblHumidity3.Enabled = False
Me.lblPressure3.Enabled = False

If Me.OptionCelcius.Value = True Then


Me.lblTemperature1.Caption = "deg C"
Me.txtTemp1.Text = FormatNumber(dblTempC, 1)
ElseIf Me.OptionFahrenheit.Value = True Then
Me.lblTemperature1.Caption = "deg F"
Me.txtTemp1.Text = FormatNumber(dblTempF, 1)
End If

Me.txtHum1.Text = FormatNumber(dblHumidityRH, 1)

Page lxiv
If Me.OptionPSI.Value = True Then
Me.lblPressure1.Caption = "PSI"
Me.txtPress1.Text = FormatNumber(dblPressurePSI, 1)
ElseIf Me.OptionAtm.Value = True Then
Me.lblPressure1.Caption = "Atm"
Me.txtPress1.Text = FormatNumber(dblPressureAtm, 1)
End If

ElseIf Me.OptionManual.Value = True Then

If bFileOpen = True And bLogManual = True And bLogAutomatic = False Then

cmdGetManualData.Enabled = True

End If

'Real Time
Me.lblTemp1.Enabled = False
Me.txtTemp1.Enabled = False
Me.lblTemperature1.Enabled = False
Me.lblHum1.Enabled = False
Me.txtHum1.Enabled = False
Me.lblHumidity1.Enabled = False
Me.lblPress1.Enabled = False
Me.txtPress1.Enabled = False
Me.lblPressure1.Enabled = False

'Manual Time
Me.lblTemp2.Enabled = True
Me.lblHum2.Enabled = True
Me.lblPress2.Enabled = True
Me.txtTemp2.Enabled = True
Me.txtHum2.Enabled = True
Me.txtPress2.Enabled = True
Me.lblTemperature2.Enabled = True
Me.lblHumidity2.Enabled = True
Me.lblPressure2.Enabled = True

'Log Output
Me.lblLogTemp.Enabled = True
Me.lblLogHumi.Enabled = True
Me.lblLogPress.Enabled = True
Me.txtTemp3.Enabled = True
Me.txtHum3.Enabled = True
Me.txtPress3.Enabled = True
Me.lblTemperature3.Enabled = True
Me.lblHumidity3.Enabled = True
Me.lblPressure3.Enabled = True

If Me.OptionCelcius.Value = True Then


Me.lblTemperature2.Caption = "deg C"
Me.lblTemperature3.Caption = "deg C"
Me.txtTemp2.Text = FormatNumber(dblTempC, 1)
ElseIf Me.OptionFahrenheit.Value = True Then
Me.lblTemperature2.Caption = "deg F"
Me.lblTemperature3.Caption = "deg F"
Me.txtTemp2.Text = FormatNumber(dblTempF, 1)

Page lxv
End If

Me.txtHum2.Text = FormatNumber(dblHumidityRH, 1)

If Me.OptionPSI.Value = True Then


Me.lblPressure2.Caption = "PSI"
Me.lblPressure3.Caption = "PSI"
Me.txtPress2.Text = FormatNumber(dblPressurePSI, 1)
ElseIf Me.OptionAtm.Value = True Then
Me.lblPressure2.Caption = "Atm"
Me.lblPressure3.Caption = "Atm"
Me.txtPress2.Text = FormatNumber(dblPressureAtm, 1)
End If

End If

End Sub

Private Sub cmdGetManualData_Click()

If bLogManual = True And bLogAutomatic = False And bFileOpen = True And


Me.OptionManual.Value = True Then

If Me.OptionCelcius.Value = True Then


dblManualTemp = FormatNumber(dblTempC, 3)
Me.txtTemp3.Text = FormatNumber(dblTempC, 3)
strManualTempunit = " C"
ElseIf Me.OptionFahrenheit.Value = True Then
dblManualTemp = FormatNumber(dblTempF, 3)
Me.txtTemp3.Text = FormatNumber(dblTempF, 3)
strManualTempunit = " F"
End If

dblManualHumi = FormatNumber(dblHumidityRH, 3)
Me.txtHum3.Text = FormatNumber(dblHumidityRH, 3)
strManualHumiunit = " %RH"

If Me.OptionPSI.Value = True Then


dblManualPress = FormatNumber(dblPressurePSI, 3)
Me.txtPress3.Text = FormatNumber(dblPressurePSI, 3)
strManualPressunit = " PSI"
ElseIf Me.OptionAtm.Value = True Then
dblManualPress = FormatNumber(dblPressureAtm, 3)
Me.txtPress3.Text = FormatNumber(dblPressureAtm, 3)
strManualPressunit = " Atm"
End If

strLog = Now & "," & "Temperature: " & dblManualTemp & strManualTempunit &
"," & "Humidity: " & dblManualHumi & strManualHumiunit & "," & "Pressure: " &
dblManualPress & strManualPressunit

Print #iFile, strLog

End If

End Sub

Page lxvi
Private Sub tcpServer_Close()
bConnection = False
ClosePort
tcpServer.Close
msg = ""
Checkuserpass = 0
tcpServer.Listen
End Sub

Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)


If tcpServer.State <> sckClosed Then
tcpServer.Close
End If
tcpServer.Accept requestID

End Sub

Private Sub tcpServer_Error(ByVal Number As Integer, Description As String,


ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
'MsgBox Source & ": " & Description, vbExclamation, "TCP/IP Error"
bConnection = False
End Sub

Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)

tcpServer.GetData msg

Msgfromclient = Split(msg, ",")


Msgarray = UBound(Msgfromclient)

If Msgarray > 0 And Checkuserpass = 0 Then

If Msgfromclient(0) = Usera And Msgfromclient(1) = Passa Then


Checkuserpass = 1
tcpServer.SendData "Password,Accepted"
OpenPort
bConnection = True
msg = ""
Else
Checkuserpass = 0
tcpServer.SendData "Invalid,Login"
msg = ""
End If

End If

If Checkuserpass = 1 And Msgarray = 0 Then

Movetherobot

End If

End Sub

Private Sub Movetherobot()

Page lxvii
If Msgfromclient(0) = "Stop" Then
Out Val("&H378"), Val(1)
End If
If Msgfromclient(0) = "StraightForward" Then
Out Val("&H378"), Val(13)
End If
If Msgfromclient(0) = "ForwardLeft" Then
Out Val("&H378"), Val(9)
End If
If Msgfromclient(0) = "ForwardRight" Then
Out Val("&H378"), Val(5)
End If
If Msgfromclient(0) = "StraightBackward" Then
Out Val("&H378"), Val(14)
End If
If Msgfromclient(0) = "BackwardLeft" Then
Out Val("&H378"), Val(10)
End If
If Msgfromclient(0) = "BackwardRight" Then
Out Val("&H378"), Val(6)
End If

End Sub

Private Sub TimerSendClient_Timer()

If bConnection = True Then


tcpServer.SendData "Temperature" & "," & dblTemp2 & "," & "Humidity" & "," &
dblHumidity1 & "," & "Pressure" & "," & dblPressure1 & ","
End If

End Sub

Page lxviii
Page lxix
APPENDIX F – SARR CLIENT CODE (VISUAL BASIC)
Option Explicit

Dim dblTemp2 As Double, dblTempC As Double, dblTempF As Double


Dim dblHumidity1 As Double, dblHumidityRH As Double
Dim dblPressure1 As Double, dblPressurePSI As Double, dblPressureAtm As
Double
Dim intMsgarray As Integer, intdatacounter As Integer
Dim dblManualTemp As Double, dblManualHumi As Double, dblManualPress As
Double
Dim strManualTempunit As String, strManualHumiunit As String,
strManualPressunit As String
Dim strLog As String
Dim bLogManual As Boolean, bLogAutomatic As Boolean, bFileOpen As Boolean
Dim iFile As Integer, CheckUserPassword As Integer
Dim msg As String, strMsgfromserver() As String, strMsg1 As String, strMsg2
As String
Dim strMsg2array() As String
Dim bisup As Boolean, bisdown As Boolean, bisleft As Boolean, bisright As
Boolean
Dim intx As Integer, intxup As Integer, intxdown As Integer
Dim intGear As Integer, intxleft As Integer, intxright As Integer
Dim intCountHeat As Integer, intCountHeat1 As Integer, intCountHeatLoop As
Integer
Dim bForward As Boolean, bMoveCheck As Boolean

Private Sub Form_Load()

Me.mnuRelogin.Visible = False
Me.mnuRelogin1.Visible = False
Me.mnuCloseConnection.Visible = False
Me.mnuCloseConnection1.Visible = False

TimerRefresh.Enabled = False
TimerLog.Enabled = False
cmdGetManualData.Enabled = False
intdatacounter = 0

bLogManual = False
bFileOpen = False
bLogAutomatic = False

strMsg1 = ""

bForward = True
bMoveCheck = True
bisup = False
bisdown = False
bisleft = False
bisright = False
intx = 0
intxup = 1
intxdown = 2
intxleft = 4

Page lxx
intxright = 8

intCountHeat = 0
intCountHeat1 = 100
intCountHeatLoop = 0

CheckUserPassword = 0

'Me.Width = 3270
Me.Height = Screen.Height
Me.Move 0, 0
Me.OptionCelcius.Value = True
Me.OptionReal.Value = True
Me.KeyPreview = True

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)


ClosePort
Unload Form2
Unload Form3
Unload Form5
End Sub

Private Sub mnuTutorial_Click()


Form5.Show
End Sub

Private Sub mnuAbout_Click()


Form3.Show
End Sub

Private Sub mnuCreateFile_Click()

If bFileOpen Then
Close #iFile
End If

On Error Resume Next


Me.CommonDialog1.InitDir = App.Path
Me.CommonDialog1.DefaultExt = ".log"
Me.CommonDialog1.FileName = "Log1.log"
Me.CommonDialog1.Filter = "Log File (*.log)|*.log|All Files (*.*)|*.*"
Me.CommonDialog1.FilterIndex = 0
Me.CommonDialog1.CancelError = True
Me.CommonDialog1.ShowSave

If Err.Number = 0 Then
If Len(Me.CommonDialog1.FileName) > 0 Then

iFile = FreeFile
Open Me.CommonDialog1.FileName For Output As #iFile
bFileOpen = True
End If
Else
Err.Clear
End If

Page lxxi
On Error GoTo 0

End Sub

Private Sub mnuManualStartLog_Click()

If bFileOpen = True Then


bLogManual = True
bLogAutomatic = False
TimerLog.Enabled = False
Me.OptionManual.Value = True

End If

End Sub

Private Sub mnuStopLog_Click()

TimerLog.Enabled = False

If bLogManual = True Then


bLogManual = False
End If

If bLogAutomatic = True Then


bLogAutomatic = False
End If

End Sub

Private Sub mnuLog10ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 10
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = True
mnuLog100ms.Checked = False
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog100ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 100
cmdGetManualData.Enabled = False

Page lxxii
mnuLog10ms.Checked = False
mnuLog100ms.Checked = True
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog500ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 500
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False
mnuLog100ms.Checked = False
mnuLog500ms.Checked = True
mnuLog1000ms.Checked = False

End If

End Sub

Private Sub mnuLog1000ms_Click()

If bFileOpen = True Then

bLogManual = False
bLogAutomatic = True
TimerLog.Enabled = True
TimerLog.Interval = 1000
cmdGetManualData.Enabled = False
mnuLog10ms.Checked = False
mnuLog100ms.Checked = False
mnuLog500ms.Checked = False
mnuLog1000ms.Checked = True

End If

End Sub

Private Sub TimerLog_Timer()

If bLogManual = False And bLogAutomatic = True And bFileOpen = True Then

If Me.OptionCelcius.Value = True Then


dblManualTemp = FormatNumber(dblTempC, 3)
strManualTempunit = " C"
ElseIf Me.OptionFahrenheit.Value = True Then
dblManualTemp = FormatNumber(dblTempF, 3)
strManualTempunit = " F"
End If

Page lxxiii
dblManualHumi = FormatNumber(dblHumidityRH, 3)
strManualHumiunit = " %RH"

If Me.OptionPSI.Value = True Then


dblManualPress = FormatNumber(dblPressurePSI, 3)
strManualPressunit = " PSI"
ElseIf Me.OptionAtm.Value = True Then
dblManualPress = FormatNumber(dblPressureAtm, 3)
strManualPressunit = " Atm"
End If

strLog = Now & "," & "Temperature: " & dblManualTemp & strManualTempunit &
"," & "Humidity: " & dblManualHumi & strManualHumiunit & "," & "Pressure: " &
dblManualPress & strManualPressunit

Print #iFile, strLog

End If

End Sub

Private Sub mnuRelogin_Click()

Me.mnuRelogin.Visible = False
Me.mnuRelogin1.Visible = False
Me.mnuCloseConnection.Visible = False
Me.mnuCloseConnection1.Visible = False
Me.FrameOutput.Visible = False
Me.FrameServerLogin.Visible = True
Me.tcpClient.Close
CheckUserPassword = 0
msg = ""
strMsg1 = ""

End Sub

Private Sub mnuCloseConnection_Click()

ClosePort

'Real Time
Me.lblTemp1.Enabled = True
Me.txtTemp1.Enabled = True
Me.txtTemp1.Text = ""
Me.lblTemperature1.Enabled = True
Me.lblHum1.Enabled = True
Me.txtHum1.Enabled = True
Me.txtHum1.Text = ""
Me.lblHumidity1.Enabled = True
Me.lblPress1.Enabled = True
Me.txtPress1.Enabled = True
Me.txtPress1.Text = ""
Me.lblPressure1.Enabled = True

'Manual Time
Me.lblTemp2.Enabled = True
Me.lblHum2.Enabled = True

Page lxxiv
Me.lblPress2.Enabled = True
Me.txtTemp2.Enabled = True
Me.txtTemp2.Text = ""
Me.txtHum2.Enabled = True
Me.txtHum2.Text = ""
Me.txtPress2.Enabled = True
Me.txtPress2.Text = ""
Me.lblTemperature2.Enabled = True
Me.lblHumidity2.Enabled = True
Me.lblPressure2.Enabled = True

'Log Output
Me.lblLogTemp.Enabled = True
Me.lblLogHumi.Enabled = True
Me.lblLogPress.Enabled = True
Me.txtTemp3.Enabled = True
Me.txtTemp3.Text = ""
Me.txtHum3.Enabled = True
Me.txtHum3.Text = ""
Me.txtPress3.Enabled = True
Me.txtPress3.Text = ""
Me.lblTemperature3.Enabled = True
Me.lblHumidity3.Enabled = True
Me.lblPressure3.Enabled = True

End Sub

Private Sub mnuQuit_Click()


Unload Me
End Sub

Private Sub ClosePort()

tcpClient.Close
TimerRefresh.Enabled = False
TimerLog.Enabled = False

If bFileOpen Then
Close #iFile
End If

End Sub

Private Sub mnuNoRate_Click()


TimerRefresh.Enabled = False
mnuNoRate.Checked = True
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh10_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 13
mnuNoRate.Checked = False
mnuRefresh10.Checked = True

Page lxxv
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh100_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 100
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = True
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh500_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 500
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = True
mnuRefresh1000.Checked = False
End Sub

Private Sub mnuRefresh1000_Click()


TimerRefresh.Enabled = True
TimerRefresh.Interval = 1000
mnuNoRate.Checked = False
mnuRefresh10.Checked = False
mnuRefresh100.Checked = False
mnuRefresh500.Checked = False
mnuRefresh1000.Checked = True
End Sub

Private Sub PackSensor()

dblTempC = ((dblTemp2 ^ 6) * (10 ^ -27)) - ((dblTemp2 ^ 5) * 6 * (10 ^ -22))


+ ((dblTemp2 ^ 4) * (10 ^ -16)) - ((dblTemp2 ^ 3) * (10 ^ -11)) + ((dblTemp2
^ 2) * 4 * (10 ^ -7)) - (dblTemp2 * 0.0091) + 81.622
dblTempF = ((dblTempC * 9) / 5) + 32
dblHumidityRH = (0.0331 * dblHumidity1 * 1000) - 26.906
dblPressurePSI = 7.5 * (dblPressure1 - 0.5)
dblPressureAtm = 0.068 * dblPressurePSI

End Sub

Private Sub TimerRefresh_Timer()


Displayme
End Sub

Private Sub Displayme()

If Me.OptionReal.Value = True Then

cmdGetManualData.Enabled = False

Page lxxvi
'Real Time
Me.lblTemp1.Enabled = True
Me.txtTemp1.Enabled = True
Me.lblTemperature1.Enabled = True
Me.lblHum1.Enabled = True
Me.txtHum1.Enabled = True
Me.lblHumidity1.Enabled = True
Me.lblPress1.Enabled = True
Me.txtPress1.Enabled = True
Me.lblPressure1.Enabled = True

'Manual Time
Me.lblTemp2.Enabled = False
Me.lblHum2.Enabled = False
Me.lblPress2.Enabled = False
Me.txtTemp2.Enabled = False
Me.txtHum2.Enabled = False
Me.txtPress2.Enabled = False
Me.lblTemperature2.Enabled = False
Me.lblHumidity2.Enabled = False
Me.lblPressure2.Enabled = False
Me.txtTemp2.Text = ""
Me.txtHum2.Text = ""
Me.txtPress2.Text = ""

'Log Output
Me.lblLogTemp.Enabled = False
Me.lblLogHumi.Enabled = False
Me.lblLogPress.Enabled = False
Me.txtTemp3.Enabled = False
Me.txtHum3.Enabled = False
Me.txtPress3.Enabled = False
Me.lblTemperature3.Enabled = False
Me.lblHumidity3.Enabled = False
Me.lblPressure3.Enabled = False

If Me.OptionCelcius.Value = True Then


Me.lblTemperature1.Caption = "deg C"
Me.txtTemp1.Text = FormatNumber(dblTempC, 1)
ElseIf Me.OptionFahrenheit.Value = True Then
Me.lblTemperature1.Caption = "deg F"
Me.txtTemp1.Text = FormatNumber(dblTempF, 1)
End If

Me.txtHum1.Text = FormatNumber(dblHumidityRH, 1)

If Me.OptionPSI.Value = True Then


Me.lblPressure1.Caption = "PSI"
Me.txtPress1.Text = FormatNumber(dblPressurePSI, 1)
ElseIf Me.OptionAtm.Value = True Then
Me.lblPressure1.Caption = "Atm"
Me.txtPress1.Text = FormatNumber(dblPressureAtm, 1)
End If

ElseIf Me.OptionManual.Value = True Then

If bFileOpen = True And bLogManual = True And bLogAutomatic = False Then

Page lxxvii
cmdGetManualData.Enabled = True

End If

'Real Time
Me.lblTemp1.Enabled = False
Me.txtTemp1.Enabled = False
Me.lblTemperature1.Enabled = False
Me.lblHum1.Enabled = False
Me.txtHum1.Enabled = False
Me.lblHumidity1.Enabled = False
Me.lblPress1.Enabled = False
Me.txtPress1.Enabled = False
Me.lblPressure1.Enabled = False

'Manual Time
Me.lblTemp2.Enabled = True
Me.lblHum2.Enabled = True
Me.lblPress2.Enabled = True
Me.txtTemp2.Enabled = True
Me.txtHum2.Enabled = True
Me.txtPress2.Enabled = True
Me.lblTemperature2.Enabled = True
Me.lblHumidity2.Enabled = True
Me.lblPressure2.Enabled = True

'Log Output
Me.lblLogTemp.Enabled = True
Me.lblLogHumi.Enabled = True
Me.lblLogPress.Enabled = True
Me.txtTemp3.Enabled = True
Me.txtHum3.Enabled = True
Me.txtPress3.Enabled = True
Me.lblTemperature3.Enabled = True
Me.lblHumidity3.Enabled = True
Me.lblPressure3.Enabled = True

If Me.OptionCelcius.Value = True Then


Me.lblTemperature2.Caption = "deg C"
Me.lblTemperature3.Caption = "deg C"
Me.txtTemp2.Text = FormatNumber(dblTempC, 1)
ElseIf Me.OptionFahrenheit.Value = True Then
Me.lblTemperature2.Caption = "deg F"
Me.lblTemperature3.Caption = "deg F"
Me.txtTemp2.Text = FormatNumber(dblTempF, 1)
End If

Me.txtHum2.Text = FormatNumber(dblHumidityRH, 1)

If Me.OptionPSI.Value = True Then


Me.lblPressure2.Caption = "PSI"
Me.lblPressure3.Caption = "PSI"
Me.txtPress2.Text = FormatNumber(dblPressurePSI, 1)
ElseIf Me.OptionAtm.Value = True Then
Me.lblPressure2.Caption = "Atm"
Me.lblPressure3.Caption = "Atm"

Page lxxviii
Me.txtPress2.Text = FormatNumber(dblPressureAtm, 1)
End If

End If

HeatBar

End Sub

Private Sub HeatBar()

If dblTempC >= -30 And dblTempC < -20 Then


intCountHeat = 0

ElseIf dblTempC >= -20 And dblTempC < -10 Then


intCountHeat = 1

ElseIf dblTempC >= -10 And dblTempC < 0 Then


intCountHeat = 2

ElseIf dblTempC >= 0 And dblTempC < 10 Then


intCountHeat = 3

ElseIf dblTempC >= 10 And dblTempC < 20 Then


intCountHeat = 4

ElseIf dblTempC >= 20 And dblTempC < 30 Then


intCountHeat = 5

ElseIf dblTempC >= 20 And dblTempC < 30 Then


intCountHeat = 6

ElseIf dblTempC >= 30 And dblTempC < 40 Then


intCountHeat = 7

ElseIf dblTempC >= 40 And dblTempC < 50 Then


intCountHeat = 8

ElseIf dblTempC >= 50 And dblTempC < 60 Then


intCountHeat = 9

ElseIf dblTempC >= 60 And dblTempC < 70 Then


intCountHeat = 10

ElseIf dblTempC >= 70 And dblTempC < 80 Then


intCountHeat = 11

End If

If intCountHeat <> intCountHeat1 Then

Do While intCountHeatLoop < intCountHeat + 1

Me.lblHeat(intCountHeatLoop).Visible = True
intCountHeatLoop = intCountHeatLoop + 1
Loop
intCountHeat1 = intCountHeat

Page lxxix
End If

intCountHeatLoop = 0

End Sub

Private Sub cmdGetManualData_Click()

If bLogManual = True And bLogAutomatic = False And bFileOpen = True And


Me.OptionManual.Value = True Then

If Me.OptionCelcius.Value = True Then


dblManualTemp = FormatNumber(dblTempC, 3)
Me.txtTemp3.Text = FormatNumber(dblTempC, 3)
strManualTempunit = " C"
ElseIf Me.OptionFahrenheit.Value = True Then
dblManualTemp = FormatNumber(dblTempF, 3)
Me.txtTemp3.Text = FormatNumber(dblTempF, 3)
strManualTempunit = " F"
End If

dblManualHumi = FormatNumber(dblHumidityRH, 3)
Me.txtHum3.Text = FormatNumber(dblHumidityRH, 3)
strManualHumiunit = " %RH"

If Me.OptionPSI.Value = True Then


dblManualPress = FormatNumber(dblPressurePSI, 3)
Me.txtPress3.Text = FormatNumber(dblPressurePSI, 3)
strManualPressunit = " PSI"
ElseIf Me.OptionAtm.Value = True Then
dblManualPress = FormatNumber(dblPressureAtm, 3)
Me.txtPress3.Text = FormatNumber(dblPressureAtm, 3)
strManualPressunit = " Atm"
End If

strLog = Now & "," & "Temperature: " & dblManualTemp & strManualTempunit &
"," & "Humidity: " & dblManualHumi & strManualHumiunit & "," & "Pressure: " &
dblManualPress & strManualPressunit

Print #iFile, strLog

End If

End Sub

Private Sub cmdLogin_Click()

Me.mnuRelogin.Visible = True
Me.mnuRelogin1.Visible = True
Me.mnuCloseConnection.Visible = True
Me.mnuCloseConnection1.Visible = True

tcpClient.RemoteHost = Me.txtIPaddress.Text
If tcpClient.RemoteHost = "" Then
tcpClient.RemoteHost = "localhost"
End If

Page lxxx
tcpClient.RemotePort = 3456
tcpClient.Connect

End Sub

Private Sub tcpClient_Close()


CheckUserPassword = 0
ClosePort
strMsg1 = ""
msg = ""
End Sub

Private Sub tcpClient_Connect()


tcpClient.SendData Me.txtServerUserName.Text & "," &
Me.txtServerPassword.Text
End Sub

Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)

tcpClient.GetData msg
strMsg1 = msg & strMsg1
strMsgfromserver = Split(strMsg1, ",")
intMsgarray = UBound(strMsgfromserver)

If CheckUserPassword = 0 And intMsgarray = 1 Then

If strMsgfromserver(0) = "Invalid" And strMsgfromserver(1) = "Login" Then


tcpClient.Close
CheckUserPassword = 0
Me.FrameServerLogin.Visible = True
Me.FrameOutput.Visible = False
Me.FrmRobotMovement.Visible = False
Me.FrmHeat.Visible = False
msg = ""
strMsg1 = ""

ElseIf strMsgfromserver(0) = "Password" And strMsgfromserver(1) =


"Accepted" Then
Me.TimerHidden.Enabled = True
TimerRefresh.Enabled = True
CheckUserPassword = 1
Me.FrameServerLogin.Visible = False
Me.FrameOutput.Visible = True
Me.FrmRobotMovement.Visible = True
Me.FrmHeat.Visible = True
msg = ""
strMsg1 = ""

End If

End If

If CheckUserPassword = 1 And intMsgarray > 5 Then

If intMsgarray > 5 Then

strMsg2 = Trim(strMsg1)

Page lxxxi
strMsg2array = Split(strMsg2, ",")

Do While intdatacounter < 6

If strMsg2array(intdatacounter) = "Temperature" Then


dblTemp2 = Val(strMsg2array(intdatacounter + 1))
End If

If strMsg2array(intdatacounter) = "Humidity" Then


dblHumidity1 = Val(strMsg2array(intdatacounter + 1))
End If

If strMsg2array(intdatacounter) = "Pressure" Then


dblPressure1 = Val(strMsg2array(intdatacounter + 1))
End If

intdatacounter = intdatacounter + 1
Loop

PackSensor
strMsg2 = ""
strMsg1 = ""
intdatacounter = 0

End If
End If
End Sub

Private Sub tcpClient_Error(ByVal Number As Integer, Description As String,


ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
MsgBox Source & ": " & Description, vbExclamation, "TCP/IP Error"
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If Me.FrameOutput.Visible = True Then

If KeyCode = vbKeyUp And bisup = False Then


bisup = True
intx = intx + intxup
End If

If KeyCode = vbKeyDown And bisdown = False Then


bisdown = True
intx = intx + intxdown
End If

If KeyCode = vbKeyLeft And bisleft = False Then


bisleft = True
intx = intx + intxleft
End If

If KeyCode = vbKeyRight And bisright = False Then


bisright = True
intx = intx + intxright
End If

Page lxxxii
GearTransition

End If

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

If Me.FrameOutput.Visible = True Then

If KeyCode = vbKeyUp Then


bisup = False
intx = intx - intxup
End If

If KeyCode = vbKeyDown Then


bisdown = False
intx = intx - intxdown
End If

If KeyCode = vbKeyLeft Then


bisleft = False
intx = intx - intxleft
End If

If KeyCode = vbKeyRight Then


bisright = False
intx = intx - intxright
End If

GearTransition

End If

End Sub

Private Sub GearTransition()

If (bisup And bisdown) Or intx = 0 Then


Me.tcpClient.SendData "Stop"
Exit Sub
End If

intGear = intx And 1

If (intGear = 1 And bForward = False) Or (intGear = 0 And bForward = True)


Then
Me.tcpClient.SendData "Stop"
Outkey
Else
Outkey
End If

End Sub

' From Data Port

Page lxxxiii
' Arrow up = bit 0 high = 1
' Arrow down = bit 1 high = 2
' Arrow left = bit 2 high = 4
' Arrow right = bit 3 high = 8

Private Sub Outkey()

'Straight Forward
If intx = 1 Then
Me.tcpClient.SendData "StraightForward"
bForward = True
Exit Sub
End If

'Forward Left
If intx = 5 Then
Me.tcpClient.SendData "ForwardLeft"
bForward = True
Exit Sub
End If

'Forward Right
If intx = 9 Then
Me.tcpClient.SendData "ForwardRight"
bForward = True
Exit Sub
End If

'Straight Backward
If intx = 2 Then
Me.tcpClient.SendData "StraightBackward"
bForward = False
Exit Sub
End If

'Backward Left
If intx = 6 Then
Me.tcpClient.SendData "BackwardLeft"
bForward = False
Exit Sub
End If

'Backward Right
If intx = 10 Then
Me.tcpClient.SendData "BackwardRight"
bForward = False
Exit Sub
End If

End Sub

Private Sub TimerHidden_Timer()


TimerHidden.Enabled = False
End Sub

Private Sub OptionDuration_Click()


Me.lblCircleTurns.Enabled = False

Page lxxxiv
Me.txtCircleTurns.Enabled = False
Me.lblCircleDuration.Enabled = True
Me.txtCircleDuration.Enabled = True
Me.cmdCircleTurns.Enabled = False
Me.cmdCircleDuration.Enabled = True
End Sub

Private Sub OptionTurns_Click()


Me.lblCircleDuration.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.lblCircleTurns.Enabled = True
Me.txtCircleTurns.Enabled = True
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = True
End Sub

Private Sub cmdCircleDuration_Click()

If Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0 And


Me.OptionCircleLeft.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Me.tcpClient.SendData "ForwardLeft"
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionCircleRight.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Me.tcpClient.SendData "ForwardRight"
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionStraightForward.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)

Page lxxxv
Me.tcpClient.SendData "StraightForward"
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionStraightBackward.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Me.tcpClient.SendData "StraightBackward"
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionBackwardLeft.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Me.tcpClient.SendData "BackwardLeft"
Me.TimerCircleDuration.Enabled = True

ElseIf Me.OptionDuration.Value = True And Val(Me.txtCircleDuration.Text) > 0


And Me.OptionBackwardRight.Value = True Then

bMoveCheck = False
Me.txtCircleTurns.Enabled = False
Me.txtCircleDuration.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleDuration.Interval = Val(Me.txtCircleDuration.Text)
Me.tcpClient.SendData "BackwardRight"
Me.TimerCircleDuration.Enabled = True

End If

End Sub

Private Sub TimerCircleDuration_Timer()


Me.tcpClient.SendData "Stop"
Me.TimerCircleDuration.Enabled = False
Me.txtCircleDuration.Enabled = True
Me.OptionDuration.Enabled = True
Me.OptionTurns.Enabled = True
Me.cmdCircleDuration.Enabled = True

Page lxxxvi
Me.cmdCircleTurns.Enabled = False
bMoveCheck = True
intx = 0
End Sub

Private Sub cmdCircleTurns_Click()

If Me.OptionTurns.Value = True And Val(Me.txtCircleTurns.Text) > 0 And


Me.OptionCircleLeft.Value = True Then

bMoveCheck = False
Me.txtCircleDuration.Enabled = False
Me.txtCircleTurns.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleTurns.Interval = Val(Me.txtCircleTurns.Text) * 500
Me.tcpClient.SendData "ForwardLeft"
Me.TimerCircleTurns.Enabled = True

ElseIf Me.OptionTurns.Value = True And Val(Me.txtCircleTurns.Text) > 0 And


Me.OptionCircleRight.Value = True Then

bMoveCheck = False
Me.txtCircleDuration.Enabled = False
Me.txtCircleTurns.Enabled = False
Me.OptionDuration.Enabled = False
Me.OptionTurns.Enabled = False
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = False
Me.TimerCircleTurns.Interval = Val(Me.txtCircleTurns.Text) * 500
Me.tcpClient.SendData "ForwardRight"
Me.TimerCircleTurns.Enabled = True

End If

End Sub

Private Sub TimerCircleTurns_Timer()


Me.tcpClient.SendData "Stop"
Me.TimerCircleTurns.Enabled = False
Me.txtCircleTurns.Enabled = True
Me.OptionDuration.Enabled = True
Me.OptionTurns.Enabled = True
Me.cmdCircleDuration.Enabled = False
Me.cmdCircleTurns.Enabled = True
bMoveCheck = True
End Sub

Private Sub cmdCircleStop_Click()

Me.TimerCircleDuration.Enabled = False
Me.TimerCircleTurns.Enabled = False
Me.tcpClient.SendData "Stop"
If Me.OptionDuration.Value = True Then
Me.txtCircleDuration.Enabled = True

Page lxxxvii
Me.cmdCircleDuration.Enabled = True
ElseIf Me.OptionTurns.Value = True Then
Me.txtCircleTurns.Enabled = True
Me.cmdCircleTurns.Enabled = True
End If
Me.OptionDuration.Enabled = True
Me.OptionTurns.Enabled = True
bMoveCheck = True

End Sub

Page lxxxviii
APPENDIX G – PIC CODE (PIC-C LANGUAGE)
// Design 2 – Sensor / Transmitter Interface
// PIC16F876
//*****************************************************************//
// Pin Designations:
//
// AN0 – Sensors B0 - Power LED C6 - Serial Output to X-mit
// AN1 - B1 - Low Battery LED C7 - Rcv from Boot-Loader
// AN2 - B2 - Temp Switch
// AN3 - !!B3 is bad!!
// AN5 - B4 - Humidity Switch
// B5 - Low Battery Switch
// B6 - Pressure Switch
//*****************************************************************//

#include <16f876.h>
#use delay(clock=20000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#fuses HS,NOWDT
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

void test_batt( int16 signal );


totemp(char c);
topres(char c);
tohum(char c);

char temp_string[20];
char pres_string[20];
char hum_string[20];
byte stringptr=0;

void main() {

unsigned int temp_int; // value of char to be sent

int counter=0; // loop counter


int i=0; // dummy loop counter

int16 anval0=0; // ADC0 Temperature


int16 anval1=0; // ADC1 Pressure
int16 anval2=0; // ADC2 Humidity
int16 anval5=0; // ADC5 Low Battery

float batt;

set_tris_b(0x00); // sets b pins for outputs


set_tris_c(0x00); // sets c pins for outputs

setup_adc(ADC_CLOCK_INTERNAL); // Uses internal timer to run ADC


setup_adc_ports( A_ANALOG ); // Sets up RA0 RA1 RA2 RA3 RA5
// as analog inputs with Ref=Vdd
set_adc_channel(PIN_A0); // sets PIC to read from AN0

Page lxxxix
output_B(0);
output_high(PIN_B0); // "Power Is On" LED

// program while loop


while (TRUE) {
counter++;

// Read temperature sensor value


output_high(PIN_B2); // Turn on only Temperature Sensor
delay_us(1000); // Delay is required for accurate reading
anval0 = read_adc(); // reading from pin AN0
output_low(PIN_B2); // Turn off temperature sensor

// Send temperature information


printf(totemp, "\fT,%ld,", anval0);
printf("%s", temp_string);

// Read pressure sensor value


output_high(PIN_B6); // Turn on only Pressure Sensor
delay_us(1000); // Delay is required for accurate reading
anval1 = read_adc(); // reading from pin AN0
output_low(PIN_B6); // Turn off pressure sensor

// Send pressure information


printf(topres, "\fP,%ld,", anval1);
printf("%s", pres_string);

// Read humidity sensor value


output_high(PIN_B4); // Turn on Humidity Sensor
delay_us(1000); // Delay is required for accurate reading
anval2 = read_adc(); // reading from pin AN0
output_low(PIN_B4); // Turn off Humidity Sensor

// Send humidity information


printf(tohum, "\fH,%ld,", anval2);
printf("%s", hum_string);

// read Low Battery sensor value less frequently


if (counter==1 || counter==64 || counter==128 || counter==192 ||
counter==32 || counter==96 || counter==160 || counter==224) {
output_high(PIN_B5); // Turn on Low_Batt Signal
delay_us(1000); // Delay is required for accurate reading
anval5 = read_adc(); // reading from pin AN5
output_low(PIN_B5); // Turn off Low_Batt Signal
test_batt( anval5 ); // test the battery voltage
} // end of if

if (counter==255) // The program should not need this statement


counter = 0;
} // end of program while loop
} // End of Main

// Function writes integer to string


totemp(char c) {
if (c=='\f')
stringptr=0;

Page xc
else
temp_string[stringptr++]=c;
temp_string[stringptr]=0;
}

// Function writes integer to string


topres(char c) {
if (c=='\f')
stringptr=0;
else
pres_string[stringptr++]=c;
pres_string[stringptr]=0;
}

// Function writes integer to string


tohum(char c) {
if (c=='\f')
stringptr=0;
else
hum_string[stringptr++]=c;
hum_string[stringptr]=0;
}

// Function tests battery voltage by way of a voltage divider


void test_batt( int16 signal ) {
if ( signal < 348 ) // if half of the 9V battery level
// is less than 3.0 V
output_high(PIN_B1); // send '1' to pin B1
else output_low(PIN_B1); // otherwise send '0' to pin B1
} // end of test_batt

Page xci