Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::Glove Class Reference

This is the abstract base glove class. More...

#include <Glove.h>

Inheritance diagram for gadget::Glove:

Inheritance graph
[legend]
Collaboration diagram for gadget::Glove:

Collaboration graph
[legend]
List of all members.

Public Types

typedef gadget::SampleBuffer<
GloveData
SampleBuffer_t

Public Methods

 Glove ()
virtual ~Glove ()
virtual bool config (jccl::ConfigElementPtr element)
gmtl::Vec3f getTipVector (GloveData::GloveComponent component, int devNum)
 Returns a vector ponting "out" of the component. More...

gmtl::Matrix44f getTipTransform (GloveData::GloveComponent component, int devNum)
 Returns the transform matrix of the specified finger tip in world space wTt = wTb bTj jTt. More...

gmtl::Matrix44f getJointTransform (GloveData::GloveComponent component, GloveData::GloveJoint joint, int devNum)
 Returns the transform matrix of the specified joint in world space wTj = wTb bTj. More...

GloveData getGloveData (int devNum)
 Returns a copy of the glove data struct. More...

void addGloveSample (const std::vector< GloveData > &gloveSample)
 Helper method to add a sample to the sample buffers. More...

void swapGloveBuffers ()
 Swap the glove data buffers. More...

const SampleBuffer_t::buffer_t & getGloveDataBuffer ()
virtual std::string getBaseType ()
virtual vpr::ReturnStatus writeObject (vpr::ObjectWriter *writer)
virtual vpr::ReturnStatus readObject (vpr::ObjectReader *reader)
std::vector< GloveDatagetGloveDataFromDigitalData (const std::vector< DigitalData > &digitalData)
 Utility function to convert a 10 size vector of DigitalData to GloveData. More...


Protected Methods

 Glove (const gadget::Glove &g)
void operator= (const gadget::Glove &g)

Protected Attributes

SampleBuffer_t mGloveSamples
 Glove samples. More...

GloveData mDefaultValue
 Default glove data to return. More...

std::vector< PositionInterfacemGlovePositions

Detailed Description

This is the abstract base glove class.

It specifies the interface to all glove objects in the system. Gadgeteer will deal only with gloves using this interface.

Definition at line 56 of file Glove.h.


Member Typedef Documentation

typedef gadget::SampleBuffer<GloveData> gadget::Glove::SampleBuffer_t
 

Definition at line 59 of file Glove.h.


Constructor & Destructor Documentation

gadget::Glove::Glove  
 

Definition at line 53 of file Glove.cpp.

References mDefaultValue, and mGlovePositions.

00054 {
00055    //Initialize the transforms for the default GloveData
00056    mDefaultValue.calcXforms();
00057 
00058    //By default there are 2 gloves
00059    mGlovePositions.resize(2);
00060 }

virtual gadget::Glove::~Glove   [inline, virtual]
 

Definition at line 64 of file Glove.h.

00064 {}

gadget::Glove::Glove const gadget::Glove &    g [inline, protected]
 

Definition at line 131 of file Glove.h.

00131 :vpr::SerializableObject(){;}


Member Function Documentation

bool gadget::Glove::config jccl::ConfigElementPtr    element [virtual]
 

Reimplemented in gadget::SimDigitalGlove.

Definition at line 62 of file Glove.cpp.

References mGlovePositions.

00063 {
00064    // For now, assume just 2 gloves (left & right)
00065    std::vector<std::string> positionProxyNames(2);
00066    positionProxyNames[0]=e->getProperty<std::string>("left_glove_position");
00067    positionProxyNames[1]=e->getProperty<std::string>("right_glove_position");
00068 
00069    mGlovePositions.resize(positionProxyNames.size());
00070    unsigned int i;
00071    for(i=0;i<positionProxyNames.size();i++)
00072    {
00073       if(positionProxyNames[i]!="")
00074       {
00075          mGlovePositions[i].init(positionProxyNames[i]);
00076       }
00077    }
00078 
00079    return true;
00080 }

gmtl::Vec3f gadget::Glove::getTipVector GloveData::GloveComponent    component,
int    devNum
 

Returns a vector ponting "out" of the component.

Can be used for selection, etc.

Definition at line 209 of file Glove.cpp.

References getTipTransform.

00210 {
00211    gmtl::Vec3f y_axis(0.0f, 1.0f, 0.0f);
00212    gmtl::Vec3f ret_val(0.0f, 0.0f, 0.0f);
00213 
00214    ret_val = getTipTransform(component, devNum) * y_axis;   // Compute the vector direction
00215    return ret_val;
00216 }

