YouBotArmTestWithoutThread.cpp
Go to the documentation of this file.
00001 #include <youbot_driver/testing/YouBotArmTestWithoutThread.hpp>
00002 #include <stdlib.h>
00003 #include <stdexcept>
00004 
00005 using namespace youbot;
00006 
00007 YouBotArmTestWithoutThread::YouBotArmTestWithoutThread() :
00008     dof(5)
00009 {
00010 
00011 }
00012 
00013 YouBotArmTestWithoutThread::~YouBotArmTestWithoutThread()
00014 {
00015 
00016 }
00017 
00018 void YouBotArmTestWithoutThread::setUp()
00019 {
00020   char* location = getenv("YOUBOT_CONFIG_FOLDER_LOCATION");
00021   if (location == NULL)
00022     throw std::runtime_error(
00023         "YouBotArmTestWithoutThread.cpp: Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION");
00024 
00025   Logger::logginLevel = trace;
00026   updateCycle = 2000;
00027   ethercatMaster = &EthercatMaster::getInstance("youbot-ethercat.cfg", location, false);
00028   if (ethercatMaster->isThreadActive())
00029   {
00030     LOG(error) << "Thread Active";
00031     EthercatMaster::destroy();
00032     ethercatMaster = &EthercatMaster::getInstance("youbot-ethercat.cfg", location, false);
00033   }
00034 
00035 }
00036 
00037 void YouBotArmTestWithoutThread::tearDown()
00038 {
00039   EthercatMaster::destroy();
00040 }
00041 
00042 void YouBotArmTestWithoutThread::youBotArmTest()
00043 {
00044   char* configLocation = getenv("YOUBOT_CONFIG_FOLDER_LOCATION");
00045   if (configLocation == NULL)
00046     throw std::runtime_error("YouBotArmTest.cpp: Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION");
00047 
00048   LOG(info) << __func__ << "\n";
00049   YouBotManipulator myArm("youbot-manipulator", configLocation);
00050   myArm.doJointCommutation();
00051   myArm.calibrateManipulator();
00052 
00053   std::stringstream jointNameStream;
00054   boost::ptr_vector<DataTrace> myTrace;
00055   std::vector<JointAngleSetpoint> upstretchedpose;
00056   std::vector<JointAngleSetpoint> foldedpose;
00057   JointAngleSetpoint desiredJointAngle;
00058 
00059   desiredJointAngle.angle = 2.56244 * radian;
00060   upstretchedpose.push_back(desiredJointAngle);
00061   desiredJointAngle.angle = 1.04883 * radian;
00062   upstretchedpose.push_back(desiredJointAngle);
00063   desiredJointAngle.angle = -2.43523 * radian;
00064   upstretchedpose.push_back(desiredJointAngle);
00065   desiredJointAngle.angle = 1.73184 * radian;
00066   upstretchedpose.push_back(desiredJointAngle);
00067   desiredJointAngle.angle = 1.5 * radian;
00068   upstretchedpose.push_back(desiredJointAngle);
00069 
00070   desiredJointAngle.angle = 0.11 * radian;
00071   foldedpose.push_back(desiredJointAngle);
00072   desiredJointAngle.angle = 0.11 * radian;
00073   foldedpose.push_back(desiredJointAngle);
00074   desiredJointAngle.angle = -0.11 * radian;
00075   foldedpose.push_back(desiredJointAngle);
00076   desiredJointAngle.angle = 0.11 * radian;
00077   foldedpose.push_back(desiredJointAngle);
00078   desiredJointAngle.angle = 0.2 * radian;
00079   foldedpose.push_back(desiredJointAngle);
00080 
00081   for (int i = 1; i <= dof; i++)
00082   {
00083     jointNameStream << "Joint_" << i << "_" << __func__;
00084     myTrace.push_back(new DataTrace(myArm.getArmJoint(i), jointNameStream.str(), true));
00085     jointNameStream.str("");
00086   }
00087 
00088   for (int i = 0; i < dof; i++)
00089   {
00090     myTrace[i].startTrace();
00091   }
00092 
00093   ClearMotorControllerTimeoutFlag clearTimeoutFlag;
00094   myArm.getArmJoint(1).setConfigurationParameter(clearTimeoutFlag);
00095   myArm.getArmJoint(2).setConfigurationParameter(clearTimeoutFlag);
00096   myArm.getArmJoint(3).setConfigurationParameter(clearTimeoutFlag);
00097   myArm.getArmJoint(4).setConfigurationParameter(clearTimeoutFlag);
00098   myArm.getArmJoint(5).setConfigurationParameter(clearTimeoutFlag);
00099 
00100   if (!ethercatMaster->isThreadActive())
00101   {
00102     ethercatMaster->sendProcessData();
00103     ethercatMaster->receiveProcessData();
00104   }
00105 
00106   // 1 sec no movement
00107   startTime = myTrace[0].getTimeDurationMilliSec();
00108   overallTime = startTime + 1000;
00109   while (myTrace[0].getTimeDurationMilliSec() < overallTime)
00110   {
00111     if (!ethercatMaster->isThreadActive())
00112     {
00113       ethercatMaster->sendProcessData();
00114       ethercatMaster->receiveProcessData();
00115     }
00116     for (int i = 0; i < dof; i++)
00117     {
00118       myTrace[i].updateTrace();
00119     }
00120     SLEEP_MICROSEC(updateCycle);
00121   }
00122 
00123   // move to upstretched position
00124   startTime = myTrace[0].getTimeDurationMilliSec();
00125   overallTime = startTime + 5000;
00126   myArm.setJointData(upstretchedpose);
00127   while (myTrace[0].getTimeDurationMilliSec() < overallTime)
00128   {
00129     if (!ethercatMaster->isThreadActive())
00130     {
00131       ethercatMaster->sendProcessData();
00132       ethercatMaster->receiveProcessData();
00133     }
00134     for (int i = 0; i < dof; i++)
00135     {
00136       myTrace[i].updateTrace();
00137     }
00138     SLEEP_MICROSEC(updateCycle);
00139   }
00140 
00141   // move to folded position
00142   startTime = myTrace[0].getTimeDurationMilliSec();
00143   overallTime = startTime + 5000;
00144   myArm.setJointData(foldedpose);
00145   while (myTrace[0].getTimeDurationMilliSec() < overallTime)
00146   {
00147     if (!ethercatMaster->isThreadActive())
00148     {
00149       ethercatMaster->sendProcessData();
00150       ethercatMaster->receiveProcessData();
00151     }
00152     for (int i = 0; i < dof; i++)
00153     {
00154       myTrace[i].updateTrace();
00155     }
00156     SLEEP_MICROSEC(updateCycle);
00157   }
00158 
00159   // 1 sec no movement
00160   startTime = myTrace[0].getTimeDurationMilliSec();
00161   overallTime = startTime + 1000;
00162   while (myTrace[0].getTimeDurationMilliSec() < overallTime)
00163   {
00164     if (!ethercatMaster->isThreadActive())
00165     {
00166       ethercatMaster->sendProcessData();
00167       ethercatMaster->receiveProcessData();
00168     }
00169     for (int i = 0; i < dof; i++)
00170     {
00171       myTrace[i].updateTrace();
00172     }
00173     SLEEP_MICROSEC(updateCycle);
00174   }
00175 
00176   for (int i = 0; i < dof; i++)
00177   {
00178     myTrace[i].stopTrace();
00179     myTrace[i].plotTrace();
00180   }
00181 
00182 }


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Oct 6 2014 09:08:01