orca-robotics INTRODUCTION Overview Download and Install Documentation REPOSITORY Interfaces Drivers Libraries Utilities Software Map DEVELOPER Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
segwayrmpacfr/driver.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef HYDRO_SEGWAYRMP_ACFR_H 00012 #define HYDRO_SEGWAYRMP_ACFR_H 00013 00014 #include <hydrointerfaces/segwayrmp.h> 00015 #include "rmpdriverconfig.h" 00016 #include "rmpio.h" 00017 #include "rxdata.h" 00018 #include "unitconverter.h" 00019 #include "commandhistory.h" 00020 00021 namespace segwayrmpacfr 00022 { 00023 00024 // 00025 // An implementation of HwHandler that knows how to talk Segway's 00026 // protocol. Requires a hardware interface implementation to be 00027 // passed to the constructor. 00028 // 00029 // All public member functions throw hydrointerfaces::SegwayRmp::Exceptions on error conditions. 00030 // 00031 class Driver : public hydrointerfaces::SegwayRmp 00032 { 00033 public: 00034 00035 Driver( const hydroutil::Context& context ); 00036 virtual ~Driver(); 00037 00038 // from SegwayRmp 00039 virtual void enable(); 00040 virtual bool read( Data& data ); 00041 virtual void write( const Command& command ); 00042 virtual void getStatus( std::string &status, bool &isWarn, bool &isFault ); 00043 virtual void applyHardwareLimits( double &maxForwardSpeed, 00044 double &maxReverseSpeed, 00045 double &maxTurnrate, 00046 double &maxLateralAcceleration ); 00047 00048 // Custom method 00049 // Shuts down the motors 00050 void shutdown(); 00051 00052 private: 00053 00054 void setMaxVelocityScaleFactor( double scale ); 00055 void setMaxTurnrateScaleFactor( double scale ); 00056 void setMaxAccelerationScaleFactor( double scale ); 00057 void setMaxCurrentLimitScaleFactor( double scale ); 00058 void resetAllIntegrators(); 00059 00060 void setGainSchedule( int sched ); 00061 void enableBalanceMode( bool enable ); 00062 00063 double maxSpeed(); 00064 // max turnrate depends on the speed 00065 double maxTurnrate( double speed ); 00066 00067 void applyScaling( const Command& original, Command &scaledCommand ); 00068 00069 // Checks that we're allowed to command the RMP in this operational mode (balance/tractor). 00070 // Throws exceptions if we're trying to do the wrong thing. 00071 void checkOperationalMode(); 00072 00073 // Reads a set of CAN packets, returns the result 00074 RxData readData(); 00075 void calculateIntegratedOdometry( const RxData &prevData, const RxData &thisData ); 00076 // fills up the Data class (understood externally) 00077 Data getData(); 00078 00079 void sendMotionCommandPacket( const Command& command ); 00080 void sendStatusCommandPacket( ConfigurationCommand commandId, uint16_t param ); 00081 00082 // The RMP reports its last received command. Check that this is what we sent. 00083 void checkReceivedCommand( const RxData &rxData ); 00084 00085 // Configuration 00086 RmpDriverConfig config_; 00087 00088 // driver/hardware interface 00089 RmpIo* rmpIo_; 00090 00091 // Remember the last commands we gave, so that we can check that the 00092 // received-commands reported by the Segway were actually sent. 00093 CommandHistory commandHistory_; 00094 00095 // integrated odometry (in SI units) 00096 double odomX_; 00097 double odomY_; 00098 double odomYaw_; 00099 00100 // Converts between units 00101 // stored as a pointer because it needs model number to be initialized 00102 UnitConverter* converter_; 00103 00104 // Most-recently-received data 00105 // stored as a pointer because it needs model number to be initialized 00106 RxData* rxData_; 00107 00108 // For logging CAN data for debugging 00109 std::ofstream *canDataFile_; 00110 00111 hydroutil::Context context_; 00112 }; 00113 00114 // Used for dynamically loading driver 00115 class Factory : public hydrointerfaces::SegwayRmpFactory 00116 { 00117 public: 00118 hydrointerfaces::SegwayRmp* 00119 createDriver( const hydroutil::Context &context ) const 00120 { 00121 return new Driver( context ); 00122 } 00123 }; 00124 00125 } // namespace 00126 00127 // Used for dynamically loading driver 00128 extern "C" { 00129 hydrointerfaces::SegwayRmpFactory *createDriverFactory(); 00130 } 00131 00132 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)