gmtl::Matrix44f gadget::Glove::getTipTransform GloveData::GloveComponent    component,
int    devNum
 

Returns the transform matrix of the specified finger tip in world space wTt = wTb bTj jTt.

Definition at line 222 of file Glove.cpp.

References getJointTransform.

Referenced by getTipVector.

00223 {
00224    gmtl::Matrix44f worldTdij;
00225 
00226    worldTdij=getJointTransform(component,GloveData::DIJ,devNum);
00227 
00228    // TODO: Fix this up
00229    gmtl::Matrix44f dijTtip;
00230    gmtl::setTrans(dijTtip,gmtl::Vec3f(0,0.5f / PositionUnitConversion::ConvertToInches,0));
00231    gmtl::postMult(worldTdij,dijTtip);
00232 
00233    return worldTdij;
00234 }

gmtl::Matrix44f gadget::Glove::getJointTransform GloveData::GloveComponent    component,
GloveData::GloveJoint    joint,
int    devNum
 

Returns the transform matrix of the specified joint in world space wTj = wTb bTj.

Definition at line 240 of file Glove.cpp.

References getGloveData, and mGlovePositions.

Referenced by getTipTransform.

00241 {
00242    gmtl::Matrix44f result;           // The returned matrix.
00243    gmtl::Matrix44f baseTdij;         // Transform from base to dig coord system
00244 
00245    const GloveData data=getGloveData(devNum);
00246 
00247    if(component==GloveData::WRIST)
00248    {
00249       gmtl::identity(baseTdij);      // No transform
00250    }
00251    else
00252    {
00253       baseTdij = data.getLocalTransformMatrix(component,GloveData::MPJ);
00254 
00255       if(joint>=GloveData::PIJ)
00256       {
00257          gmtl::postMult(baseTdij,data.getLocalTransformMatrix(component,GloveData::PIJ));       // mpjTpij
00258 
00259          if(joint>=GloveData::DIJ)
00260          {
00261             gmtl::postMult(baseTdij,data.getLocalTransformMatrix(component,GloveData::DIJ));    // pijTdij
00262          }
00263       }
00264    }
00265 
00266    // Compute return value: result = TIPw = wTb bTd dTt
00267    if(devNum<(int)mGlovePositions.size()){
00268       result=mGlovePositions[devNum]->getData();      // wTb
00269    }
00270    gmtl::postMult(result,baseTdij);                     // bTd
00271 
00272    return result;
00273 }

GloveData gadget::Glove::getGloveData int    devNum
 

Returns a copy of the glove data struct.

Definition at line 275 of file Glove.cpp.

References mDefaultValue, mGloveSamples, and gadget::SampleBuffer< GloveData >::stableBuffer.

Referenced by getJointTransform.

00276 {
00277    SampleBuffer_t::buffer_t& stable_buffer = mGloveSamples.stableBuffer();
00278 
00279    if ( (!stable_buffer.empty()) && (stable_buffer.back().size() > (unsigned)devNum) )  // If have entry && devNum in range
00280    {
00281       return stable_buffer.back()[devNum];
00282    }
00283    else        // No data or request out of range, return default value
00284    {
00285       if ( stable_buffer.empty() )
00286       {
00287          vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) << "Warning: Digital::getGloveData: Stable buffer is empty. If this is not the first read, then this is a problem.\n" << vprDEBUG_FLUSH;
00288       }
00289       else
00290       {
00291          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Warning: Digital::getGloveData: Requested devNum " << devNum << " is not in the range available.  May have configuration error\n" << vprDEBUG_FLUSH;
00292       }
00293       return mDefaultValue;
00294    }
00295 }

void gadget::Glove::addGloveSample const std::vector< GloveData > &    gloveSample [inline]
 

Helper method to add a sample to the sample buffers.

This MUST be called by all glove devices to add a new sample. The data samples passed in will then be modified by any local filters.

Postcondition:
Sample is added to the buffers and the local filters are run on that sample.

Definition at line 97 of file Glove.h.

Referenced by gadget::SimDigitalGlove::updateData.

00098    {
00099       // Locks and then swaps the indices.
00100       mGloveSamples.lock();
00101       mGloveSamples.addSample(gloveSample);
00102       mGloveSamples.unlock();
00103    }

void gadget::Glove::swapGloveBuffers   [inline]
 

Swap the glove data buffers.

Postcondition:
If ready has values, then copy values from ready to stable if not, then stable keeps its old values

