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: This class simulates the PowerCubes in a very rough and simple way. 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: Aug 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_SIM_H_ 00055 #define __POWER_CUBE_SIM_H_ 00056 00057 #include <cob_powercube_chain/PowerCubeCtrl.h> 00058 #include <cob_powercube_chain/Joint.h> 00059 #include <iostream> 00060 #include <stdio.h> 00061 #include <stdlib.h> 00062 #include <vector> 00063 00064 using namespace std; 00065 #include <pthread.h> 00066 00067 00068 //------------------------------------------------------------------------- 00069 // Defines 00070 // ------------------------------------------------------------------------- 00071 00072 #define MAX_VEL 0.5 00073 #define MAX_ACC 0.5 00074 #define K13 0.5 00075 #define K14 0.5 00076 #define K15 3 00077 #define DAEMPFUNG 0.5 00078 00079 //#define __LINUX__ 00080 00081 #ifdef SWIG 00082 %module PowerCubeSim 00083 %include "Source/Manipulation/Interfaces/armInterface.h" 00084 %{ 00085 #include "PowerCubeSim.h" 00086 %} 00087 #endif 00088 00089 class PowerCubeSim; 00090 00091 /* Thread arguments for simulation threads*/ 00092 typedef struct 00093 { 00094 PowerCubeSim * cubeSimPtr; 00095 int cubeID; 00096 double targetAngle; 00097 } SimThreadArgs; 00098 00099 class PowerCubeSim 00100 { 00101 public: 00102 00103 PowerCubeSim(); 00104 ~PowerCubeSim(); 00105 00106 00107 bool Init(PowerCubeCtrlParams * params); 00108 00109 bool isInitialized() const { return m_Initialized; } 00110 00111 std::string getErrorMessage() const { return m_ErrorMessage; } 00112 00113 int Close(){return true;} 00114 // Arm-Ansteuerung: 00115 00116 00119 bool MoveJointSpaceSync(const std::vector<double>& Angle); 00120 00122 bool MoveVel(const std::vector<double>& vel); 00123 00125 bool Stop(); 00126 00128 // Funktionen zum setzen von Parametern: // 00130 00133 bool setMaxVelocity(double radpersec); 00134 00135 bool setMaxVelocity(const std::vector<double>& radpersec); 00136 00139 bool setMaxAcceleration(double radPerSecSquared); 00140 bool setMaxAcceleration(const std::vector<double>& radPerSecSquared); 00141 00143 // hier die Funktionen zur Statusabfrage: // 00145 00146 00148 bool getConfig(std::vector<double>& result); 00149 00151 bool getJointVelocities(std::vector<double>& result); 00152 00153 void setCurrentAngles(std::vector<double> Angles); 00154 00155 void setCurrentJointVelocities(std::vector<double> Angles); 00156 00159 bool statusMoving(); 00160 bool statusMoving(int cubeNo); 00161 00163 bool statusDec(); 00164 00166 bool statusAcc(); 00167 00169 //vector<int> getModuleMap(int dev); 00170 00172 //void HomingDone(); 00173 00174 typedef enum 00175 { 00176 PC_CTRL_OK = 0, 00177 PC_CTRL_NOT_REFERENCED = -1, 00178 PC_CTRL_ERR = -2, 00179 PC_CTRL_POW_VOLT_ERR = -3 00180 } PC_CTRL_STATE; 00181 //int getStatus(){return PC_CTRL_OK;} 00182 double maxVel; 00183 00184 void setStatusMoving (int cubeNo, bool moving); 00185 bool getStatusMoving (int cubeNo) const { return m_MovementInProgress[cubeNo]; } 00186 00187 vector<int> getModuleMap() const {return m_IdModules;} 00188 std::vector<double> getCurrentAngularMaxVel() {return m_CurrentAngularMaxVel;} 00189 std::vector<double> getCurrentAngularMaxAccel() {return m_CurrentAngularMaxAccel;} 00190 void millisleep(unsigned int milliseconds) const; 00191 protected: 00192 00194 //void waitForSync(); 00196 //void dontWaitForSync(); 00198 double timeRampMove(double dtheta, double vnow, double v, double a); 00199 00200 int startSimulatedMovement(std::vector<double> target); 00201 00202 00203 //void* SimThreadRoutine (void*); 00204 00205 00206 #ifdef COB3 00207 Manipulator * m_Obj_Manipulator; 00208 #endif 00209 00210 int m_DOF; 00211 int m_Initialized; 00212 int m_NumOfModules; 00213 int m_Dev; 00214 vector<int> m_IdModules; 00215 00216 std::vector<double> m_maxVel; 00217 std::vector<double> m_maxAcc; 00218 00219 Jointd m_AngleOffsets; 00220 00221 std::vector<bool> m_MovementInProgress; 00222 00223 std::vector<double> m_CurrentAngles; 00224 std::vector<double> m_CurrentAngularVel; 00225 std::vector<double> m_CurrentAngularMaxVel; 00226 std::vector<double> m_CurrentAngularMaxAccel; 00227 00228 00229 00230 //vector<unsigned long> startConf; 00231 00232 std::string m_ErrorMessage; 00233 00234 float maxAcc; 00235 00236 pthread_mutex_t m_Angles_Mutex; 00237 pthread_mutex_t m_AngularVel_Mutex; 00238 pthread_mutex_t m_Movement_Mutex; 00239 pthread_t * m_SimThreadID; 00240 SimThreadArgs ** m_SimThreadArgs; 00241 00242 }; 00243 00244 00245 #endif