DS402Group.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of the SCHUNK Canopen Driver suite.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
00012 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00023 //----------------------------------------------------------------------
00024 
00025 #include "DS402Group.h"
00026 
00027 namespace icl_hardware {
00028 namespace canopen_schunk {
00029 
00030 DS402Group::DS402Group(const std::string& name)
00031  : DS301Group(name)
00032 {
00033 }
00034 
00035 void DS402Group::initNodes(const int16_t node_id)
00036 {
00037   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00038        it != m_ds402_nodes.end();
00039        ++it)
00040   {
00041     DS402Node::Ptr node = *it;
00042     if (node->getNodeId() == node_id || node_id < 0)
00043     {
00044       node->initNode();
00045     }
00046   }
00047 }
00048 
00049 
00050 void DS402Group::printStatus(const int16_t node_id)
00051 {
00052   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00053        it != m_ds402_nodes.end();
00054        ++it)
00055   {
00056     DS402Node::Ptr node = *it;
00057     if (node->getNodeId() == node_id || node_id < 0)
00058     {
00059       node->printStatus();
00060     }
00061   }
00062 }
00063 
00064 bool DS402Group::setTarget (const float target, const uint8_t node_id)
00065 {
00066   bool successful = false;
00067   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00068        it != m_ds402_nodes.end();
00069        ++it)
00070   {
00071     DS402Node::Ptr node = *it;
00072     if (node->getNodeId() == node_id)
00073     {
00074       successful = node->setTarget(target);
00075     }
00076   }
00077 
00078   return successful;
00079 }
00080 
00081 bool DS402Group::setTarget (const std::vector< float >& targets)
00082 {
00083   bool all_successful = true;
00084   size_t i = 0;
00085   if (targets.size() != m_ds402_nodes.size())
00086   {
00087     LOGGING_ERROR (CanOpen, "The given number of target points (" << targets.size() <<
00088       ") does not match the " <<
00089       "number of nodes registered to this group (" << m_ds402_nodes.size() << ")." << endl
00090     );
00091     return false;
00092   }
00093 
00094   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00095        it != m_ds402_nodes.end();
00096        ++it)
00097   {
00098     DS402Node::Ptr node = *it;
00099     all_successful &= node->setTarget(targets[i]);
00100     ++i;
00101   }
00102 
00103   return all_successful;
00104 }
00105 
00106 void DS402Group::startPPMovement(const int16_t node_id)
00107 {
00108   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00109        it != m_ds402_nodes.end();
00110        ++it)
00111   {
00112     DS402Node::Ptr node = *it;
00113     if (node->getNodeId() == node_id || node_id < 0)
00114     {
00115       node->startPPMovement();
00116     }
00117   }
00118 }
00119 
00120 void DS402Group::acceptPPTargets(const int16_t node_id)
00121 {
00122   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00123        it != m_ds402_nodes.end();
00124        ++it)
00125   {
00126     DS402Node::Ptr node = *it;
00127     if (node->getNodeId() == node_id || node_id < 0)
00128     {
00129       node->acceptPPTargets();
00130     }
00131   }
00132 }
00133 
00134 void DS402Group::getTargetFeedback (std::vector< double >& feedback)
00135 {
00136   feedback.resize(m_ds402_nodes.size());
00137   size_t i = 0;
00138   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00139        it != m_ds402_nodes.end();
00140        ++it)
00141   {
00142     DS402Node::Ptr node = *it;
00143     feedback[i] = node->getTargetFeedback();
00144     ++i;
00145   }
00146 }
00147 
00148 void DS402Group::setDefaultPDOMapping (const DS402Node::eDefaultPDOMapping mapping, const int16_t node_id)
00149 {
00150   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00151        it != m_ds402_nodes.end();
00152        ++it)
00153   {
00154     DS402Node::Ptr node = *it;
00155     if (node->getNodeId() == node_id || node_id < 0)
00156     {
00157       node->setDefaultPDOMapping(mapping);
00158     }
00159   }
00160 }
00161 
00162 void DS402Group::home (const int16_t node_id)
00163 {
00164   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00165        it != m_ds402_nodes.end();
00166        ++it)
00167   {
00168     DS402Node::Ptr node = *it;
00169     if (node->getNodeId() == node_id || node_id < 0)
00170     {
00171       node->home();
00172     }
00173   }
00174 }
00175 
00176 void DS402Group::getModeOfOperation (std::vector< ds402::eModeOfOperation >& modes)
00177 {
00178   modes.resize(m_ds402_nodes.size());
00179   size_t i = 0;
00180   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00181        it != m_ds402_nodes.end();
00182        ++it)
00183   {
00184     DS402Node::Ptr node = *it;
00185     modes[i] = node->getModeOfOperation();
00186     ++i;
00187   }
00188 }
00189 
00190 bool DS402Group::setModeOfOperation (const ds402::eModeOfOperation op_mode, const int16_t node_id)
00191 {
00192   bool all_successful = true;
00193   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00194        it != m_ds402_nodes.end();
00195        ++it)
00196   {
00197     DS402Node::Ptr node = *it;
00198     if (node->getNodeId() == node_id || node_id < 0)
00199     {
00200       all_successful &= node->setModeOfOperation(op_mode);
00201     }
00202   }
00203 
00204   return all_successful;
00205 }
00206 
00207 bool DS402Group::isModeSupported (const ds402::eModeOfOperation op_mode, const int16_t node_id)
00208 {
00209   bool supported_by_all = true;
00210   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00211        it != m_ds402_nodes.end();
00212        ++it)
00213   {
00214     DS402Node::Ptr node = *it;
00215     if (node->getNodeId() == node_id || node_id < 0)
00216     {
00217       supported_by_all &= node->isModeSupported(op_mode);
00218     }
00219   }
00220 
00221   return supported_by_all;
00222 }
00223 
00224 void DS402Group::quickStop (const int16_t node_id)
00225 {
00226   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00227        it != m_ds402_nodes.end();
00228        ++it)
00229   {
00230     DS402Node::Ptr node = *it;
00231     if (node->getNodeId() == node_id || node_id < 0)
00232     {
00233       node->quickStop();
00234       #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
00235       if (m_ws_broadcaster)
00236       {
00237         m_ws_broadcaster->robot->setJointEnabled(false, node->getNodeId());
00238       }
00239       #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
00240     }
00241   }
00242 }
00243 
00244 
00245 
00246 void DS402Group::setupProfilePositionMode (const ds402::ProfilePositionModeConfiguration& config, const int16_t node_id)
00247 {
00248   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00249        it != m_ds402_nodes.end();
00250        ++it)
00251   {
00252     DS402Node::Ptr node = *it;
00253     if (node->getNodeId() == node_id || node_id < 0)
00254     {
00255       node->setupProfilePositionMode(config);
00256     }
00257   }
00258 }
00259 
00260 void DS402Group::setupHomingMode (const ds402::HomingModeConfiguration& config, const int16_t node_id)
00261 {
00262   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00263        it != m_ds402_nodes.end();
00264        ++it)
00265   {
00266     DS402Node::Ptr node = *it;
00267     if (node->getNodeId() == node_id || node_id < 0)
00268     {
00269       node->setupHomingMode(config);
00270     }
00271   }
00272 }
00273 
00274 void DS402Group::setupProfileVelocityMode (const ds402::ProfileVelocityModeConfiguration& config, const int16_t node_id)
00275 {
00276   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00277        it != m_ds402_nodes.end();
00278        ++it)
00279   {
00280     DS402Node::Ptr node = *it;
00281     if (node->getNodeId() == node_id || node_id < 0)
00282     {
00283       node->setupProfileVelocityMode(config);
00284     }
00285   }
00286 }
00287 
00288 void DS402Group::setupProfileTorqueMode (const ds402::ProfileTorqueModeConfiguration& config, const int16_t node_id)
00289 {
00290   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00291        it != m_ds402_nodes.end();
00292        ++it)
00293   {
00294     DS402Node::Ptr node = *it;
00295     if (node->getNodeId() == node_id || node_id < 0)
00296     {
00297       node->setupProfileTorqueMode(config);
00298     }
00299   }
00300 }
00301 
00302 bool DS402Group::resetFault (const int16_t node_id)
00303 {
00304   bool all_successful = true;
00305   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00306        it != m_ds402_nodes.end();
00307        ++it)
00308   {
00309     DS402Node::Ptr node = *it;
00310     if (node->getNodeId() == node_id || node_id < 0)
00311     {
00312       all_successful &= node->resetFault();
00313     }
00314   }
00315 
00316   return all_successful;
00317 }
00318 
00319 void DS402Group::configureInterpolationCycleTime (const int16_t node_id, const uint8_t interpolation_cycle_time_ms)
00320 {
00321   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00322        it != m_ds402_nodes.end();
00323        ++it)
00324   {
00325     DS402Node::Ptr node = *it;
00326     if (node->getNodeId() == node_id || node_id < 0)
00327     {
00328       node->configureInterpolationCycleTime(interpolation_cycle_time_ms);
00329     }
00330   }
00331 }
00332 
00333 void DS402Group::configureHomingSpeeds (const uint32_t low_speed, const uint32_t high_speed, const int16_t node_id)
00334 {
00335   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00336        it != m_ds402_nodes.end();
00337        ++it)
00338   {
00339     DS402Node::Ptr node = *it;
00340     if (node->getNodeId() == node_id || node_id < 0)
00341     {
00342       node->configureHomingSpeeds(low_speed, high_speed);
00343     }
00344   }
00345 }
00346 
00347 void DS402Group::configureHomingMethod (const int8_t homing_method, const int16_t node_id)
00348 {
00349   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00350        it != m_ds402_nodes.end();
00351        ++it)
00352   {
00353     DS402Node::Ptr node = *it;
00354     if (node->getNodeId() == node_id || node_id < 0)
00355     {
00356       node->configureHomingSpeeds(homing_method);
00357     }
00358   }
00359 }
00360 
00361 void DS402Group::enableNodes (const ds402::eModeOfOperation operation_mode, const int16_t node_id)
00362 {
00363   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00364        it != m_ds402_nodes.end();
00365        ++it)
00366   {
00367     DS402Node::Ptr node = *it;
00368     if (node->getNodeId() == node_id || node_id < 0)
00369     {
00370       node->enableNode(operation_mode);
00371 
00372       #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
00373       if (m_ws_broadcaster)
00374       {
00375         m_ws_broadcaster->robot->setJointEnabled(true, node->getNodeId());
00376       }
00377       #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
00378 
00379     }
00380   }
00381 }
00382 
00383 void DS402Group::disableNodes (const int16_t node_id)
00384 {
00385   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00386        it != m_ds402_nodes.end();
00387        ++it)
00388   {
00389     DS402Node::Ptr node = *it;
00390     if (node->getNodeId() == node_id || node_id < 0)
00391     {
00392       node->disableNode();
00393 
00394       #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
00395       if (m_ws_broadcaster)
00396       {
00397         m_ws_broadcaster->robot->setJointEnabled(false, node->getNodeId());
00398       }
00399       #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
00400     }
00401   }
00402 }
00403 
00404 void DS402Group::openBrakes (const int16_t node_id)
00405 {
00406   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00407        it != m_ds402_nodes.end();
00408        ++it)
00409   {
00410     DS402Node::Ptr node = *it;
00411     if (node->getNodeId() == node_id || node_id < 0)
00412     {
00413       node->openBrakes();
00414       #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
00415       if (m_ws_broadcaster)
00416       {
00417         m_ws_broadcaster->robot->setJointEnabled(true, node->getNodeId());
00418       }
00419       #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
00420     }
00421   }
00422 }
00423 
00424 void DS402Group::closeBrakes (const int16_t node_id)
00425 {
00426   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00427        it != m_ds402_nodes.end();
00428        ++it)
00429   {
00430     DS402Node::Ptr node = *it;
00431     if (node->getNodeId() == node_id || node_id < 0)
00432     {
00433       node->closeBrakes();
00434       #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
00435       if (m_ws_broadcaster)
00436       {
00437         m_ws_broadcaster->robot->setJointEnabled(false, node->getNodeId());
00438       }
00439       #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
00440     }
00441   }
00442 }
00443 
00444 bool DS402Group::isTargetReached (std::vector< bool >& reached_single)
00445 {
00446   reached_single.resize(m_ds402_nodes.size());
00447   bool reached_all = true;
00448   size_t i = 0;
00449   for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
00450        it != m_ds402_nodes.end();
00451        ++it)
00452   {
00453     DS402Node::Ptr node = *it;
00454     reached_single[i] = node->isTargetReached();
00455     reached_all &= reached_single[i];
00456     ++i;
00457   }
00458 
00459   return reached_all;
00460 }
00461 
00462 
00463 
00464 
00465 
00466 }} // end of NS


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Sun May 22 2016 03:30:56