Definition at line 109 of file Glove.h.

Referenced by readObject, and gadget::SimDigitalGlove::updateData.

00110    {
00111       mGloveSamples.swapBuffers();
00112    }

const SampleBuffer_t::buffer_t& gadget::Glove::getGloveDataBuffer   [inline]
 

Definition at line 114 of file Glove.h.

00115    {
00116       return mGloveSamples.stableBuffer();
00117    }

virtual std::string gadget::Glove::getBaseType   [inline, virtual]
 

Reimplemented in gadget::InputMixer< InputMixer< InputMixer< Input, Digital >, SimInput >, Glove >.

Definition at line 119 of file Glove.h.

00120    {
00121       return std::string("Glove");
00122    }

vpr::ReturnStatus gadget::Glove::writeObject vpr::ObjectWriter *    writer [virtual]
 

Reimplemented in gadget::InputMixer< InputMixer< InputMixer< Input, Digital >, SimInput >, Glove >.

Definition at line 82 of file Glove.cpp.

References gadget::SampleBuffer< GloveData >::lock, mGloveSamples, gadget::MSG_DATA_GLOVE, gadget::SampleBuffer< GloveData >::stableBuffer, and gadget::SampleBuffer< GloveData >::unlock.

00083 {
00084    SampleBuffer_t::buffer_t& stable_buffer = mGloveSamples.stableBuffer();
00085 
00086    writer->beginTag(Glove::getBaseType());
00087    writer->beginAttribute(gadget::tokens::DataTypeAttrib);
00088       writer->writeUint16(MSG_DATA_GLOVE);                               // Write out the data type so that we can assert if reading in wrong place
00089    writer->endAttribute();
00090 
00091    writer->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00092       writer->writeUint16(stable_buffer.size());         // Write the size of the stable buffer
00093    writer->endAttribute();
00094 
00095    if ( !stable_buffer.empty() )
00096    {
00097       mGloveSamples.lock();
00098       for ( unsigned j=0;j<stable_buffer.size();j++ )
00099       {
00100          writer->beginTag(gadget::tokens::BufferSampleTag);
00101          writer->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00102             writer->writeUint16(stable_buffer[j].size());            // Number of glove values for this entry
00103          writer->endAttribute();
00104 
00105          for ( unsigned i=0;i<stable_buffer[j].size();i++ )       // For each glove value
00106          {
00107             writer->beginTag(gadget::tokens::GloveValue);
00108 
00109             // TODO: If we switch the GloveData to only work with Matrix4x4s, then change this.
00110             for(unsigned component=0;component<GloveData::NUM_COMPONENTS;component++)
00111             {
00112                for(unsigned joint=0;joint<GloveData::NUM_JOINTS;joint++)
00113                {
00114                   float value=stable_buffer[j][i].mAngles[GloveData::NUM_COMPONENTS][GloveData::NUM_JOINTS];
00115                   writer->writeFloat(value);
00116                }
00117             }
00118 
00119             writer->beginAttribute(gadget::tokens::TimeStamp);
00120                writer->writeUint64(stable_buffer[j][i].getTime().usec());           // Write Time Stamp vpr::Uint64
00121             writer->endAttribute();
00122             writer->endTag();
00123          }
00124          writer->endTag();
00125       }
00126       mGloveSamples.unlock();
00127    }
00128    else       // No data or request out of range, return default value
00129    {
00130       vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) << "Warning: Glove::writeObject: Stable buffer is empty. If this is not the first write, then this is a problem.\n" << vprDEBUG_FLUSH;
00131    }
00132    writer->endTag();
00133 
00134    return vpr::ReturnStatus::Succeed;
00135 }

vpr::ReturnStatus gadget::Glove::readObject vpr::ObjectReader *    reader [virtual]
 

Reimplemented in gadget::InputMixer< InputMixer< InputMixer< Input, Digital >, SimInput >, Glove >.

Definition at line 137 of file Glove.cpp.

References gadget::SampleBuffer< GloveData >::addSample, gadget::SampleBuffer< GloveData >::lock, mGloveSamples, gadget::MSG_DATA_GLOVE, swapGloveBuffers, and gadget::SampleBuffer< GloveData >::unlock.

