Skip to content

Commit

Permalink
- OrientationInterpreter filter orientation_buffer_size is now confi…
Browse files Browse the repository at this point in the history
…gurable.

 -Threshold accessors removed from OrientationFilter since those had no effect.
  • Loading branch information
Antti Virtanen committed Mar 8, 2011
1 parent 645a33b commit 40b5443
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 50 deletions.
3 changes: 2 additions & 1 deletion adaptors/accelerometeradaptor/accelerometeradaptor.cpp
Expand Up @@ -79,7 +79,6 @@ void AccelerometerAdaptor::interpretEvent(int src, struct input_event *ev)
break;
}
break;

}
}

Expand All @@ -98,6 +97,8 @@ void AccelerometerAdaptor::commitOutput(struct input_event *ev)
d->y_ = orientationValue_.y_;
d->z_ = orientationValue_.z_;

sensordLogT() << "Accelerometer reading: " << d->x_ << ", " << d->y_ << ", " << d->z_;

accelerometerBuffer_->commit();
accelerometerBuffer_->wakeUpReaders();
}
Expand Down
4 changes: 2 additions & 2 deletions adaptors/magnetometeradaptor/magnetometeradaptor.cpp
Expand Up @@ -98,7 +98,7 @@ void MagnetometerAdaptor::processSample(int pathId, int fd)
unsigned int bytesRead = read(fd, &mag_data, sizeof(mag_data));

if (bytesRead < sizeof(mag_data)) {
sensordLogW() << "read" << bytesRead << "bytes out of expected" << sizeof(mag_data) << "bytes. Previous error:" << strerror(errno);
sensordLogW() << "read " << bytesRead << " bytes out of expected " << sizeof(mag_data) << " bytes. Previous error: " << strerror(errno);
//return;
}

Expand All @@ -107,7 +107,7 @@ void MagnetometerAdaptor::processSample(int pathId, int fd)
sensordLogD() << "Invalid sample received from magnetometer";
}

sensordLogT() << "Magnetometer Reading:" << mag_data.x << mag_data.y << mag_data.z;
sensordLogT() << "Magnetometer reading: " << mag_data.x << ", " << mag_data.y << ", " << mag_data.z;

TimedXyzData* sample = magnetometerBuffer_->nextSlot();

Expand Down
1 change: 1 addition & 0 deletions config/90-sensord-default.conf
Expand Up @@ -39,6 +39,7 @@ orientation_threshold_portrait = 20
orientation_overflow_min = 800
orientation_overflow_max = 1250
orientation_poll_interval = 1000
orientation_buffer_size = 10

# Offset for Screen.TopEdge. If 0, Screen.TopEdge equals side edges from
# OrientationSensor. Each additional value rotates the top one step to
Expand Down
2 changes: 2 additions & 0 deletions debian/changelog
Expand Up @@ -11,6 +11,8 @@ sensord (0.6.41) unstable; urgency=low
- SensorManager::addSensor() now gracefully handles if object registration to dbus fails.
- SocketHandler::socketReadable now gracefully handles if client writes sessionId incorrectly.
* Downsampling (which works by dropping samples) can be now enabled/disabled.
* OrientationInterpreter filter orientation_buffer_size is now configurable.
* Threshold accessors removed from OrientationFilter since those had no effect.

-- Antti Virtanen <antti.i.virtanen@nokia.com> Mon, 07 Mar 2011 16:17:54 +0200

Expand Down
53 changes: 21 additions & 32 deletions filters/orientationinterpreter/orientationinterpreter.cpp
Expand Up @@ -47,25 +47,26 @@ typedef PoseData (OrientationInterpreter::*ptrFUN)(int);

OrientationInterpreter::OrientationInterpreter() :
accDataSink(this, &OrientationInterpreter::accDataAvailable),
threshold_(DEFAULT_THRESHOLD),
topEdge(PoseData::Undefined),
face(PoseData::Undefined),
previousFace(PoseData::Undefined),
o_(PoseData::Undefined)
orientationData(PoseData::Undefined)

