Permalink
Browse files

Adding SpinToWinKid, a cool and weird experiment

  • Loading branch information...
cpscotti
cpscotti committed Apr 19, 2011
1 parent f6fda3b commit 3265f7df6d88ca5a4ae49e43fe5b05f1cc6b0ebd
@@ -301,6 +301,9 @@ void DevicesManager::SetupAbstractDevices()
PushN8SimpleReportsGenerator * reportGenerator = new PushN8SimpleReportsGenerator();
configuredDevices->push_back(reportGenerator);
- VirtualBrosDevice * virtualBros = new VirtualBrosDevice();
- configuredDevices->push_back(virtualBros);
+ SpinToWinKid * spin2WinKid = new SpinToWinKid();
+ configuredDevices->push_back(spin2WinKid);
+
+// VirtualBrosDevice * virtualBros = new VirtualBrosDevice();
+// configuredDevices->push_back(virtualBros);
}
@@ -64,6 +64,7 @@
#include "pushn8simplereportsgenerator.h"
#include "virtualbrosdevice.h"
+#include "spintowinkid.h"
//#include "pushn8unprogdev.h"
#include "pushn8simulationdevice.h"
@@ -32,6 +32,15 @@ NPushAirTimeTick::NPushAirTimeTick(quint64 a_msecsInAir, bool a_landed, quint64
landed = a_landed;
msecsToEpoch = a_msecsToEpoch;
msecsOnAir = a_msecsInAir;
+ isOnlyHint = false;
+}
+
+NPushAirTimeTick::NPushAirTimeTick(quint64 a_msecsInAir, bool a_landed, quint64 a_msecsToEpoch, bool a_hint)
+{
+ landed = a_landed;
+ msecsToEpoch = a_msecsToEpoch;
+ msecsOnAir = a_msecsInAir;
+ isOnlyHint = a_hint;
}
@@ -42,22 +51,26 @@ NPushAirTimeTick::~NPushAirTimeTick()
void NPushAirTimeTick::append_to_xml(QDomDocument& doc, QDomElement& root) const
{
- QDomElement tickDom = doc.createElement("air_time");
- tickDom.setAttribute("tstamp", (double)(msecsToEpoch*0.001));
- tickDom.setAttribute("in_air", (double)(msecsOnAir*0.001));
- tickDom.setAttribute("landed", ((landed)?"true":"false") );
+ if(!isOnlyHint) {
+ QDomElement tickDom = doc.createElement("air_time");
+ tickDom.setAttribute("tstamp", (double)(msecsToEpoch*0.001));
+ tickDom.setAttribute("in_air", (double)(msecsOnAir*0.001));
+ tickDom.setAttribute("landed", ((landed)?"true":"false") );
- root.appendChild(tickDom);
+ root.appendChild(tickDom);
+ }
}
void NPushAirTimeTick::dump_to_xml(QXmlStreamWriter& xml) const
{
- xml.writeStartElement("air_time");
+ if(!isOnlyHint) {
+ xml.writeStartElement("air_time");
- xml.writeAttribute("tstamp", QString::number(((double)msecsToEpoch)/(double)1000.0, 'f', 3));
- xml.writeAttribute("in_air", QString::number(((double)msecsOnAir)/(double)1000.0, 'f', 3));
- xml.writeAttribute("landed", ((landed)?"true":"false") );
- xml.writeEndElement();//air_time
+ xml.writeAttribute("tstamp", QString::number(((double)msecsToEpoch)/(double)1000.0, 'f', 3));
+ xml.writeAttribute("in_air", QString::number(((double)msecsOnAir)/(double)1000.0, 'f', 3));
+ xml.writeAttribute("landed", ((landed)?"true":"false") );
+ xml.writeEndElement();//air_time
+ }
}
QString NPushAirTimeTick::get_pretty_print() const
@@ -38,6 +38,7 @@ class NPushAirTimeTick : public NPushLogTick
{
public:
NPushAirTimeTick(quint64 a_msecsInAir, bool a_landed, quint64 a_msecsToEpoch);
+ NPushAirTimeTick(quint64 a_msecsInAir, bool a_landed, quint64 a_msecsToEpoch, bool a_hint);
~NPushAirTimeTick();
void append_to_xml(QDomDocument& doc, QDomElement& root) const;
@@ -46,6 +47,8 @@ class NPushAirTimeTick : public NPushLogTick
public:
+ bool isOnlyHint;
+
quint64 msecsToEpoch;
quint64 msecsOnAir;
bool landed;
@@ -53,7 +53,7 @@ public slots:
private:
QQueue<NPushLogTick *> ticksQueue;
- static const int maxQueueSize = 2000;
+ static const int maxQueueSize = 5000;//Oh shit.. not now!
};
@@ -114,6 +114,9 @@ void PushN8AirTimeDetector::handle_response_new(Response resp)
takeOffTime = currentTstamp;
lastAirborneTime = takeOffTime;
qDebug() << "take off: " << takeOffTime;
+
+ //NOTE: To make SpinToWinKid possible
+ newTick = new NPushAirTimeTick(0, false, currentTstamp, true);
break;
default:
@@ -124,15 +127,15 @@ void PushN8AirTimeDetector::handle_response_new(Response resp)
break;
case CountingAir:
- qDebug() << "CountingAir";
+// qDebug() << "CountingAir";
switch(resp) {
case FlyingLikeAnEagle:
- qDebug() << "Flying lika bitch";
+// qDebug() << "Flying lika bitch";
if(currentTstamp >= lastAirborneTime) {//Accounts for delayed timestamps
lastAirborneTime = currentTstamp;
quint64 airTime = (lastAirborneTime - takeOffTime);
- qDebug() << "CountingAir: " << airTime;
+// qDebug() << "CountingAir: " << airTime;
if( airTime > air_threshold) {
dynamic_state = IdleAir;
@@ -142,7 +145,7 @@ void PushN8AirTimeDetector::handle_response_new(Response resp)
break;
case SlidingDownLikeAPenguin:
- qDebug() << "Sliding lika bitch";
+// qDebug() << "Sliding lika bitch";
if(lastAirborneTime >= takeOffTime) {
dynamic_state = IdleGround;
qDebug() << "IdleGround";
@@ -170,7 +173,7 @@ void PushN8AirTimeDetector::handle_response_new(Response resp)
if(currentTstamp >= lastAirborneTime) {//Accounts for delayed timestamps
lastAirborneTime = currentTstamp;
quint64 airTime = (lastAirborneTime - takeOffTime);
- qDebug() << "IdleAir: " << airTime;
+// qDebug() << "IdleAir: " << airTime;
newTick = new NPushAirTimeTick(airTime, false, currentTstamp);
}
@@ -197,7 +200,7 @@ void PushN8AirTimeDetector::handle_response_new(Response resp)
//resume
if(currentTstamp > touchDownTime && currentTstamp > lastAirborneTime) {
dynamic_state = IdleAir;
- qDebug() << "IdleAir";
+// qDebug() << "IdleAir";
lastAirborneTime = currentTstamp;
quint64 airTime = (lastAirborneTime - takeOffTime);
@@ -208,7 +211,7 @@ void PushN8AirTimeDetector::handle_response_new(Response resp)
case SlidingDownLikeAPenguin:
//count on
if(currentTstamp > touchDownTime) {
- qDebug() << "Counting ground: " << (currentTstamp - touchDownTime);
+// qDebug() << "Counting ground: " << (currentTstamp - touchDownTime);
if((currentTstamp - touchDownTime) > ground_threshold) {
dynamic_state = IdleGround;
quint64 airTime = (lastAirborneTime - takeOffTime);
@@ -257,7 +260,7 @@ void PushN8AirTimeDetector::handle_response(Response resp)
if(lastAirborneTime > takeOffTime && lastAirborneTime == currentTstamp) {
quint64 airTime = lastAirborneTime-takeOffTime;
- qDebug() << "Counting Air Time";
+// qDebug() << "Counting Air Time";
if(airTime > AIR_TIME_THRESHOLD) {
newTick = new NPushAirTimeTick(airTime, false, currentTstamp);
@@ -153,7 +153,7 @@ NPushFootTick * PushN8SimulationDevice::readFootTick()
QChar side = xml.attributes().value("side").toString().at(0);
- qDebug() << "CAUTION!! Flipping to correct runs from yesterday (march 8th)";
+// qDebug() << "CAUTION!! Flipping to correct runs from yesterday (march 8th)";
//CAUTION!! Flipping to correct runs from yesterday (march 8th).
int toes = xml.attributes().value("toes").toString().toInt();
int heel = xml.attributes().value("heel").toString().toInt();
@@ -0,0 +1,72 @@
+#include "spintowinkid.h"
+
+SpinToWinKid::SpinToWinKid(QObject *parent) : PushBurtonGenericDevice(parent)
+{
+ onAir = false;
+ qDebug() << "SpinToWinKid started";
+}
+
+
+
+SpinToWinKid::~SpinToWinKid()
+{
+ qDebug() << "SpinToWinKid closed";
+}
+
+QString SpinToWinKid::get_description()
+{
+ return QString("SpinToWinKid");
+}
+
+bool SpinToWinKid::is_online()
+{
+ return true;
+}
+
+bool SpinToWinKid::subscribesToAny()
+{
+ return true;
+}
+
+//This function will return true when the given device is a AirTimeDetector or a Imu
+bool SpinToWinKid::subscribesTo(PushBurtonGenericDevice* deviceType)
+{
+ if(typeid(*deviceType) == typeid(PushN8AirTimeDetector)){
+ return true;
+ } else if(typeid(*deviceType) == typeid(PushN8IMUDevice)){
+ return true;
+ } else {
+ return false;
+ }
+}
+
+
+void SpinToWinKid::incoming_reading(NPushLogTick * tick)
+{
+ if(typeid(*tick) == typeid(NPushAirTimeTick)) {
+
+ NPushAirTimeTick * airTimeTick = (NPushAirTimeTick *)tick;
+
+ if(airTimeTick->isOnlyHint) {
+ qDebug() << "SpinToWinKid got hint";
+ onAir = true;
+ spinAcc = 0.0;
+ lastTstamp = airTimeTick->msecsToEpoch;
+ } else if(airTimeTick->landed) {
+ qDebug() << "Landed Trick; SpinAcc = " << spinAcc;
+ onAir = false;
+ }
+ } else if(typeid(*tick) == typeid(NPushIMUTick)
+ && onAir){
+
+ NPushIMUTick * imuTick = (NPushIMUTick*)tick;
+ double spinInc = 0.0;
+ if(imuTick->msecsToEpoch > lastTstamp) {
+ spinInc = ((double)imuTick->gyro[2])/14.375;
+ qDebug() << "T = " << (imuTick->msecsToEpoch - lastTstamp)*0.001;
+ spinInc *= (imuTick->msecsToEpoch - lastTstamp)*0.001;
+ lastTstamp = imuTick->msecsToEpoch;
+ }
+ spinAcc += spinInc;
+ }
+}
View
@@ -0,0 +1,45 @@
+#ifndef SPINTOWINKID_H
+#define SPINTOWINKID_H
+
+#include <QDebug>
+#include <QString>
+#include <typeinfo>
+
+#include "pushburtongenericdevice.h"
+
+#include "npushairtimetick.h"
+#include "pushn8airtimedetector.h"
+
+#include "pushn8imudevice.h"
+#include "npushimutick.h"
+
+class SpinToWinKid : public PushBurtonGenericDevice
+{
+ Q_OBJECT
+public:
+ explicit SpinToWinKid(QObject *parent = 0);
+
+ ~SpinToWinKid();
+
+ QString get_description();
+ bool is_online();
+
+ bool subscribesToAny();//returns true..
+
+ //This function will return true when the given device is a AirTimeDetector or a Imu
+ bool subscribesTo(PushBurtonGenericDevice* deviceType);
+
+signals:
+
+public slots:
+ void incoming_reading(NPushLogTick *);
+
+private:
+ quint64 lastTstamp;
+ double spinAcc;
+ bool onAir;
+
+
+};
+
+#endif // SPINTOWINKID_H

0 comments on commit 3265f7d

Please sign in to comment.