My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2011 Google Inc. All Rights Reserved.

package com.cellbots.perception.sensors;

import android.hardware.Sensor;
import android.hardware.SensorEvent;

import com.cellbots.perception.math.FlatteningIntegrator;
import com.cellbots.perception.math.Integrator;
import com.cellbots.perception.math.Vector;

/**
* A vector sensor that processes acceleration data and integrates position.
* @author centaur@google.com (Anthony Francis)
*/
public class AccelSensor extends VectorSensor implements PositionSensor {
/** The integrator used to record the integrated position. */
private Integrator integrator;

/** The current position. */
private Vector pos;

/** Previous position (required for Verlet integration). */
private Vector lastPos;

/**
* Create a new AccelSensor wrapping the given Android Sensor.
* @param sensor the sensor wrapped by the superclass.
* @param damping velocity damping with 1.0 is none.
* @param flattening position flattening with 1.0 is none.
*/
public AccelSensor(Sensor sensor, float damping, float flattening) {
super(sensor);
integrator = new FlatteningIntegrator(damping, flattening);
pos = new Vector();
lastPos = new Vector();
}

@Override
public void update(SensorEvent event) {
super.update(event);
updatePosition();
}

/** Integrate the position based on the accel vector. */
public void updatePosition() {
integrator.integrate(getPos(), getLastPos(), data, elapsedTime);
}

@Override
public void setPos(Vector pos) {
this.pos = pos;
}

@Override
public Vector getPos() {
return pos;
}

@Override
public void setLastPos(Vector lastPos) {
this.lastPos = lastPos;
}

@Override
public Vector getLastPos() {
return lastPos;
}
}

Change log

r228 by cent...@google.com on May 20, 2011   Diff
PerceptionManager code (manager subdir)
testing application (testbed) and
unittests.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1786 bytes, 69 lines
Powered by Google Project Hosting