This might be the front or rear, or even the USB camera
depending on what is available and how your tablet manages
the list. Just try the different options on your machine to
determine what camera each command activates.
The resolution parameter works in a similar way. Each
camera has a list of possible resolutions, and the resolution
parameter passed (0, 1, 2, 3, etc.) is used to select an
option from the list. Typically, a value of zero gives the
maximum available resolution. If your camera only has three
possible choices, then you should only use the numbers 0,
Using the GPS
The short RobotBASIC program in Figure 2
demonstrates how to build a ReadGPS() function that can
provide easy access to GPS coordinates obtained from the
Sensor Utility. As discussed in the first article of this series,
the name of a text file is used to create a handshaking
arrangement between the utility and the application. (Refer
to that article in the December 2013 issue for more details.)
xyString 10,100,"Longitude: ",Long;" "
xyString 10,120,"Latitude: ",Lat;" "
When the program is run, it produces the output shown in
There are several considerations worth mentioning. The
GPS unit we used provided a reasonable test environment,
but it definitely has limitations. As you would expect, the
imprecise resolution of an inexpensive GPS can certainly
impact the robot’s performance, and new readings can
sometimes take 10 seconds or more for a new physical
position to register. The coordinates also bounce around a
lot in the least significant digits, so you might want to
round the values to some appropriate number of digits as
shown in Figure 2.
// give the Interface Utility a command
// now request the Utility to perform
// and wait for it to respond
// then get the data from the clipboard
// and parse it
// and return the values as variables
// round to 5 decimal places
Many USB GPS units (including the BU-353-S4) have a
strong magnet on their backside to hold the sensor to the
top of a car. The strength of the magnet will interfere with
the tablet’s compass readings, so we removed it before
getting it near the tablet (the magnet was glued to the
bottom under a thin membrane).
As mentioned earlier, this month’s project needs to
capture images in order to search for objects of a specified
color. In addition to being able to obtain readings from a
tablet’s internal sensors, our Sensor Utility provides the
ability to capture images from up to three cameras (perhaps
a front, rear, and USB camera) in any of the available
resolutions. Figure 4 shows a function that can obtain
either a JPG or a BMP image from the utility.
To use the function, you pass it a camera command
and either the string “JPG” or “BMP” depending on what
type of image you need. The available commands are
Cam1, Cam2, and Cam3 — each of which is followed by a
space then a number representing the resolution to use
during the capture (i.e., Cam2 1).
If you use Cam1, the image will be obtained from the
first camera in Windows’ internal list of available cameras.
SERVO 02.2014 59
// tell the Utility to take the picture
If type="BMP" then FileDelete("Temp.bmp")
// wait for handshake
if type="BMP" then ToBmp "Temp.jpg"
return Figure 4.