faces north which is 180° out of phase with what you
would want if the tablet is mounted on a robot as shown in
Figure 1. As another example, it is not inconceivable that
someone might prefer to think of north as a specific wall in
the room where your robot operates. Since the compass
reading should always have a value between 0 and 359, the
offset value is so adjusted, if necessary, before placing it
into the designated variable.
Figure 3 shows the data displayed when the program
of Figure 2 is run. The top of the figure shows the parsed
data displayed directly from the Sensors[] array. The bottom
of the figure shows the modified data displayed using the
variable names passed to the Orientation function.
Before you execute the program shown in Figure 2,
you must ensure that the Sensors Interface Utility is
running. The utility program and its handshaking text file
should reside in the same directory as the application
program unless you add path names to all the associated
commands.
If you are using RobotBASIC, you have the option of
setting the default directory either through the FILE menu
or within a program using the DirSet() function. We
assumed that some users might prefer to have their
application start the Sensor Utility, so we added support for
this option by having it terminate if another copy is already
running. You can run the utility from RobotBASIC with the
command Spawn (“RBsensorUtility.exe”, P_NOWAIT).
Since the Sensor Utility runs entirely in the background,
we have it automatically start in the minimized mode. If you
click the tray icon though, you will see the splash screen as
shown in Figure 4 which has a button for terminating the
program. You can also terminate the program through the
command interface by placing the word Stop on the
clipboard and renaming the text file to tell the utility to
process the current command.
The Sensor Utility has numerous commands for
obtaining the desired sensor data. Placing the command
word Raw on the clipboard, for example, will request the raw
data from the gyroscope and the accelerometer (eight total
items including the two headings). The command
BasicSensors will return all of the readings shown in Figure 5,
and the command Sensors returns that data plus eight more
readings associated with the full orientation sensor. There are
other commands for obtaining images from cameras and GPS
data, but they will be discussed in future articles.
We had problems with the orientation sensors that are
worth discussion. On two occasions, the compass heading
and the tilt values on our tablet become erratic or zero.
This appeared to happen when the tablet was used near a
TV or other appliance with a significant magnetic field,
but we cannot confirm that as the cause. An Internet
search indicated that other Windows 8 tablet owners also
had this problem.
Slowly rotating the tablet (without the keyboard) on all
three axes fixed the problem for us, but only if no programs
were accessing the sensors (so close your utility before
performing this procedure). We assume the rotation causes
the tablet’s firmware to perform an internal calibration
procedure, but no one at Samsung tech support could
verify this.
As nice as it is to have access to the internal tablet
sensors, most robotic projects will also require some form
of proximity and/or ranging sensors, as well as some way
to control the robot’s motors. This generally means your
tablet needs to have a USB connector on the tablet itself
and not just on the keyboard. Most Windows tablets do
have a USB connector, but even the ones that don’t could
use the built-in Bluetooth for I/O operations. Let’s examine
four basic ways of interfacing a tablet with external sensors
and motors:
• USB I/O: Adding a USB I/O board is a
straightforward way of adding I/O pins to the tablet. We
have used the U4xx devices (see the U401 in Figure 6)
SERVO 12.2013 61
0 Light Sensor
16
2 Accelerometer
3 -0.0780000037048012
4 -1.02600004873239
5 -0.0340000016149133
6 Gyroscope
7 0.56000002659857386
8 0.0700000033248216
9 0.07000000332482166
10 Inclinometer
11 88.36
12 - 4. 59
13 267.61
14 Compass
15 92.4699979331344
16
17 Simple Orientation Sensor
18 Not Rotated
Figure 5.
Figure 4.