Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MoCapLogger.h

Go to the documentation of this file.
00001 #ifndef INCLUDED_MoCapLogger_h_
00002 #define INCLUDED_MoCapLogger_h_
00003 
00004 #include "Behaviors/Controls/ControlBase.h"
00005 #include "Behaviors/Controls/NullControl.h"
00006 #include "Behaviors/Controls/ToggleControl.h"
00007 #include "Behaviors/Controls/StringInputControl.h"
00008 #include "Events/MoCapEvent.h"
00009 #include "Events/TextMsgEvent.h"
00010 #include "Events/EventCallback.h"
00011 #include "Shared/TimeET.h"
00012 #include <fstream>
00013 #include <memory>
00014 
00015 //! Provides display and logging of mocap data
00016 /*! Send a text message event "mocap" to report next mocap event on the console.
00017  *  From the Tekkotsu HAL, that would be the command 'msg mocap'.
00018  *  
00019  *  Logged data is tab delimited with fields: time frame posX posY posZ [ori0 ori1 ori2]
00020  *  
00021  *  Availability of particular frames or orientation data depends on the data source.
00022  *  Orientation data can be either yaw-pitch-roll (in degrees), or the axis component
00023  *  of the quaternion, depending on the state of #rotAxis.  Default is yaw-pitch-roll. */
00024 class MoCapLogger : public ControlBase {
00025 protected:
00026   TimeET lastRefresh; //!< limits rate of GUI updates
00027   NullControl* x; //!< displays current x position
00028   NullControl* y; //!< displays current y position
00029   NullControl* z; //!< displays current z position
00030   NullControl* r0; //!< displays the first rotation component (heading or x)
00031   NullControl* r1; //!< displays the second rotation component (pitch or y)
00032   NullControl* r2; //!< displays the third rotation component (roll or z)
00033   ToggleControl * consoleLog; //!< lets user control whether to dump to console
00034   StringInputControl * fileLog; //!< lets user control whether to dump to file
00035   ToggleControl * rotAxis; //!< lets user control whether they want yaw-pitch-roll or the rotation axis
00036   
00037   std::ofstream file; //!< the output stream if dumping to file
00038   
00039   //! convenience function for updating UI elements
00040   static void rename(ControlBase* c, std::ostream& sstream);
00041   
00042   
00043   // Note how auto_ptr deletes during destruction, thus EventCallback automatically unsubscribes: no cleanup necessary
00044   // We store pointers so we can test for current status, but could use erouter->isListening() instead...
00045   
00046   std::unique_ptr<EventCallbackAs<MoCapEvent> > mocapGUI; //!< triggers callback to gotMoCapEvent()
00047   void gotMoCapGUI(const MoCapEvent& mce); //!< refreshes the ControllerGUI display
00048   
00049   std::unique_ptr<EventCallbackAs<MoCapEvent> > mocapConsole; //!< triggers callback to gotMoCapConsole()
00050   void gotMoCapConsole(const MoCapEvent& mce); //!< forwards to dump(std::cout, mce)... if not for #rotAxis, could make dump() static and just call it directly
00051   
00052   std::unique_ptr<EventCallbackAs<MoCapEvent> > mocapFile; //!< triggers callback to gotMoCapFile()
00053   void gotMoCapFile(const MoCapEvent& mce); //!< forwards to dump(#file, mce)... if not for #rotAxis, could make dump() static and just call it directly
00054   
00055   
00056   // These two are 'always on', just stored directly as members
00057   
00058   EventCallbackAs<TextMsgEvent> txtmsgSingle; //!< triggers callback to gotTxtMsgSingle()
00059   void gotTxtMsgSingle(const TextMsgEvent& txt); //! activates mocapSingle to dump next mocap event, and a timer to report error
00060   
00061   EventCallback mocapSingle; //!< triggers callback to gotMoCapSingle()
00062   void gotMoCapSingle(const EventBase& event); //!< if receives MoCapEvent, dumps to std::cout, otherwise assumes timer and complains about lack of MoCapEvents
00063   
00064 public:
00065   //! Constructor
00066   MoCapLogger() : ControlBase("MoCap Logger","Displays and log motion capture event data (e.g. from Mirage)"), 
00067     lastRefresh(), x(), y(), z(), r0(), r1(), r2(), consoleLog(), fileLog(), rotAxis(), file(), mocapGUI(), mocapConsole(), mocapFile(),
00068     txtmsgSingle(&MoCapLogger::gotTxtMsgSingle,*this),
00069     mocapSingle(&MoCapLogger::gotMoCapSingle,*this)
00070   {
00071     pushSlot(x = new NullControl("X: waiting"));
00072     pushSlot(y = new NullControl("Y: waiting"));
00073     pushSlot(z = new NullControl("Z: waiting"));
00074     pushSlot(r0 = new NullControl("Heading: waiting"));
00075     pushSlot(r1 = new NullControl("Pitch: waiting"));
00076     pushSlot(r2 = new NullControl("Roll: waiting"));
00077     pushSlot(consoleLog = new ToggleControl("Log To Console","Will write MoCapEvent data to the console"));
00078     pushSlot(fileLog = new StringInputControl("Log To File","Enter filename to dump mocap data into"));
00079     pushSlot(rotAxis = new ToggleControl("Rotation Axis","If selected, will display/log the quaternion axis, otherwise heading/pitch/roll"));
00080   }
00081   
00082   //! Serialize data from @a mce into @a os
00083   void dump(std::ostream& os, const MoCapEvent& mce);
00084   
00085   //! called when a child has deactivated and this control should refresh its display, or some other event (such as the user pressing the refresh button) has happened to cause a refresh to be needed
00086   virtual void refresh();
00087   
00088   //! called when this control is being popped from the control stack
00089   virtual void deactivate();
00090   
00091   //! when the user has trigger an "open selection"
00092   /*! default is to return the hilighted control */
00093   virtual ControlBase * doSelect();
00094   
00095   //! Add listener for mocap log requests.
00096   /*! Can't do this from constructor, due to auto-registration that will run at global initialization, possibly before erouter is available */
00097   virtual void registered() {
00098     erouter->addListener(&txtmsgSingle,EventBase::textmsgEGID);
00099   }
00100   
00101 private:
00102   MoCapLogger(const MoCapLogger& o); //!< Do not call
00103   MoCapLogger& operator=(const MoCapLogger& o); //!< Do not call
00104 };
00105 
00106 /*! @file
00107  * @brief Describes MoCapLogger, which provides display and logging of mocap data
00108  * @author ejt (Creator)
00109  */
00110 
00111 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:45 2016 by Doxygen 1.6.3