00138 {
00139    vprASSERT(reader->attribExists("rim.timestamp.delta"));
00140    vpr::Uint64 delta = reader->getAttrib<vpr::Uint64>("rim.timestamp.delta");
00141 
00142    reader->beginTag(Glove::getBaseType());
00143    reader->beginAttribute(gadget::tokens::DataTypeAttrib);
00144       vpr::Uint16 temp = reader->readUint16();
00145    reader->endAttribute();
00146 
00147    // XXX: Should there be error checking for the case when vprASSERT() is
00148    // compiled out?  -PH 8/21/2003
00149    vprASSERT(temp==MSG_DATA_GLOVE && "[Remote Input Manager]Not Glove Data");
00150    boost::ignore_unused_variable_warning(temp);
00151 
00152    std::vector<GloveData> dataSample;
00153 
00154    unsigned int numGloveDatas;
00155    vpr::Uint64 timeStamp;
00156    GloveData gloveData;
00157 
00158    reader->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00159       unsigned int numVectors = reader->readUint16();
00160    reader->endAttribute();
00161 
00162    mGloveSamples.lock();
00163    for ( unsigned int i=0;i<numVectors;i++ )
00164    {
00165       reader->beginTag(gadget::tokens::BufferSampleTag);
00166       reader->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00167          numGloveDatas = reader->readUint16();
00168       reader->endAttribute();
00169 
00170       dataSample.clear();
00171 
00172       for ( unsigned int j=0;j<numGloveDatas;j++ )
00173       {
00174          reader->beginTag(gadget::tokens::GloveValue);
00175          for(unsigned int component=0;component<GloveData::NUM_COMPONENTS;component++)
00176          {
00177             for(unsigned int joint=0;joint<GloveData::NUM_JOINTS;joint++)
00178             {
00179                gloveData.mAngles[component][joint]=reader->readFloat();
00180             }
00181          }
00182 
00183          reader->beginAttribute(gadget::tokens::TimeStamp);
00184             timeStamp = reader->readUint64();
00185          reader->endAttribute();
00186          reader->endTag();
00187 
00188          gloveData.setTime(vpr::Interval(timeStamp + delta,vpr::Interval::Usec));
00189          gloveData.calcXforms();
00190          dataSample.push_back(gloveData);
00191       }
00192 
00193       mGloveSamples.addSample(dataSample);
00194       reader->endTag();
00195    }
00196 
00197    mGloveSamples.unlock();
00198    swapGloveBuffers();
00199    reader->endTag();
00200 
00201    return(vpr::ReturnStatus::Succeed);
00202 }

std::vector< GloveData > gadget::Glove::getGloveDataFromDigitalData const std::vector< DigitalData > &    digitalData
 

Utility function to convert a 10 size vector of DigitalData to GloveData.

Definition at line 300 of file Glove.cpp.

Referenced by gadget::SimDigitalGlove::updateData.

00301 {
00302    assert(digitalData.size()>=10);
00303 
00304    std::vector<GloveData> gloveData=std::vector<GloveData>(2);
00305 
00306    for(unsigned int i=0;i<2;i++)
00307    {
00308       for(unsigned int j=0;j<GloveData::NUM_COMPONENTS-1;j++)
00309       {
00310          // Use funky indexing here to access the correct digitalData
00311          if( digitalData[i*(GloveData::NUM_COMPONENTS-1)+j].getDigital() == 1)
00312          {
00313             for(unsigned int k=0;k<GloveData::NUM_JOINTS;k++)
00314             {
00315                gloveData[i].mAngles[j][k]=gmtl::Math::PI_OVER_2;
00316             }
00317          }
00318          else
00319          {
00320             for(unsigned int k=0;k<GloveData::NUM_JOINTS;k++)
00321             {
00322                gloveData[i].mAngles[j][k]=0;
00323             }
00324          }
00325       }
00326    }
00327    
00328    gloveData[0].calcXforms();
00329    gloveData[1].calcXforms();
00330 
00331    return gloveData;
00332 }

void gadget::Glove::operator= const gadget::Glove &    g [inline, protected]
 

Definition at line 132 of file Glove.h.

00132 {;}


Member Data Documentation

SampleBuffer_t gadget::Glove::mGloveSamples [protected]
 

Glove samples.

Definition at line 134 of file Glove.h.

Referenced by getGloveData, readObject, and writeObject.

GloveData gadget::Glove::mDefaultValue [protected]
 

Default glove data to return.

Definition at line 135 of file Glove.h.

Referenced by getGloveData, and Glove.

std::vector<PositionInterface> gadget::Glove::mGlovePositions [protected]
 

Definition at line 137 of file Glove.h.

Referenced by config, getJointTransform, and Glove.


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:26:59 2004 for Gadgeteer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002