00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2010 00004 * 00005 * Fraunhofer Institute for Manufacturing Engineering 00006 * and Automation (IPA) 00007 * 00008 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00009 * 00010 * Project name: care-o-bot 00011 * ROS stack name: cob_driver 00012 * ROS package name: cob_powercube_chain 00013 * Description: An interface class to the Powercube-hardware implementing armInterface. 00014 * 00015 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00016 * 00017 * Author: Felix Geibel, email:Felix.Geibel@gmx.de 00018 * Supervised by: Alexander Bubeck, email:alexander.bubeck@ipa.fhg.de 00019 * 00020 * Date of creation: Apr 2007 00021 * ToDo: 00022 * 00023 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00024 * 00025 * Redistribution and use in source and binary forms, with or without 00026 * modification, are permitted provided that the following conditions are met: 00027 * 00028 * * Redistributions of source code must retain the above copyright 00029 * notice, this list of conditions and the following disclaimer. 00030 * * Redistributions in binary form must reproduce the above copyright 00031 * notice, this list of conditions and the following disclaimer in the 00032 * documentation and/or other materials provided with the distribution. 00033 * * Neither the name of the Fraunhofer Institute for Manufacturing 00034 * Engineering and Automation (IPA) nor the names of its 00035 * contributors may be used to endorse or promote products derived from 00036 * this software without specific prior written permission. 00037 * 00038 * This program is free software: you can redistribute it and/or modify 00039 * it under the terms of the GNU Lesser General Public License LGPL as 00040 * published by the Free Software Foundation, either version 3 of the 00041 * License, or (at your option) any later version. 00042 * 00043 * This program is distributed in the hope that it will be useful, 00044 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00045 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00046 * GNU Lesser General Public License LGPL for more details. 00047 * 00048 * You should have received a copy of the GNU Lesser General Public 00049 * License LGPL along with this program. 00050 * If not, see <http://www.gnu.org/licenses/>. 00051 * 00052 ****************************************************************/ 00053 00054 #ifndef __POWER_CUBE_CTRL_H_ 00055 #define __POWER_CUBE_CTRL_H_ 00056 00057 //#define __LINUX__ 00058 00059 #include <libm5api/m5apiw32.h> 00060 #include <cob_powercube_chain/moveCommand.h> 00061 #include <cob_powercube_chain/PowerCubeCtrlParams.h> 00062 //#include "Utilities/mutex.h" 00063 00064 #include <iostream> 00065 #include <stdio.h> 00066 #include <stdlib.h> 00067 #include <vector> 00068 #include <string> 00069 00070 //#include <pthread.h> 00071 00072 // using namespace std; 00073 // Needs the Following Libraries to Compile: 00074 // -lm5api 00075 // -ldevice 00076 // -lutil 00077 // -lntcan 00078 00079 00080 //------------------------------------------------------------------------- 00081 // Defines 00082 // ------------------------------------------------------------------------- 00083 class PowerCubeCtrlParams 00084 { 00085 00086 public: 00087 PowerCubeCtrlParams():m_DOF(0){;} 00088 00089 int Init(std::string CanModule, std::string CanDevice, int BaudRate, std::vector<int> ModuleIDs) 00090 { 00091 SetCanModule(CanModule); 00092 SetCanDevice(CanDevice); 00093 SetBaudRate(BaudRate); 00094 SetNumberOfDOF(ModuleIDs.size()); 00095 for (unsigned int i=0; i < GetNumberOfDOF() ;i++) 00096 { 00097 m_IDModulesNumber.push_back(ModuleIDs[i]); 00098 } 00099 return 0; 00100 } 00101 00102 //DOF 00103 void SetNumberOfDOF(unsigned int DOF){m_DOF=DOF;} 00104 unsigned int GetNumberOfDOF(){return m_DOF;} 00105 00106 //Can Module 00107 void SetCanModule(std::string CanModule){m_CanModule = CanModule;} 00108 std::string GetCanModule(){return m_CanModule;} 00109 00110 //Can Device 00111 void SetCanDevice(std::string CanDevice){m_CanDevice = CanDevice;} 00112 std::string GetCanDevice(){return m_CanDevice;} 00113 00114 //BaudRate 00115 void SetBaudRate(int BaudRate){m_BaudRate=BaudRate;} 00116 int GetBaudRate(){return m_BaudRate;} 00117 00118 //ModuleIDs 00119 std::vector<int> GetModuleIDVector(){return m_IDModulesNumber;} 00120 int GetModuleID(unsigned int no){if (no < GetNumberOfDOF()) return m_IDModulesNumber[no]; else return -1;} 00121 int SetModuleID(unsigned int no, int id){ 00122 if (no < GetNumberOfDOF()) 00123 { 00124 m_IDModulesNumber[no] = id; 00125 return 0; 00126 } 00127 else 00128 return -1; 00129 00130 } 00131 00132 //Angular Constraints 00133 int SetUpperLimits(std::vector<double> UpperLimits) 00134 { 00135 if (UpperLimits.size() == GetNumberOfDOF()) 00136 { 00137 m_UpperLimits = UpperLimits; 00138 return 0; 00139 00140 } 00141 return -1; 00142 } 00143 int SetLowerLimits(std::vector<double> LowerLimits) 00144 { 00145 if (LowerLimits.size() == GetNumberOfDOF()) 00146 { 00147 m_LowerLimits = LowerLimits; 00148 return 0; 00149 } 00150 return -1; 00151 } 00152 int SetAngleOffsets(std::vector<double> AngleOffsets) 00153 { 00154 if (AngleOffsets.size() == GetNumberOfDOF()) 00155 { 00156 m_Offsets = AngleOffsets; 00157 return 0; 00158 } 00159 return -1; 00160 } 00161 int SetMaxVel(std::vector<double> MaxVel) 00162 { 00163 if (MaxVel.size() == GetNumberOfDOF()) 00164 { 00165 m_MaxVel = MaxVel; 00166 return 0; 00167 } 00168 return -1; 00169 } 00170 int SetMaxAcc(std::vector<double> MaxAcc) 00171 { 00172 if (MaxAcc.size() == GetNumberOfDOF()) 00173 { 00174 m_MaxAcc = MaxAcc; 00175 return 0; 00176 } 00177 return -1; 00178 } 00179 00180 std::vector<double> GetUpperLimits(){return m_UpperLimits;} 00181 std::vector<double> GetLowerLimits(){return m_LowerLimits;} 00182 std::vector<double> GetAngleOffsets(){return m_Offsets;} 00183 std::vector<double> GetMaxAcc(){return m_MaxAcc;} 00184 std::vector<double> GetMaxVel(){return m_MaxVel;} 00185 00186 00187 private: 00188 std::vector<int> m_IDModulesNumber; 00189 unsigned int m_DOF; 00190 std::string m_CanModule; 00191 std::string m_CanDevice; 00192 int m_BaudRate; 00193 std::vector<double> m_Offsets; 00194 std::vector<double> m_UpperLimits; 00195 std::vector<double> m_LowerLimits; 00196 std::vector<double> m_MaxVel; 00197 std::vector<double> m_MaxAcc; 00198 }; 00199 00200 /* uncomment the following line to switch on debugging output: */ 00201 // #define _POWER_CUBE_CTRL_DEBUG 00202 00203 class PowerCubeCtrl 00204 { 00205 public: 00206 00207 PowerCubeCtrl(); 00208 ~PowerCubeCtrl(); 00209 00210 bool Init(PowerCubeCtrlParams * params); 00211 00212 bool isInitialized() const { return m_Initialized; } 00213 00214 std::string getErrorMessage() const { return m_ErrorMessage; } 00215 00216 bool Close(); 00217 00219 // Funktionen Arm-Ansteuerung: // 00221 00224 bool MoveJointSpaceSync(const std::vector<double>& Angle); 00225 00227 bool MoveVel(const std::vector<double>& Vel); 00228 00230 bool Stop(); 00231 00233 bool Recover(); 00234 00236 // Funktionen zum setzen von Parametern: // 00238 00241 bool setMaxVelocity(double radpersec); 00242 bool setMaxVelocity(const std::vector<double>& radpersec); 00243 00246 bool setMaxAcceleration(double radPerSecSquared); 00247 bool setMaxAcceleration(const std::vector<double>& radPerSecSquared); 00248 00250 // hier die Funktionen zur Statusabfrage: // 00252 00253 00255 bool getConfig(std::vector<double>& result); 00256 00258 bool getJointVelocities(std::vector<double> & result); 00259 00262 bool statusMoving(); 00263 00265 bool statusDec(); 00266 00268 bool statusAcc(); 00269 00271 bool doHoming(); 00272 bool HomingDone(); 00273 00274 typedef enum 00275 { 00276 PC_CTRL_OK = 0, 00277 PC_CTRL_NOT_REFERENCED = -1, 00278 PC_CTRL_ERR = -2, 00279 PC_CTRL_POW_VOLT_ERR = -3 00280 } PC_CTRL_STATE; 00281 00282 bool getStatus(PC_CTRL_STATE& error, std::vector<std::string>& errorMessages); 00283 00285 bool waitForSync(); 00287 bool dontWaitForSync(); 00288 00289 protected: 00290 00291 00294 void millisleep(unsigned int milliseconds) const; 00295 00296 int m_DOF; 00297 int m_Dev; 00298 bool m_Initialized; 00299 bool m_CANDeviceOpened; 00300 00301 std::vector<int> m_IdModules; 00302 00303 std::vector<double> m_maxVel; 00304 std::vector<double> m_maxAcc; 00305 00306 std::string m_ErrorMessage; 00307 00308 }; 00309 00310 00311 #endif