Go to the documentation of this file.00001 #include <robodyn_controllers/ForceTrajectory.h>
00002
00003 ForceTrajectory::ForceTrajectory()
00004 : lastTime(0.)
00005 , logCategory("gov.nasa.controllers.ForceTrajectory")
00006 {
00007 }
00008
00009 void ForceTrajectory::getPose(double time, KDL::JntArrayAcc& pose)
00010 {
00011 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "entered ForceTrajectory::getPose " << time;
00012
00013 if (time == 0.)
00014 {
00015 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "initializing..";
00016 pose = jointsLast = jointsInit;
00017 lastTime = 0.;
00018 return;
00019 }
00020
00021 if (time < lastTime)
00022 {
00023 std::stringstream err;
00024 err << "ForceTrajectory time moved backwards" << std::endl;
00025 NasaCommonLogging::Logger::log(logCategory, log4cpp::Priority::ERROR, err.str());
00026 throw std::runtime_error(err.str());
00027
00028 return;
00029 }
00030
00031 if (time >= double(trajectory->getDuration()))
00032 {
00033 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "end of trajectory";
00034 return;
00035 }
00036
00037
00038 trajectory->getPose(time, nodeFramesAcc);
00039 nodeFrames.resize(nodeFramesAcc.size());
00040
00041 for (unsigned int i = 0; i < nodeFramesAcc.size(); ++i)
00042 {
00043 nodeFrames[i] = nodeFramesAcc[i].GetFrame();
00044 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "node " << nodeNames[i] << " before: "
00045 << nodeFrames[i].p.x() << ", " << nodeFrames[i].p.y() << ", " << nodeFrames[i].p.z() << ", "
00046 << nodeFrames[i].M.GetRot().x() << ", " << nodeFrames[i].M.GetRot().y() << ", " << nodeFrames[i].M.GetRot().z();
00047 }
00048
00049 std::map<std::string, KDL::Frame> controlledFrames;
00050 std::vector<std::string> jointNames;
00051 treeIk->getJointNames(jointNames);
00052
00053 treeIk->getFrames(jointsLast.q, controlledFrames);
00054
00055 for (unsigned int i = 0; i < nodeNames.size(); ++i)
00056 {
00057 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "getFrames " << nodeNames[i] << ": "
00058 << controlledFrames[nodeNames[i]].p.x() << ", " << controlledFrames[nodeNames[i]].p.y() << ", " << controlledFrames[nodeNames[i]].p.z() << ", "
00059 << controlledFrames[nodeNames[i]].M.GetRot().x() << ", " << controlledFrames[nodeNames[i]].M.GetRot().y() << ", " << controlledFrames[nodeNames[i]].M.GetRot().z();
00060 }
00061
00062 double dt = time - lastTime;
00063
00064 forceController->updateFrames(nodeNames, controlledFrames, nodeFrames, dt);
00065
00066 for (unsigned int i = 0; i < nodeFrames.size(); ++i)
00067 {
00068 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << "node " << nodeNames[i] << " after: "
00069 << nodeFrames[i].p.x() << ", " << nodeFrames[i].p.y() << ", " << nodeFrames[i].p.z() << ", "
00070 << nodeFrames[i].M.GetRot().x() << ", " << nodeFrames[i].M.GetRot().y() << ", " << nodeFrames[i].M.GetRot().z();
00071 }
00072
00073 pose.resize(jointsInit.q.rows());
00074 treeIk->getJointPositions(jointsLast.q, nodeNames, nodeFrames, pose.q, nodePriorities);
00075
00076
00077 for (unsigned int i = 0; i < pose.q.rows(); ++i)
00078 {
00079 double tstep = time - lastTime;
00080
00081 if (tstep < treeIk->getTimeStep() / 2.) { tstep = treeIk->getTimeStep() / 2.; }
00082
00083 pose.qdot(i) = (pose.q(i) - jointsLast.q(i)) / tstep;
00084 pose.qdotdot(i) = (pose.qdot(i) - jointsLast.qdot(i)) / tstep;
00085 }
00086
00087 lastTime = time;
00088 jointsLast = pose;
00089 }
00090
00091 void ForceTrajectory::printFrame(std::string name, KDL::Frame frame)
00092 {
00093 NasaCommonLogging::Logger::getCategory(logCategory) << log4cpp::Priority::DEBUG << name << ": "
00094 << frame.p.x() << ", " << frame.p.y() << ", " << frame.p.z() << ", "
00095 << frame.M.GetRot().x() << ", " << frame.M.GetRot().y() << ", " << frame.M.GetRot().z();
00096
00097 }