YouBotBaseTest.cpp
Go to the documentation of this file.
00001 #include <youbot_driver/testing/YouBotBaseTest.hpp>
00002 #include <stdlib.h>
00003 #include <stdexcept>
00004 
00005 using namespace youbot;
00006 
00007 YouBotBaseTest::YouBotBaseTest()
00008 {
00009   char* location;
00010   location = getenv("YOUBOT_CONFIG_FOLDER_LOCATION");
00011   if (location == NULL)
00012     throw std::runtime_error("YouBotBaseTest.cpp: Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION");
00013   EthercatMaster::getInstance("youbot-ethercat.cfg", location, true);
00014 
00015 }
00016 
00017 YouBotBaseTest::~YouBotBaseTest()
00018 {
00019 
00020 }
00021 
00022 void YouBotBaseTest::setUp()
00023 {
00024   Logger::logginLevel = trace;
00025   jointNO = 4;
00026   stepStartTime = 1000;
00027   durationNull = 1000;
00028   overallTime = 0;
00029   startTime = 0;
00030   updateCycle = 2000;
00031   setAngle.angle = 0 * radian;
00032   setVel.angularVelocity = 0 * radian_per_second;
00033   currentSetpoint.current = 0 * ampere;
00034 
00035 }
00036 
00037 void YouBotBaseTest::tearDown()
00038 {
00039 //      EthercatMaster::destroy();
00040 }
00041 
00042 void YouBotBaseTest::youBotBaseTest_PositionMode()
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   YouBotBase myBase("youbot-base", configLocation);
00050   myBase.doJointCommutation();
00051   DataTrace myTrace(myBase.getBaseJoint(jointNO), __func__, true);
00052   myBase.getBaseJoint(jointNO).setEncoderToZero();
00053   myTrace.startTrace();
00054 
00055   startTime = myTrace.getTimeDurationMilliSec();
00056   overallTime = startTime + durationNull + stepStartTime + durationNull;
00057 
00058   while (myTrace.getTimeDurationMilliSec() < overallTime)
00059   {
00060     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull)
00061     {
00062       setAngle.angle = 0 * radian;
00063     }
00064     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull
00065         && myTrace.getTimeDurationMilliSec() < startTime + durationNull + stepStartTime)
00066     {
00067       setAngle.angle = 1 * radian;
00068     }
00069     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull + stepStartTime)
00070     {
00071       setAngle.angle = 0 * radian;
00072     }
00073 
00074     myBase.getBaseJoint(jointNO).setData(setAngle);
00075     myTrace.updateTrace(setAngle);
00076 
00077     SLEEP_MICROSEC(updateCycle);
00078   }
00079   myTrace.stopTrace();
00080   myTrace.plotTrace();
00081 }
00082 
00083 void YouBotBaseTest::youBotBaseTest_VelocityMode()
00084 {
00085   char* configLocation = getenv("YOUBOT_CONFIG_FOLDER_LOCATION");
00086   if (configLocation == NULL)
00087     throw std::runtime_error("YouBotArmTest.cpp: Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION");
00088 
00089   LOG(info) << __func__ << "\n";
00090   YouBotBase myBase("youbot-base", configLocation);
00091   myBase.doJointCommutation();
00092   DataTrace myTrace(myBase.getBaseJoint(jointNO), __func__, true);
00093   myBase.getBaseJoint(jointNO).setEncoderToZero();
00094   myTrace.startTrace();
00095 
00096   startTime = myTrace.getTimeDurationMilliSec();
00097   overallTime = startTime + durationNull + stepStartTime + durationNull;
00098 
00099   while (myTrace.getTimeDurationMilliSec() < overallTime)
00100   {
00101     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull)
00102     {
00103       setVel.angularVelocity = 0 * radian_per_second;
00104     }
00105     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull
00106         && myTrace.getTimeDurationMilliSec() < startTime + durationNull + stepStartTime)
00107     {
00108       setVel.angularVelocity = 1 * radian_per_second;
00109     }
00110     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull + stepStartTime)
00111     {
00112       setVel.angularVelocity = 0 * radian_per_second;
00113     }
00114 
00115     myBase.getBaseJoint(jointNO).setData(setVel);
00116     myTrace.updateTrace(setVel);
00117 
00118     SLEEP_MICROSEC(updateCycle);
00119   }
00120   myTrace.stopTrace();
00121   myTrace.plotTrace();
00122 }
00123 
00124 void YouBotBaseTest::youBotBaseTest_CurrentMode()
00125 {
00126   char* configLocation = getenv("YOUBOT_CONFIG_FOLDER_LOCATION");
00127   if (configLocation == NULL)
00128     throw std::runtime_error("YouBotArmTest.cpp: Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION");
00129 
00130   LOG(info) << __func__ << "\n";
00131   YouBotBase myBase("youbot-base", configLocation);
00132   myBase.doJointCommutation();
00133   DataTrace myTrace(myBase.getBaseJoint(jointNO), __func__, true);
00134   myBase.getBaseJoint(jointNO).setEncoderToZero();
00135   myTrace.startTrace();
00136 
00137   startTime = myTrace.getTimeDurationMilliSec();
00138   overallTime = startTime + durationNull + stepStartTime + durationNull;
00139 
00140   while (myTrace.getTimeDurationMilliSec() < overallTime)
00141   {
00142     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull)
00143     {
00144       currentSetpoint.current = 0 * ampere;
00145     }
00146     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull
00147         && myTrace.getTimeDurationMilliSec() < startTime + durationNull + stepStartTime)
00148     {
00149       currentSetpoint.current = 0.3 * ampere;
00150     }
00151     if (myTrace.getTimeDurationMilliSec() > startTime + durationNull + stepStartTime)
00152     {
00153       currentSetpoint.current = 0 * ampere;
00154     }
00155 
00156     myBase.getBaseJoint(jointNO).setData(currentSetpoint);
00157     myTrace.updateTrace(currentSetpoint);
00158 
00159     SLEEP_MICROSEC(updateCycle);
00160   }
00161   myTrace.stopTrace();
00162   myTrace.plotTrace();
00163 }


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