VelocityProjection.cpp
Go to the documentation of this file.
00001 /*
00002  * SpringCoupler.cpp
00003  *
00004  *  Created on: 31-08-2011
00005  *      Author: konradb3
00006  */
00007 
00008 #include <rtt/Component.hpp>
00009 
00010 #include "VelocityProjection.h"
00011 #include <tf_conversions/tf_kdl.h>
00012 #include <Eigen/Dense>
00013 
00014 namespace lwr {
00015 
00016 VelocityProjector::VelocityProjector(const std::string& name) : TaskContext(name, PreOperational) {
00017   // command inputs
00018 
00019   this->addPort("CartesianVelocityCommand", port_cartesian_velocity_command);
00020   this->addPort("NullspaceVelocityCommand", port_nullspace_velocity_command);
00021   this->addPort("MassMatrix", port_mass_matrix);
00022   this->addPort("ToolFrame", port_tool_frame);
00023   this->addEventPort("CommandPeriod", port_command_period);
00024   // meansurment inputs
00025   this->addPort("Jacobian", port_jacobian);
00026   this->addPort("DesiredJointPosition", port_jnt_pos_des);
00027   // commands outputs
00028   this->addPort("JointPositionCommand", port_joint_position_command);
00029 }
00030 
00031 VelocityProjector::~VelocityProjector() {
00032 
00033 }
00034 
00035 bool VelocityProjector::configureHook() {
00036         return true;
00037 }
00038 
00039 void VelocityProjector::cleanupHook() {
00040 
00041 }
00042 
00043 bool VelocityProjector::startHook() {
00044 
00045   jnt_pos_cmd.resize(7);
00046 
00047         if(port_command_period.read(dt) == RTT::NoData) {
00048           RTT::Logger::log(RTT::Logger::Error) << "No comand period data " << RTT::endlog();
00049                 return false;
00050         }
00051         
00052         geometry_msgs::Pose tool_frame_msg;
00053         
00054         if(port_tool_frame.read(tool_frame_msg) == RTT::NoData) {
00055           RTT::Logger::log(RTT::Logger::Error) << "No tool data " << RTT::endlog();
00056          // return false;
00057         }
00058         
00059         //tf::PoseMsgToKDL(tool_frame_msg, tool_frame);
00060 
00061         return true;
00062 }
00063 
00064 void VelocityProjector::stopHook() {
00065 
00066 }
00067 
00068 void VelocityProjector::updateHook() {
00069 
00070   Matrix77d M, Mi;
00071   Matrix76d Ji;
00072   Vector7d qd_dot, q0_dot;
00073   Vector6d xc_dot;
00074   
00075   port_command_period.read(dt);
00076   port_jacobian.read(jacobian);
00077   
00078   xc_dot = Vector6d::Zero();
00079   
00080   if(port_cartesian_velocity_command.read(cart_vel_cmd) == RTT::NewData){
00081     xc_dot(0) = cart_vel_cmd.linear.x;
00082     xc_dot(1) = cart_vel_cmd.linear.y;
00083     xc_dot(2) = cart_vel_cmd.linear.z;
00084     xc_dot(3) = cart_vel_cmd.angular.x;
00085     xc_dot(4) = cart_vel_cmd.angular.y; 
00086     xc_dot(5) = cart_vel_cmd.angular.z; 
00087   }
00088   
00089   q0_dot = Vector7d::Zero();
00090   
00091   if(port_nullspace_velocity_command.read(null_vel_cmd) == RTT::NewData){
00092       for(size_t i = 0; i < 7; i++) {
00093         q0_dot(i) = null_vel_cmd[i];
00094       }
00095   }
00096 
00097   port_mass_matrix.read(M);
00098   
00099   port_jnt_pos_des.read(jnt_pos_des);
00100 
00101   for(size_t i = 0; i < 7; i++)
00102     q0_dot(i) = -(jnt_pos_des[i]/17.0);
00103 
00104   Mi = M.inverse();
00105   Ji = Mi * jacobian.data.transpose() * (jacobian.data * Mi * jacobian.data.transpose()).inverse();
00106  
00107   qd_dot = Ji * xc_dot + (Matrix77d::Identity() - Ji * jacobian.data) * q0_dot;
00108   
00109   for(size_t i = 0; i < 7; i++) { 
00110     jnt_pos_cmd[i] = jnt_pos_des[i] + qd_dot(i) * dt;
00111   }
00112   
00113   port_joint_position_command.write(jnt_pos_cmd);
00114 }
00115 
00116 }
00117 ORO_CREATE_COMPONENT(lwr::VelocityProjector)


lwr_impedance_controller
Author(s): Konrad Banachowicz
autogenerated on Mon Oct 6 2014 02:01:41