YouBotBaseKinematicsTest.cpp
Go to the documentation of this file.
00001 #include <youbot_driver/testing/YouBotBaseKinematicsTest.hpp>
00002 #include <stdlib.h>
00003 #include <stdexcept>
00004 
00005 using namespace youbot;
00006 
00007 YouBotBaseKinematicsTest::YouBotBaseKinematicsTest()
00008 {
00009   char* location = getenv("YOUBOT_CONFIG_FOLDER_LOCATION");
00010   if (location == NULL)
00011     throw std::runtime_error(
00012         "YouBotBaseKinematicsTest.cpp: Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION");
00013 
00014   EthercatMaster::getInstance("youbot-ethercat.cfg", location, true);
00015 
00016 }
00017 
00018 YouBotBaseKinematicsTest::~YouBotBaseKinematicsTest()
00019 {
00020 
00021 }
00022 
00023 void YouBotBaseKinematicsTest::setUp()
00024 {
00025   Logger::logginLevel = trace;
00026   updateCycle = 2000;
00027 
00028 }
00029 
00030 void YouBotBaseKinematicsTest::tearDown()
00031 {
00032   //    EthercatMaster::destroy();
00033 }
00034 
00035 void YouBotBaseKinematicsTest::youBotBaseKinematicsTest()
00036 {
00037   char* configLocation = getenv("YOUBOT_CONFIG_FOLDER_LOCATION");
00038   if (configLocation == NULL)
00039     throw std::runtime_error("YouBotArmTest.cpp: Could not find environment variable YOUBOT_CONFIG_FOLDER_LOCATION");
00040 
00041   LOG(info) << __func__ << "\n";
00042   YouBotBase myBase("youbot-base", configLocation);
00043   myBase.doJointCommutation();
00044   std::stringstream jointNameStream;
00045   boost::ptr_vector<DataTrace> myTrace;
00046   unsigned int step1 = 1000;
00047   unsigned int step2 = 4000;
00048   unsigned int step3 = 7000;
00049   unsigned int step4 = 10000;
00050   unsigned int step5 = 13000;
00051   unsigned int step6 = 16000;
00052 
00053   // create variables to set and get the base cartesian velocity and pose
00054   quantity<si::velocity> longitudinalVelocity = 0.0 * meter_per_second;
00055   quantity<si::velocity> transversalVelocity = 0.0 * meter_per_second;
00056   quantity<si::angular_velocity> angularVelocity = 0 * radian_per_second;
00057   /*
00058    quantity<si::velocity> actualLongitudinalVelocity = 0 * meter_per_second;
00059    quantity<si::velocity> actualTransversalVelocity = 0 * meter_per_second;
00060    quantity<si::angular_velocity> actualAngularVelocity = 0 * radian_per_second;
00061 
00062    quantity<si::length> actualLongitudinalPose = 0 * meter;
00063    quantity<si::length> actualTransversalPose = 0 * meter;
00064    quantity<si::plane_angle> actualAngle = 0 * radian;
00065    */
00066   for (int i = 1; i <= 4; i++)
00067   {
00068     jointNameStream << "Joint_" << i << "_" << __func__;
00069     myTrace.push_back(new DataTrace(myBase.getBaseJoint(i), jointNameStream.str(), true));
00070     jointNameStream.str("");
00071     myBase.getBaseJoint(i).setEncoderToZero();
00072   }
00073 
00074   for (int i = 0; i < 4; i++)
00075   {
00076     myTrace[i].startTrace();
00077   }
00078 
00079   startTime = myTrace[0].getTimeDurationMilliSec();
00080   overallTime = startTime + step6 + 10;
00081 
00082   while (myTrace[0].getTimeDurationMilliSec() < overallTime)
00083   {
00084     if (myTrace[0].getTimeDurationMilliSec() > startTime + step1)
00085     {
00086       longitudinalVelocity = 0.0 * meter_per_second;
00087       transversalVelocity = 0.0 * meter_per_second;
00088       angularVelocity = 0 * radian_per_second;
00089     }
00090     if (myTrace[0].getTimeDurationMilliSec() > startTime + step1
00091         && myTrace[0].getTimeDurationMilliSec() < startTime + step2)
00092     {
00093       longitudinalVelocity = 0.2 * meter_per_second;
00094       transversalVelocity = 0.0 * meter_per_second;
00095       angularVelocity = 0 * radian_per_second;
00096     }
00097     if (myTrace[0].getTimeDurationMilliSec() > startTime + step2
00098         && myTrace[0].getTimeDurationMilliSec() < startTime + step3)
00099     {
00100       longitudinalVelocity = 0.0 * meter_per_second;
00101       transversalVelocity = 0.2 * meter_per_second;
00102       angularVelocity = 0.0 * radian_per_second;
00103     }
00104 
00105     if (myTrace[0].getTimeDurationMilliSec() > startTime + step3
00106         && myTrace[0].getTimeDurationMilliSec() < startTime + step4)
00107     {
00108       longitudinalVelocity = 0.0 * meter_per_second;
00109       transversalVelocity = 0.0 * meter_per_second;
00110       angularVelocity = 0.2 * radian_per_second;
00111     }
00112 
00113     if (myTrace[0].getTimeDurationMilliSec() > startTime + step4
00114         && myTrace[0].getTimeDurationMilliSec() < startTime + step5)
00115     {
00116       longitudinalVelocity = 0.1 * meter_per_second;
00117       transversalVelocity = 0.1 * meter_per_second;
00118       angularVelocity = 0.0 * radian_per_second;
00119     }
00120 
00121     if (myTrace[0].getTimeDurationMilliSec() > startTime + step5
00122         && myTrace[0].getTimeDurationMilliSec() < startTime + step6)
00123     {
00124       longitudinalVelocity = 0.1 * meter_per_second;
00125       transversalVelocity = 0.1 * meter_per_second;
00126       angularVelocity = 0.0 * radian_per_second;
00127     }
00128 
00129     if (myTrace[0].getTimeDurationMilliSec() > startTime + step6)
00130     {
00131       longitudinalVelocity = 0 * meter_per_second;
00132       transversalVelocity = 0 * meter_per_second;
00133       angularVelocity = 0 * radian_per_second;
00134     }
00135 
00136     myBase.setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity);
00137     for (int i = 0; i < 4; i++)
00138     {
00139       myTrace[i].updateTrace();
00140     }
00141 
00142     SLEEP_MICROSEC(updateCycle);
00143   }
00144   for (int i = 0; i < 4; i++)
00145   {
00146     myTrace[i].stopTrace();
00147     myTrace[i].plotTrace();
00148   }
00149 
00150 }


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