00001 #ifndef ROBOTS_SCORBOT_INTERFACE_H 00002 #define ROBOTS_SCORBOT_INTERFACE_H 00003 00004 #include "Component/ModelComponent.H" 00005 #include "Devices/Serial.H" 00006 #include <pthread.h> 00007 #include <map> 00008 00009 class ScorbotInterface : public ModelComponent 00010 { 00011 public: 00012 00013 enum Joint_t {Base=0, Shoulder=1, Elbow=2, Wrist1=3, Wrist2=4, Gripper=5, Slider=6}; 00014 typedef std::map<Joint_t, int32> encoderVals_t; 00015 typedef std::map<Joint_t, float> pwmVals_t; 00016 00017 ScorbotInterface(OptionManager& mgr, 00018 const std::string& descrName = "ScorbotInterface", 00019 const std::string& tagName = "ScorbotInterface"); 00020 00021 //! Disables the motor interface 00022 ~ScorbotInterface(); 00023 00024 //! Sets all desired joint positions to their current positions at startup 00025 void start2(); 00026 00027 //! Set the joint to move to the given encoder position in the given amount of time 00028 void setJoint(Joint_t joint, int32 encoderPos, int32 time_ms); 00029 00030 //! A convenience function to set multiple joint positions 00031 /*! This function just loops over all positions in pos and sets them using setJointPos() !*/ 00032 void setJoints(encoderVals_t pos, int32 time_ms); 00033 00034 //! Get the position of a joint 00035 int32 getEncoder(Joint_t joint); 00036 00037 //! Get the position of all joints 00038 encoderVals_t getEncoders(); 00039 00040 //! Turn on/off the motors at the Scorpower box 00041 void setEnabled(bool enabled); 00042 00043 //! Reset all encoders to 0, and set the desired position of all joints to 0 00044 void resetEncoders(); 00045 00046 //! Get the current PWM value of a joint 00047 float getPWM(Joint_t joint); 00048 00049 //! Get the current PWM values of all joints 00050 pwmVals_t getPWMs(); 00051 00052 //! Set the PID control params for a joint 00053 void setControlParams(Joint_t joint, 00054 float pGain, float iGain, float dGain, float maxI, float maxPWM, float pwmOffset); 00055 00056 //! Get the PID values for a joint from the microcontroller 00057 void getPIDVals(Joint_t joint, 00058 float &pGain, float &iGain, float &dGain, float &maxI, float &maxPWM, float &pwmOffset); 00059 00060 //! Get the current target position and velocity 00061 void getTuningVals(Joint_t joint, 00062 int32 &targetPos, int32 &targetVel, float& gravityCompensation); 00063 00064 //! Set the gravity compensation parameters 00065 void setGravityParameters(int32 upperArmMass, int32 foreArmMass, float compensationScale); 00066 00067 //! Get the current gravity compensation parameters 00068 void getGravityParameters(int32 &upperArmMass, int32 &foreArmMass, float &compensationScale); 00069 00070 private: 00071 nub::soft_ref<Serial> itsSerial; 00072 pthread_mutex_t itsSerialMutex; 00073 }; 00074 00075 #endif // ROBOTS_SCORBOT_INTERFACE_H 00076