{
addSink(&accDataSink, "accsink");
addSource(&topEdgeSource, "topedge");
addSource(&faceSource, "face");
addSource(&orientationSource, "orientation");

minlimit = Config::configuration()->value("orientation_overflow_min",QVariant(OVERFLOW_MIN)).toInt();
maxlimit = Config::configuration()->value("orientation_overflow_max",QVariant(OVERFLOW_MAX)).toInt();
minLimit = Config::configuration()->value("orientation_overflow_min", QVariant(OVERFLOW_MIN)).toInt();
maxLimit = Config::configuration()->value("orientation_overflow_max", QVariant(OVERFLOW_MAX)).toInt();

angleThresholdPortrait = Config::configuration()->value("orientation_threshold_portrait",QVariant(THRESHOLD_PORTRAIT)).toInt();
angleThresholdLandscape = Config::configuration()->value("orientation_threshold_landscape",QVariant(THRESHOLD_LANDSCAPE)).toInt();
angleThresholdPortrait = Config::configuration()->value("orientation_threshold_portrait", QVariant(THRESHOLD_PORTRAIT)).toInt();
angleThresholdLandscape = Config::configuration()->value("orientation_threshold_landscape", QVariant(THRESHOLD_LANDSCAPE)).toInt();

discardTime = Config::configuration()->value("orientation_discard_time", QVariant(DISCARD_TIME)).toUInt();

maxBufferSize = Config::configuration()->value("orientation_buffer_size", QVariant(AVG_BUFFER_MAX_SIZE)).toInt();
}

