beetlebug▾
/

ztcl::motion watch

Runs a script at each reading of a sensor.

ztcl::motion watch accelerometer|gyroscope|rotation|heading ?-interval MS? -command SCRIPT

Description

Gives a handle, and runs SCRIPT with the dict of each reading appended, from the event loop, about each MS milliseconds: 10 to 60,000, and 100 by default. Each dict has time, in milliseconds of the uptime of the device.

The axes are those of the device in portrait. accelerometer gives x y z in m/s² with gravity: +9.81 on z with the phone flat and face up. gyroscope gives x y z in rad/s. rotation gives a quaternion x y z w in the frame east, north, up. heading gives magnetic and accuracy in degrees, and true in degrees while a location is known.

While a watch is active, the event loop wakes at least every 20 milliseconds, since the host gives the readings from its own thread. The interpreter stops each watch when it ends.

Returns

A handle, such as motion1.

Examples

% catch {ztcl::motion watch gyroscope -command puts} msg; set msg
the gyroscope is not available on this platform

Errors

% ztcl::motion watch gyroscope -command puts
the gyroscope is not available on this platform
-errorcode ZTCL MOTION UNAVAILABLE

% ztcl::motion watch gyroscope -interval 5 -command puts
bad interval "5": must be 10 to 60000 milliseconds
-errorcode ZTCL MOTION VALUE

% ztcl::motion watch gyroscope
wrong # args: should be "ztcl::motion watch accelerometer|gyroscope|rotation|heading ?-interval ms? -command script"
-errorcode TCL WRONGARGS

Facts

Capability
sensors. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.6

See also