simulatedArm.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #include <schunk_powercube_chain/simulatedArm.h>
00019 #include <schunk_powercube_chain/simulatedMotor.h>
00020 #include <math.h>
00021 
00022 #define PSIM_CHECK_INITIALIZED()                                                                                       \
00023   if (isInitialized() == false)                                                                                        \
00024   {                                                                                                                    \
00025     m_ErrorMessage.assign("Manipulator not initialized.");                                                             \
00026     return false;                                                                                                      \
00027   }
00028 
00029 simulatedArm::simulatedArm()
00030 {
00031   std::cerr << "==============Starting Simulated Powercubes\n";
00032   m_DOF = 0;
00033   m_Initialized = false;
00034   m_motors.clear();
00035 }
00036 
00037 simulatedArm::~simulatedArm()
00038 {
00039   // nothing to do...
00040   ;
00041 }
00042 
00043 bool simulatedArm::Init(PowerCubeCtrlParams* params)
00044 {
00045   m_DOF = params->GetNumberOfDOF();
00046   ;
00047 
00048   double vmax = 1.0;
00049   double amax = 1.5;
00050 
00051   setMaxVelocity(vmax);
00052   setMaxAcceleration(amax);
00053   m_maxVel.resize(m_DOF);
00054   m_maxAcc.resize(m_DOF);
00055 
00056   std::vector<double> ul(m_DOF);
00057   std::vector<double> ll(m_DOF);
00058   ul = params->GetUpperLimits();
00059   ll = params->GetLowerLimits();
00060   m_maxVel = params->GetMaxVel();
00061   m_maxAcc = params->GetMaxAcc();
00062 
00063   for (int i = 0; i < m_DOF; i++)
00064   {
00065     m_motors.push_back(simulatedMotor(ll[i], ul[i], amax, vmax));
00066   }
00067   std::cerr << "===========Initializing Simulated Powercubes\n";
00068   m_Initialized = true;
00069   return true;
00070 }
00071 
00073 bool simulatedArm::Stop()
00074 {
00075   for (int i = 0; i < m_DOF; i++)
00076     m_motors[i].stop();
00077   return true;
00078 }
00079 
00080 bool simulatedArm::MoveJointSpaceSync(const std::vector<double>& target)
00081 {
00082   std::cerr << "======================TUTUTUTUT\n";
00083   PSIM_CHECK_INITIALIZED();
00084 
00085   std::vector<double> acc(m_DOF);
00086   std::vector<double> vel(m_DOF);
00087 
00088   double TG = 0;
00089 
00090   try
00091   {
00092     // Ermittle Joint, der bei max Geschw. und Beschl. am längsten braucht:
00093 
00094     std::vector<double> posnow;
00095     posnow.resize(m_DOF);
00096     if (getConfig(posnow) == false)
00097       return false;
00098 
00099     std::vector<double> velnow;
00100     velnow.resize(m_DOF);
00101     if (getJointVelocities(velnow) == false)
00102       return false;
00103 
00104     std::vector<double> times(m_DOF);
00105 
00106     for (int i = 0; i < m_DOF; i++)
00107     {
00108       RampCommand rm(posnow[i], velnow[i], target[i], m_maxAcc[i], m_maxVel[i]);
00109       times[i] = rm.getTotalTime();
00110     }
00111 
00112     // determine the joint index that has the greates value for time
00113     int furthest = 0;
00114 
00115     double max = times[0];
00116 
00117     for (int i = 1; i < m_DOF; i++)
00118     {
00119       if (times[i] > max)
00120       {
00121         max = times[i];
00122         furthest = i;
00123       }
00124     }
00125 
00126     RampCommand rm_furthest(posnow[furthest], velnow[furthest], target[furthest], m_maxAcc[furthest],
00127                             m_maxVel[furthest]);
00128 
00129     double T1 = rm_furthest.T1();
00130     double T2 = rm_furthest.T2();
00131     double T3 = rm_furthest.T3();
00132 
00133     // Gesamtzeit:
00134     TG = T1 + T2 + T3;
00135 
00136     // Jetzt Geschwindigkeiten und Beschl. für alle:
00137     acc[furthest] = m_maxAcc[furthest];
00138     vel[furthest] = m_maxVel[furthest];
00139 
00140     for (int i = 0; i < m_DOF; i++)
00141     {
00142       if (i != furthest)
00143       {
00144         double a;
00145         double v;
00146         // a und v berechnen:
00147         RampCommand::calculateAV(posnow[i], velnow[i], target[i], TG, T3, m_maxAcc[i], m_maxVel[i], a, v);
00148 
00149         acc[i] = a;
00150         vel[i] = v;
00151       }
00152     }
00153   }
00154   catch (...)
00155   {
00156     m_ErrorMessage.assign("Problem during calculation of a and av.");
00157     return false;
00158   }
00159 
00160   // Jetzt Bewegung starten:
00161   for (int i = 0; i < m_DOF; i++)
00162   {
00163     std::cout << "moving motor " << i << ": " << target[i] << ": " << vel[i] << ": " << acc[i] << "\n";
00164     m_motors[i].moveRamp(target[i], vel[i], acc[i]);
00165   }
00166 
00167   return true;
00168 }
00169 
00170 bool simulatedArm::MoveVel(const std::vector<double>& Vel)
00171 {
00172   PSIM_CHECK_INITIALIZED();
00173 
00174   //    std::cerr << ".";
00175   //    std::cerr << "Vels: ";
00176   for (int i = 0; i < m_DOF; i++)
00177   {
00178     //          std::cerr << Vel[i] << " ";
00179     m_motors[i].moveVel(Vel[i]);
00180   }
00181   //    std::cerr << "\n";
00182   return true;
00183 }
00184 
00185 bool simulatedArm::MovePos(const std::vector<double>& Pos)
00186 {
00187   PSIM_CHECK_INITIALIZED();
00188 
00189   for (int i = 0; i < m_DOF; i++)
00190     m_motors[i].movePos(Pos[i]);
00191 
00192   return true;
00193 }
00194 
00196 // Funktionen zum setzen von Parametern: //
00198 
00200 bool simulatedArm::setMaxVelocity(double radpersec)
00201 {
00202   PSIM_CHECK_INITIALIZED();
00203 
00204   m_maxVel.resize(m_DOF);
00205 
00206   for (int i = 0; i < m_DOF; i++)
00207   {
00208     m_maxAcc[i] = radpersec;
00209     m_motors[i].setMaxVelocity(radpersec);
00210   }
00211 
00212   return true;
00213 }
00214 
00215 bool simulatedArm::setMaxVelocity(const std::vector<double>& radpersec)
00216 {
00217   PSIM_CHECK_INITIALIZED();
00218 
00219   m_maxAcc = radpersec;
00220 
00221   for (int i = 0; i < m_DOF; i++)
00222     m_motors[i].setMaxVelocity(radpersec[i]);
00223 
00224   return true;
00225 }
00226 
00228 bool simulatedArm::setMaxAcceleration(double radPerSecSquared)
00229 {
00230   PSIM_CHECK_INITIALIZED();
00231 
00232   for (int i = 0; i < m_DOF; i++)
00233     m_motors[i].setMaxAcceleration(radPerSecSquared);
00234 
00235   return true;
00236 }
00237 
00238 bool simulatedArm::setMaxAcceleration(const std::vector<double>& radPerSecSquared)
00239 {
00240   PSIM_CHECK_INITIALIZED();
00241 
00242   for (int i = 0; i < m_DOF; i++)
00243     m_motors[i].setMaxAcceleration(radPerSecSquared[i]);
00244 
00245   return true;
00246 }
00247 
00249 // hier die Funktionen zur Statusabfrage: //
00251 
00253 bool simulatedArm::getConfig(std::vector<double>& result)
00254 {
00255   PSIM_CHECK_INITIALIZED();
00256 
00257   result.resize(m_DOF);
00258   for (int i = 0; i < m_DOF; i++)
00259   {
00260     result[i] = m_motors[i].getAngle();
00261   }
00262 
00263   return true;
00264 }
00265 
00267 bool simulatedArm::getJointVelocities(std::vector<double>& result)
00268 {
00269   PSIM_CHECK_INITIALIZED();
00270 
00271   result.resize(m_DOF);
00272   for (int i = 0; i < m_DOF; i++)
00273   {
00274     result[i] = m_motors[i].getVelocity();
00275   }
00276 
00277   return true;
00278 }
00279 
00282 bool simulatedArm::statusMoving()
00283 {
00284   PSIM_CHECK_INITIALIZED();
00285 
00286   for (int i = 0; i < m_DOF; i++)
00287   {
00288     if (m_motors[i].statusMoving())
00289       return true;
00290   }
00291   return false;
00292 }
00293 
00295 bool simulatedArm::statusDec()
00296 {
00297   PSIM_CHECK_INITIALIZED();
00298 
00299   for (int i = 0; i < m_DOF; i++)
00300   {
00301     if (m_motors[i].statusDec())
00302       return true;
00303   }
00304   return false;
00305 }
00306 
00308 bool simulatedArm::statusAcc()
00309 {
00310   PSIM_CHECK_INITIALIZED();
00311 
00312   for (int i = 0; i < m_DOF; i++)
00313   {
00314     if (m_motors[i].statusAcc())
00315       return true;
00316   }
00317   return false;
00318 }


schunk_powercube_chain
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:18