Connect IQ > Position & Sensors


Positioning and Sensors


Monkey C provides access to the wearable’s available sensors, which may include the GPS, altimeter, thermometer, and supported ANT sensors.

Location


A Location is an abstraction of a coordinate. It exposes the ability to retrieve the coordinates in radians or decimal degrees and then provides a method to convert to coordinate formats supported by the Garmin system. The Position module also exposes string parsing interface to convert from various coordinate formats to a Location object.

// The GEO enum is used to retrieve coordinates in various String representations.
enum
{
   GEO_DEG,    // Degree Format, ddd.dddddd: 38.278652
   GEO_DM,     // Degree/Minute Format, dddmm.mmm: 38 27.865'
   GEO_DMS,    // Degree/Minute/Seconds Format, dddmmss: 38 27' 8"
   GEO_MGRS    // Military Grid Reference System (MGRS): 4QFJ12345678
}

// The Location object represents a position. It provides accessor
// methods for retrieving the coordinates in various formats.
class Location
{
   // Constructor: create a coordinate based off an options hash table
   // @param [Dictionary] options Hash table of options
   // @option options [Number] :latitude The latitude
   // @option options [Number] :longitude The longitude
   // @option options [Symbol] :format The format of lat/long (possible
   //        values are :degrees, :radians, or :semicircles)
   function initialize( options );

   // Use toDegrees() to retrieve the coordinate back as an Array of degree values.
   // @return [Array] An Array of the latitude and the longitude in degree format
   function toDegrees();

   // Use toRadians() to retrieve the coordinate back as an Array of radian values.
   // @return [Array] An Array of the latitude and the longitude in radian format
   function toRadians();

   // Use toGeoString() to get a String representation of the coordinate.
   // @param format Coordinate format to which coordinate should be
   //      converted (GEO constant)
   // @return [String] Formatted coordinate String
   function toGeoString( format );
}

Location Events


To enable the GPS call the enableLocationEvents() method. The parameters are outlined below:

enum
{
   LOCATION_ONE_SHOT,      // One-time retrieval of Location
   LOCATION_CONTINUOUS,    // Register for Location updates
   LOCATION_DISABLE        // Unregister for Location updates
}

// Request a location event with enableLocationEvents().
// @param type LOCATION_ONE_SHOT for a single location request,
//       LOCATION_CONTINUOUS to enable location tracking, and
//       LOCATION_DISABLE to turn off location tracking
// @param [Method] listener Method object to call with location updates
function enableLocationEvents( type, listener );

To register a position listener, use the method() call to create a Method callback:

function onPosition( info ) {
   Sys.println( "Position " + info.position.toGeoString( Position.GEO_DM ) );
}

function initializeListener() {
   Position.enableLocationEvents( Position.LOCATION_CONTINUOUS, method( :onPosition ) );
}

All of the location information will be sent in an Info object:

// The Location.Info class contains all information necessary for the Location.
// It can be passed on the update or it can be retrieved on demand.
class Info
{
   var position;   // Lat/lon
   var speed;      // Speed in meters per second
   var altitude;   // Altitude in meters, mean sea level
   var accuracy;   // Accuracy - good, usable, poor, not available
   var heading;    // Heading in radians
   var when;       // Moment Object: GPS time stamp of fix
}

// Use getInfo() to retrieve the current Location.Info
// @return [Location.Info] The Info object containing the current information
function getInfo();

Sensors

センサー (Sensor) モジュールを使うと、 Garmin ANT+ センサーから情報を読み出すことができる。使うためには、センサーを有効にし、リスナー関数を割り当てなければならない。

function initialize() {
   Sensor.setEnabledSensors( [Sensor.SENSOR_HEARTRATE] );
   Sensor.enableSensorEvents( method( :onSensor ) );
}

function onSensor(sensorInfo) {
   System.println( "Heart Rate: " + sensorInfo.heartRate );
}

Sensor information is packaged in the Sensor.Info object:

// The Sensor.Info class contains all information necessary for the Sensor.
// It can be passed on the update or it can be retrieved on demand.
class Info
{
   var speed;          // Speed in meters per second
   var cadence;        // Cadence in revolutions per minute
   var heartRate;      // HR in beats per minute
   var temperature;    // Temperature in degrees Centigrade
   var altitude;       // Altitude in meters
   var pressure;       // Pressure in Pa
   var heading;        // Heading in Radians
}

The simulator can simulate sensor data via the Simulation menu by selecting Fit Data > Simulate Data.
This generates valid but random values that can be read in via the sensor interface.
For more acuate simulation, the simulator can play back a FIT file and feed the input into the Sensor module.
To do this, select Simulation > Fit Data > Playback File and choose a FIT file from the dialog.

Fit ファイルへの記録

Monkey C では watch apps にて、 FIT ファイル の記録開始・停止を行うことができる。これには数ステップが必要。

  1. 各種センサーでの sensors を有効にする
  2. Fit.createSession(options) で session オブジェクトを生成する。
  3. start() で FIT session に有効なセンサーからのデータを記録(開始)する
  4. stop() to pause the recording
  5. save() で保存、もしくは discard() で削除

The FIT file will sync with Garmin Connect. You can use the Garmin Connect API to process the FIT file from a web service.

Communicating With ANT Sensors


Connect IQ provides a low level interface for communication with ANT and ANT+ sensors.
With this interface, an ANT channel can be created to send and receive ANT packets.
The MO2Display sample provides a sample application that implements the Muscle Oxygen ANT profile.
The ANT Generic interface is not available to watch faces.
Low and High priority search timeout for sensors differs from the basic ANT radio specification to allow for interoperation with native ANT behavior on devices.
These are limited to a maximum timeout of 30 seconds and 5 seconds respectively.

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2016年03月05日 23:24