void OrientationInterpreter::accDataAvailable(unsigned, const AccelerationData* pdata)
Expand All @@ -82,26 +83,18 @@ void OrientationInterpreter::accDataAvailable(unsigned, const AccelerationData*
// Append new value to buffer
dataBuffer.append(data);

// Limit buffer size to N samples
// Avoids bloating when timestamps don't make sense
if (dataBuffer.count() > AVG_BUFFER_MAX_SIZE)
{
dataBuffer.erase(dataBuffer.begin(), dataBuffer.end() - 10);
}

// Clear old values from buffer.
while (dataBuffer.count() > 1 && (data.timestamp_ - dataBuffer.first().timestamp_ > discardTime))
while (dataBuffer.count() > maxBufferSize || (dataBuffer.count() > 1 && (data.timestamp_ - dataBuffer.first().timestamp_ > discardTime)))
{
dataBuffer.removeFirst();
}

//Calculate average
long x = 0;
long y = 0;
long z = 0;
foreach (const AccelerationData& sample, dataBuffer)
{
// Dummy average calculations, optimise if a neater method
// is figured out.
x += sample.x_;
y += sample.y_;
z += sample.z_;
Expand All @@ -123,19 +116,18 @@ void OrientationInterpreter::accDataAvailable(unsigned, const AccelerationData*

bool OrientationInterpreter::overFlowCheck()
{
int gVector = ((data.x_*data.x_ + data.y_*data.y_ + data.z_*data.z_)/1000);
return !((gVector >= minlimit) && (gVector <=maxlimit));
int gVector = ((data.x_ * data.x_ + data.y_ * data.y_ + data.z_ * data.z_) / 1000);
return !((gVector >= minLimit) && (gVector <= maxLimit));
}

int OrientationInterpreter::orientationCheck(const AccelerationData &data, OrientationMode mode) const
{
if (mode == OrientationInterpreter::Landscape)
return round(atan((double)data.x_ / sqrt(data.y_*data.y_ + data.z_*data.z_)) * RADIANS_TO_DEGREES);
return round(atan((double)data.x_ / sqrt(data.y_ * data.y_ + data.z_ * data.z_)) * RADIANS_TO_DEGREES);
else
return round(atan((double)data.y_ / sqrt(data.x_*data.x_ + data.z_*data.z_)) * RADIANS_TO_DEGREES);
return round(atan((double)data.y_ / sqrt(data.x_ * data.x_ + data.z_ * data.z_)) * RADIANS_TO_DEGREES);
}


PoseData OrientationInterpreter::rotateToPortrait(int rotation)
{
PoseData newTopEdge = PoseData::Undefined;
Expand Down Expand Up @@ -168,7 +160,6 @@ PoseData OrientationInterpreter::rotateToLandscape(int rotation)
}

return newTopEdge;

}

PoseData OrientationInterpreter::orientationRotation (const AccelerationData &data, OrientationMode mode, PoseData (OrientationInterpreter::*ptrFUN)(int))
Expand Down Expand Up @@ -208,7 +199,7 @@ void OrientationInterpreter::processTopEdge()
if (topEdge.orientation_ != newTopEdge.orientation_)
{
topEdge.orientation_ = newTopEdge.orientation_;
sensordLogT() << "new TopEdge value:" << topEdge.orientation_;
sensordLogT() << "new TopEdge value: " << topEdge.orientation_;
topEdge.timestamp_ = data.timestamp_;
topEdgeSource.propagate(1, &topEdge);
}
Expand All @@ -223,8 +214,7 @@ void OrientationInterpreter::processFace()

if (newFace.orientation_ == PoseData::FaceDown)
{
if (topEdge.orientation_ != PoseData::Undefined)
{
if (topEdge.orientation_ != PoseData::Undefined) {
face.orientation_ = PoseData::FaceUp;
} else {
face.orientation_ = PoseData::FaceDown;
Expand All @@ -246,17 +236,16 @@ void OrientationInterpreter::processOrientation()
{
PoseData newPose;

if (topEdge.orientation_ != PoseData::Undefined)
{
if (topEdge.orientation_ != PoseData::Undefined) {
newPose.orientation_ = topEdge.orientation_;
} else {
newPose.orientation_ = face.orientation_;
}

if (newPose.orientation_ != o_.orientation_) {
o_.orientation_ = newPose.orientation_;
sensordLogT() << "New orientation value:" << o_.orientation_;
o_.timestamp_ = data.timestamp_;
orientationSource.propagate(1, &o_);
if (newPose.orientation_ != orientationData.orientation_) {
orientationData.orientation_ = newPose.orientation_;
sensordLogT() << "New orientation value: " << orientationData.orientation_;
orientationData.timestamp_ = data.timestamp_;
orientationSource.propagate(1, &orientationData);
}
}
21 changes: 6 additions & 15 deletions filters/orientationinterpreter/orientationinterpreter.h
Expand Up @@ -30,7 +30,6 @@
#define ORIENTATIONINTERPRETER_H

#include <QObject>
#include <QAtomicInt>
#include "filter.h"
#include <datatypes/orientationdata.h>
#include <datatypes/posedata.h>
Expand All @@ -42,13 +41,11 @@
* #AccelerometerChain is used.
*
*/

class OrientationInterpreter : public QObject, public FilterBase
{
Q_OBJECT;

Q_PROPERTY(PoseData orientation READ orientation);
Q_PROPERTY(int threshold READ threshold WRITE setThreshold);

private:
Sink<OrientationInterpreter, AccelerationData> accDataSink;
Expand All @@ -65,8 +62,6 @@ class OrientationInterpreter : public QObject, public FilterBase

OrientationInterpreter();

QAtomicInt threshold_;

PoseData topEdge;
PoseData face;
PoseData previousFace;
Expand All @@ -75,13 +70,15 @@ class OrientationInterpreter : public QObject, public FilterBase
AccelerationData data;
QList<AccelerationData> dataBuffer;

int minlimit;
int maxlimit;
int minLimit;
int maxLimit;
int angleThresholdPortrait;
int angleThresholdLandscape;
unsigned long discardTime;
int maxBufferSize;

PoseData orientationData;

PoseData o_;
enum OrientationMode
{
Portrait = 0, /**< Orientation mode is portrait. */
Expand Down Expand Up @@ -117,13 +114,7 @@ class OrientationInterpreter : public QObject, public FilterBase
return new OrientationInterpreter();
}

PoseData orientation() const {
return o_;
}

int threshold() const { return threshold_; }

void setThreshold(int threshold) { threshold_ = threshold; }
PoseData orientation() const { return orientationData; }
};

#endif

0 comments on commit 40b5443

Please sign in to comment.