Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

MomentumWheel.h

Go to the documentation of this file.
00001 /************************************************************************************************/
00002 /*! \file MomentumWheel.h
00003 *  \brief The MomentumWheel class provides the interface for h/w momentum wheels.
00004 *  \author $Author: jayhawk_hokie $
00005 *  \version $Revision: 1.30 $
00006 *  \date    $Date: 2007/07/24 09:39:38 $
00007 ************************************************************************************************/
00008 /*! 
00009 *
00010 ************************************************************************************************/
00011 
00012 #ifndef __SSSL_MOMENTUMWHEEL_H__
00013 #define __SSSL_MOMENTUMWHEEL_H__
00014 
00015 // System Includes
00016         #include <string>
00017         #include <map>
00018 
00019 // DSACSS Includes
00020         #include "PhysicalMomentumWheel.h"
00021         #include <Base/Actuator.h>
00022         #include <matrix/Matrix.h>
00023         #include <Utils/Misc.h>
00024         #include <Logging/WheelHistory.h>
00025         // Xml Parsing
00026         #include <dsacssinterface.h>
00027 
00028 using namespace std;
00029 using namespace O_SESSAME;
00030 
00031 /*! Class to interface with momentum wheels */
00032 class MomentumWheel : public Actuator  
00033 {
00034 public:
00035         //////////////////////////////////////////
00036         // Contructors/Deconstructors
00037         //////////////////////////////////////////
00038 
00039         /*! \brief Default Constructor */
00040         MomentumWheel( );
00041     
00042         /*! \brief Constructor that accepts a cfgBody variable sent from the cfgPars function 
00043          *  @param handle is a TiXmlHandle type that has the wheel configuration parameters. 
00044          *  @param wheel is a string that specifies the wheel.
00045          */
00046         MomentumWheel( TiXmlHandle handle, string wheel );
00047     
00048         /*! \brief Deconstructor */
00049         virtual ~MomentumWheel( );
00050 
00051         //////////////////////////////////////////
00052         // Facilitators
00053         //////////////////////////////////////////
00054 
00055         /*! \brief Initialize the wheels */
00056         int Initialize( TiXmlHandle handle, string wheel );   
00057  
00058         /*! \brief Deinitialize the wheels */
00059         int Deinitialize( );   
00060 
00061         /*! \brief Stop the wheel
00062          *  Calls PhysicalMomentumWheel::Stop( )
00063          */
00064         int Stop( );
00065 
00066         /*! \brief Enable torque mode for the wheel motor.
00067          *  Calls PhysicalMomentumWheel::TorqueCommand( int _power )
00068          *  @param _power is the voltage to be commanded in Torque Mode
00069          */
00070         int TorqueCommand( double _power );
00071 
00072         /*! \brief Start the speed reading routine of the motor in a separate thread. Calls
00073          *  PhysicalMomentumWheel::StartSpeedQuery( )
00074          */
00075         void StartSpeedQuery( );
00076         
00077         /*! \brief Stop the speed reading routine of the motor.  This function does not need to be called a t the end of the program.
00078          *  Calls PhysicalMomentumWheel::StopSpeedQuery( )
00079          *  The thread will be closed automatically when the program ends. 
00080          */
00081         void StopSpeedQuery( );
00082         
00083         /*! \brief Set the torque applied to the wheel
00084          *  Calls PhysicalMomentumWheel::CommandWheelTorque(  double _wheelTorque )
00085          *  @param wheelTorque The desired wheel torque in N-m
00086          */
00087         void SetWheelTorque( double wheelTorque ); 
00088 
00089         /*! \brief Set the desired wheel speed. The wheel controller is running in a thread and this function
00090          *  updates the desired wheel rate value passed to the wheel controller.
00091          *  Calls PhysicalMomentumWheel::CommandWheelSpeed( double wheelOmega )
00092          *  @param wheelOmega The desired wheel angular velocity in rad/sec 
00093          */
00094         void SetWheelSpeed( double wheelOmega );   // will change wheelOmega if set different due to saturation
00095         
00096         /*! \brief Start the PID Control Thread 
00097          *  Calls PhysicalMomentumWheel::StartPID( )
00098          */
00099         void StartPID( );
00100         
00101         /*! \brief End the PID Control Thread (will be called by the deconstructor)
00102          *  Calls PhysicalMomentumWheel::StopPID( )
00103          */
00104         void StopPID( );
00105         
00106         /*! \brief Set the old-style torque applied to the wheel
00107          *  Calls PhysicalMomentumWheel::CommandSystemTorque( double wheelTorque )
00108          *  @param wheelTorque The desired wheel torque in N-m
00109          */
00110         void SetSystemTorque(double wheelTorque);
00111     
00112         /*! \brief Set the wheel speed coefficients. The wheel speed coefficients are determined from the characterization of each wheel motor.
00113          *  Calls PhysicalMomentumWheel::SetWheelSpeedCoefficients( Vector _Coefficients1, Vector _Coefficients2, Vector _Coefficients3, Vector _Coefficients4 )
00114          *  @param _Coefficients1 a 4x1 vector of constants
00115          *  @param _Coefficients2 a 3x1 vector of constants
00116          *  @param _Coefficients3 a 3x1 vector of constants
00117          *  @param _Coefficients4 a 4x1 vector of constants
00118          */
00119         void SetWheelSpeedCoefficients( Vector _Coefficients1, Vector _Coefficients2, Vector _Coefficients3, Vector _Coefficients4 );
00120 
00121         //////////////////////////////////////////
00122         // Mutators
00123         //////////////////////////////////////////
00124     
00125         /*! \brief Set the address of the wheel on its daisy chain
00126          *  Calls PhysicalMomentumWheel::SetWheelAddress( int wheelAddress )
00127          *  @param wheeladdress an integer describing the address of the wheel*/
00128         void SetWheelAddress( int wheeladdress );
00129     
00130         /*! \brief Set the axis of rotation for the wheel
00131          *  @param newWheelAxis a 3x1 vector describing the wheel axis*/
00132         void SetWheelAxis( const Vector& newWheelAxis );
00133 
00134         /*! \brief Set communications port 
00135          *  Calls PhysicalMomentumWheel::SetDaisyChainNumber( int daisyChain )
00136          *  @param daisyChain A int specifying the daisy chain number 
00137          */
00138         void SetChainNumber( int daisyChain );
00139         
00140         /*! \brief Set communications port 
00141          *  Calls PhysicalMomentumWheel::SetDaisyChainPort( string DaisyChainPort );
00142          *  @param Port A string specifying the RS232 port ex. /dev/ttyUSB0
00143          */
00144         void SetPort( string Port );
00145     
00146         /*! \brief Set the bias wheel wheel speed for a Momentum wheel 
00147          *  Calls PhysicalMomentumWheel::SetBiasSpeed( double BiasSpeed )
00148          *  @param BiasSpeed A double specifying the bias speed
00149          */
00150         void SetBiasSpeed( double BiasSpeed );
00151     
00152         /*! \brief Set the axial inertia for a Momentum wheel
00153          *  Calls PhysicalMomentumWheel::SetAxialInertia( double axialInertia )
00154          *  @param axialInertia A double specifying the axial inertia kg-m^2
00155          */
00156         void SetAxialInertia( double axialInertia );
00157 
00158         /*! \brief Set the momentum wheel torque limits 
00159          *  Calls PhysicalMomentumWheel::SetWheelTorqueLimits( const double& minWheelTorque, const double& maxWheelTorque )
00160          *  @param torque_limit_low A double specifying low torque limit N-m
00161          *  @param torque_limit_high A double specifying high torque limit N-m
00162          */
00163         void SetWheelTorqueLimits( double torque_limit_low, double torque_limit_high );    
00164 
00165         /*! \brief Set the momentum wheel string name 
00166          *  Calls PhysicalMomentumWheel::SetWheelName( string _wheelName )
00167          *  @param _wheelName A string naming the wheel
00168          */
00169         void SetWheelName( string _wheelName );    
00170         
00171         //////////////////////////////////////////
00172         // Inspectors
00173         //////////////////////////////////////////
00174 
00175         /*! \brief Get the current angular speed of the wheel, returns the wheel speed in rad/sec.
00176          *  Calls PhysicalMomentumWheel::GetWheelSpeed( double& Speed, double& measTime )
00177          *  @param Speed double set to the current wheel speed
00178          *  @param measTime double set to the number of seconds since unix epoch when the velocity waas measured*/
00179         void GetWheelSpeed( double& Speed, double& measTime );
00180 
00181         /*! \brief Get the current torque output to the wheel, returns the value in N-m. This is not necessarily the
00182          *  torque being applied to the system. This value is determined from the smart motors. 
00183          *  Calls PhysicalMomentumWheel::QueryWheelTorque( )
00184          */
00185         double GetWheelTorque( );
00186 
00187         /*! \brief Get the axis of the wheel, returns a 3x1 vector */
00188         Vector GetWheelAxis( ) const;
00189 
00190         /*! \brief Returns an integer representing the total number of momentum wheels instantiated*/
00191         int GetWheelCount( );  
00192 
00193         /*! \brief Returns a double representing the axial inertia of the wheel in kg-m^2
00194          *  Calls PhysicalMomentumWheel::GetAxialInertia( )
00195          */
00196         double GetAxialInertia( );
00197         
00198         /*! \brief Returns a string representing the wheel name
00199          *  Calls PhysicalMomentumWheel::GetWheelName( )
00200          */
00201         string GetWheelName( );
00202         
00203         /*! \brief Get the file desciptor of the wheel. 
00204          *  Calls PhysicalMomentumWheel::GetWheelFD( )
00205          */
00206         int GetWheelFD( );
00207         
00208         /*! \brief Get the current used by the motor. 
00209          *  Calls PhysicalMomentumWheel::GetAmps( )
00210          */
00211         double GetAmps( );
00212         
00213         /*! \brief Get the voltage at the motor. 
00214          *  Calls PhysicalMomentumWheel::GetVolts( )
00215          */
00216         double GetVolts();
00217    
00218 
00219         //////////////////////////////////////////
00220         // Data Logging
00221         //////////////////////////////////////////
00222 
00223         /*! \brief Start the wheel speed data collection routine 
00224          *  Each wheel's speed query needs to be started individually.  The performance occurs
00225          *  when the spart calls for each wheel are spread evenly over  sec (value subject to change)
00226          */
00227         void StartWheelSpeedDataLogging( );
00228 
00229         /*! \brief Friend function split in a new thread that queries the wheel speed repeatedly.  It begins running in the
00230          *  StartSpeedQuery function. Velocity by Position: This function determines the velocity of the wheel by differentiating
00231          *  the position reported by the wheel.  The function asks the wheel for its
00232          *  position and then gets the time of day at which the measurement is reported.
00233          *  The code then delays for a small time and asks for the position and gets
00234          *  the time again.  The velocity is then calculated by dividing the change
00235          *  in position byt he change in time.  The return value is the velocity in rev/sec.
00236          *
00237          *  @param arg the argument is set to be a "this" pointer cast as a void pointer
00238          */
00239         friend void* DataWheelSpeed( void* arg );
00240 
00241         /*! \brief Stop the speed reading routine of the motor.  This function does not need to be called a t the end of the program.
00242          *  The thread will be closed automatically when the program ends.
00243          */
00244         void StopWheelSpeedDataLogging( );
00245 
00246 
00247 
00248         /*! \brief Value-Definitions of the different string values */
00249         enum StringValue{ ON,
00250                         OFF };
00251 
00252         /*! \brief Map to associate the strings with the enum values */
00253         map<string, StringValue> s_mapStringValues;
00254  
00255 protected: 
00256     
00257     
00258 private:
00259 
00260         /*! \brief Static member integer representing the total number of wheels instantiated*/
00261         static int m_WheelCount;
00262 
00263         /*! \brief 3x1 vector corresponding to the axis normal to the wheel*/
00264         Vector m_WheelAxis; 
00265 
00266         /*! \brief Member PhysicalMomentumWheel object*/
00267         PhysicalMomentumWheel m_PhysicalMomentumWheel;
00268 
00269         /*! \brief Member WheelHistory in MomentumWheel.h, saving time and wheel speed for 
00270          *   for initialized wheel. */
00271         WheelHistory *m_WheelHistory;
00272 
00273         /*! \brief Member string in MomentumWheel.h, ON or OFF for logging. */
00274         string m_LogData;
00275 
00276         /*! \brief Member pthread for Wheel Speed Data Logging. */
00277         pthread_t m_DataSpeedThreadID;
00278 
00279         /*! \brief Memeber mutex lock variable for Data*/
00280         pthread_mutex_t m_DataMutex;
00281 
00282         int m_exitConditionData;
00283 };
00284 
00285 #endif 
00286 // Do not change the comments below - they will be added automatically by CVS
00287 /*****************************************************************************
00288 *       $Log: MomentumWheel.h,v $
00289 *       Revision 1.30  2007/07/24 09:39:38  jayhawk_hokie
00290 *       Removed matrix and vector pointers.
00291 *       
00292 *       Revision 1.29  2007/05/30 23:48:43  jayhawk_hokie
00293 *       Modified thread termination.
00294 *       
00295 *       Revision 1.28  2007/03/27 19:07:16  jayhawk_hokie
00296 *       Updated Momentum Wheels.
00297 *       
00298 *       Revision 1.27  2007/02/06 20:48:16  jayhawk_hokie
00299 *       Update for XML parsing for Momentum Wheels.
00300 *       
00301 *       Revision 1.26  2005/02/25 18:40:52  cakinli
00302 *       Created Makefiles and organized include directives to reduce the number of
00303 *       include paths.  Reorganized libraries so that there is now one per source
00304 *       directory.  Each directory is self-contained in terms of its Makefile.
00305 *       The local Makefile in each directory includes src/config.mk, which has all
00306 *       the definitions and general and pattern rules.  So at most, to see what
00307 *       goes into building a target, a person needs to examine the Makefile in
00308 *       that directory, and ../config.mk.
00309 *       
00310 *       Revision 1.25  2004/03/04 23:13:09  bstreetman
00311 *       Big changes! new functions and functionality.  FUnctions: GetVolts() -- get motor voltage.  GetAmps() -- ge current used by motors.  GetWheelFD() -- get the wheel comm file descriptor.  SetBiasSpeed() -- Set the bias speed used in momentum wheel mode.  SetSystemTorque() -- old style torque function, used mainly by me.  friend RUnTorqueCOntroller() -- new torque controller, runs in a separate thread.  StartTorqueController() -- spawns torque thread, called internally.  Other Changes:  config parameters -- added BiasSpeed confige parameter, sets bias speed and commands the wheel to go there.  SetWheelSpeed() -- no more PID controller, uses a function created by the data i took.  SetWHeelTorque() -- happens in a better way now based on tons of data and hdot = g.
00312 *       
00313 *       Revision 1.24  2003/12/16 17:20:26  bstreetman
00314 *       A bit o' fall cleaning.  Just look at how pretty it is.
00315 *       
00316 *       Revision 1.23  2003/11/14 20:15:44  bstreetman
00317 *       Apparently I broke the PID controller with the last update, but now it works again.  I also added a StopPID() function to end the thread of the PID controller.  To spin up to 900 rpm (about half speed) use SetWheelSpedd(92).  If you wnat to then switch to torque control sleep for about 12 seconds and run StopPID() and you should be good to go.
00318 *       
00319 *       Revision 1.22  2003/10/17 20:01:33  bstreetman
00320 *       Wheel code updated to reflect hardware changes.  All wheels now considered on separate serial port.  Wheels also changed to read wheel velocity in a separate thread.  Thread is fired off by StartSpeedQuery() function.  Wheel Speed and measurement timestamp are set by the function GetWheelSpeed(speed, time).  See SpeedTest.cpp in the work directory for a sample using the new code.
00321 *       
00322 *       Revision 1.21  2003/08/18 19:31:17  mavandyk
00323 *       Fixed config parsing.
00324 *       
00325 *       Revision 1.20  2003/08/06 21:18:48  bstreetman
00326 *       Updated to work with config parser
00327 *       
00328 *       Revision 1.19  2003/08/04 21:25:23  bstreetman
00329 *       Now with doxygen-style comments
00330 *       
00331 *       Revision 1.18  2003/08/01 20:21:20  bstreetman
00332 *       Cleaned and streamlined all code. Reduced warning and outputs. CMG and Momentum Wheels now no longer accept a global integer in initialization.  The file descriptor is now set and held internally.
00333 *       
00334 *       Revision 1.17  2003/07/28 17:54:00  bstreetman
00335 *       Change some pass-by-reference to pass-by-value
00336 *       
00337 *       Revision 1.16  2003/07/21 20:15:30  bstreetman
00338 *       Updates
00339 *       
00340 *       Revision 1.15  2003/07/09 20:24:33  cskelton
00341 *       Corrected Initialization and Deconstruction
00342 *       
00343 *       Revision 1.14  2003/07/08 21:32:26  cskelton
00344 *       Added functionality, initialization fixed, command torque works
00345 *       
00346 *       Revision 1.13  2003/07/07 19:34:08  cskelton
00347 *       Removed virtual from functions
00348 *       
00349 *       Revision 1.12  2003/07/04 16:02:00  nicmcp
00350 *       Added the AxialInertia from PhysicalMomentumwheel.h
00351 *       
00352 *       Revision 1.11  2003/07/04 15:54:51  simpliciter
00353 *       Fixed capitalization.
00354 *       
00355 *       Revision 1.10  2003/07/03 19:47:49  nicmcp
00356 *       Added an instance counter
00357 *       
00358 *       Revision 1.9  2003/07/02 22:02:12  bstreetman
00359 *       Improve functionality and made to work with the c hardware code.
00360 *       
00361 *       Revision 1.8  2003/07/01 20:54:18  bstreetman
00362 *       Fixed Small #include problem
00363 *       
00364 *       Revision 1.7  2003/07/01 19:56:09  cskelton
00365 *       Added Hardware software support
00366 *       
00367 *       Revision 1.6  2003/07/01 19:19:43  cskelton
00368 *       Debugged to compile
00369 *       
00370 *       Revision 1.5  2003/06/30 17:22:20  cskelton
00371 *       Updated functions and herader file
00372 *       
00373 *       Revision 1.3  2003/06/30 15:34:23  cskelton
00374 *       Added PMW member
00375 *       
00376 *       Revision 1.2  2003/06/19 21:29:58  simpliciter
00377 *       Updated from Andy's generic layout.
00378 *       
00379 *       Revision 1.1  2003/06/13 15:24:33  simpliciter
00380 *       Initial submission.
00381 *       
00382 *
00383 ******************************************************************************/

Generated on Wed Sep 5 12:54:22 2007 for DSACSS Operational Code by  doxygen 1.3.9.1