Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

CreateDriver.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_CreateDriver_h_
00003 #define INCLUDED_CreateDriver_h_
00004 
00005 #include "local/DeviceDriver.h"
00006 #include "local/MotionHook.h"
00007 #include "local/DataSource.h"
00008 #include "local/CommPort.h"
00009 #include "Shared/plist.h"
00010 #include <iostream>
00011 
00012 /*
00013 Specs
00014 Big Endian <---!!!!!
00015 
00016 
00017 Motors: 5
00018 0 - LD1          - 0.5A
00019 1 - LD0          - 0.5A
00020 2 - LD2          - 1.6A
00021 3 - Right Wheel  - 1.0A
00022 4 - Left Wheel   - 1.0A
00023 
00024 Digital Inputs: 4
00025 
00026 Digital Outputs: 3
00027 
00028 LEDs: 2 (Play + Advanced)
00029 
00030 Buttons: 2 (Play + Advanced)
00031 
00032 Sensors: 5
00033 0 - bump right
00034 1 - bump left
00035 2 - wheeldrop right
00036 3 - wheeldrop left
00037 4 - wheeldrop caster
00038 
00039 Wall Sensor
00040 
00041 Cliff Left
00042 
00043 Cliff Right
00044 
00045 Cliff Front Left
00046 
00047 Cliff Front Right
00048 
00049 Distance (per wheel) -- capped if not polled frequent enough
00050 
00051 Angle (per wheel) -- capped if not polled frequent enough
00052 
00053 Voltage
00054 
00055 Current
00056 
00057 Battery Temperature
00058 
00059 Battery Charge
00060 
00061 Battery Capacity (not accurate for alkaline)
00062 */
00063 
00064 typedef struct CreateStatus_t{
00065   unsigned char bumpsWheelDrops;
00066   unsigned char wall;
00067   unsigned char cliffLeft;
00068   unsigned char cliffFrontLeft;
00069   unsigned char cliffFrontRight;
00070   unsigned char cliffRight;
00071   unsigned char virtualWall;
00072   unsigned char overcurrents;
00073   unsigned char ir;
00074   unsigned char buttons;
00075   short distance;
00076   short angle;
00077   unsigned char chargingState;
00078   short voltage;
00079   short current;
00080   unsigned char batteryTemperature;
00081   short batteryCharge;
00082   short batteryCapacity;
00083   short wallSignal;
00084   short cliffLeftSignal;
00085   short cliffFrontLeftSignal;
00086   short cliffFrontRightSignal;
00087   short cliffRightSignal;
00088   unsigned char userDigitalInputs;
00089   short userAnalogInput;
00090   unsigned char chargingSourcesAvailable;
00091   unsigned char oiMode;
00092   unsigned char songNumber;
00093   unsigned char songPlay;
00094   short velocity;
00095   short radius;
00096   short rightVelocity;
00097   short leftVelocity;
00098 } CreateStatus;
00099 
00100 //! description of CreateDriver
00101 class CreateDriver : public virtual DeviceDriver, public MotionHook, public DataSource, public virtual plist::PrimitiveListener {
00102 public:
00103   explicit CreateDriver(const std::string& name)
00104     : DeviceDriver(autoRegisterCreateDriver,name), MotionHook(), DataSource(),
00105       commName(), motionActive(false), sensorsActive(false), lastSensor(), frameNumber(0), createStatus()
00106   {
00107     addEntry("CommPort",commName,"The name of the comm port where output will be sent");
00108   }
00109   virtual ~CreateDriver() {}
00110   
00111   virtual std::string getClassName() const { return autoRegisterCreateDriver; }
00112   
00113   virtual MotionHook* getMotionSink() { return dynamic_cast<MotionHook*>(this); }
00114   virtual void getSensorSources(std::map<std::string,DataSource*>& sources) {
00115     sources.clear();
00116     sources["Sensors"]=dynamic_cast<DataSource*>(this);
00117   }
00118   
00119   virtual void motionStarting();
00120   virtual void motionStopping();
00121   virtual void motionCheck(const float outputs[][NumOutputs]);
00122 
00123   virtual unsigned int nextTimestamp();
00124   virtual const std::string& nextName() { return instanceName; }
00125   virtual unsigned int getData(const char *& payload, unsigned int& payloadSize, unsigned int& timestamp, std::string& name);
00126   virtual void setDataSourceThread(LoadDataThread* th);
00127   
00128   virtual void plistValueChanged(const plist::PrimitiveBase& pl);
00129   
00130   plist::Primitive<std::string> commName;
00131   
00132 protected:
00133   virtual void connect();
00134 
00135   virtual unsigned char readChar(std::istream &is);
00136   virtual short readShort(std::istream &is);
00137   virtual int readPacket(std::istream &is, const char &type);
00138   
00139   //! forwards call to DataSource::providingOutput() if the index is valid
00140   void provideOutput(unsigned int idx) { if(idx<NumOutputs) providingOutput(idx); }
00141   //! forwards call to DataSource::ignoringOutput() if the index is valid
00142   void ignoreOutput(unsigned int idx) { if(idx<NumOutputs) ignoringOutput(idx); }
00143   
00144   //! converts the value @a s from specified input's signal to voltage
00145   virtual float getAnalog(unsigned int inputIdx, unsigned char s);
00146   //! converts the value @a cur and @a latch to the output format (0 if low, 0.5 if high but has been low, 1 if consistent high)
00147   virtual float getDigital(unsigned int inputIdx, unsigned char cur, unsigned char latch);
00148   
00149   bool motionActive;
00150   bool sensorsActive;
00151   std::string lastSensor;
00152   unsigned int frameNumber;
00153   
00154 private:
00155   //! holds the class name, set via registration with the DeviceDriver registry
00156   static const std::string autoRegisterCreateDriver;
00157 
00158   CreateStatus createStatus;
00159 };
00160 
00161 /*! @file
00162  * @brief 
00163  * @author Ethan Tira-Thompson (ejt) (Creator)
00164  *
00165  * $Author: bensont $
00166  * $Name: tekkotsu-4_0 $
00167  * $Revision: 1.3 $
00168  * $State: Exp $
00169  * $Date: 2007/11/18 19:16:10 $
00170  */
00171 
00172 #endif

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4