/*
q2d_teleop_rviz: A ROS node to teloperate the Quanser 2DSFJE robot.
- Copyright (c) 2018 Walter Fetter Lages <w.fetter@ieee.org>
+ Copyright (c) 2018,2019 Walter Fetter Lages <w.fetter@ieee.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <kdl/chainiksolverpos_lma.hpp>
#include <kdl_parser/kdl_parser.hpp>
-#define sqr(x) (x*x)
+#define sqr(x) ((x)*(x))
class Q2dTeleop
{
ros::Publisher elbowCmdPub_;
KDL::Frame goal_;
+ KDL::Chain chain_;
KDL::ChainIkSolverPos_LMA *ikSolverPos_;
KDL::JntArray q_;
if (!kdl_parser::treeFromString(robotDescription,tree))
ROS_ERROR_STREAM("Failed to construct KDL tree.");
- KDL::Chain chain;
- if (!tree.getChain("origin_link","tool_link",chain))
+ if (!tree.getChain("origin_link","tool_link",chain_))
ROS_ERROR_STREAM("Failed to get chain from KDL tree.");
- q_.resize(chain.getNrOfJoints());
+ q_.resize(chain_.getNrOfJoints());
goal_.Identity();
goal_.p.x(0.61);
Eigen::Matrix<double,6,1> L;
L << 1.0 , 1.0 , 1.0, 0.01, 0.01, 0.01;
-
- ikSolverPos_=new KDL::ChainIkSolverPos_LMA(chain,L);
- ikSolverPos_->display_information=true;
-
-/*
- std::cout << "q_=" << q_ << std::endl;
- std::cout << "goal=" << goal_ << std::endl;
-
- KDL::JntArray q_out=q_;
- int error=0;
- if((error=ikSolverPos_->CartToJnt(q_,goal_,q_out)) < 0)
- ROS_ERROR_STREAM("Failed to compute invere kinematics: (" << error << ") "
- << ikSolverPos_->strError(error));
- q_=q_out;
- std::cout << "q_=" << q_ << std::endl;
-*/
+
+ // A copy of chain_ is not created inside!
+ ikSolverPos_=new KDL::ChainIkSolverPos_LMA(chain_,L);
+ ikSolverPos_->display_information=false;
}
Q2dTeleop::~Q2dTeleop(void)
publish();
}
+#define KDL_IK
void Q2dTeleop::publish(void)
{
-/*
- std::cout << "q_=" << q_ << std::endl;
- std::cout << "goal=" << goal_ << std::endl;
-
+#ifdef KDL_IK
KDL::JntArray q_out=q_;
int error=0;
if((error=ikSolverPos_->CartToJnt(q_,goal_,q_out)) < 0)
ROS_ERROR_STREAM("Failed to compute invere kinematics: (" << error << ") "
<< ikSolverPos_->strError(error));
q_=q_out;
- std::cout << "q_=" << q_ << std::endl;
-*/
-
+#else
+ // Algebric inverse kinematics
const double l1=0.343;
const double l2=0.267;
double c1=(sqr(goal_.p.x())+sqr(goal_.p.y())-sqr(l1)-sqr(l2))/2/l1/l2;
q_(1)=q1b;
}
}
-
+#endif
+
std_msgs::Float64 shoulderCmd;
std_msgs::Float64 elbowCmd;
/*
q2d_teleop_tablet: A ROS node to teloperate the Quanser 2DSFJE robot.
- Copyright (c) 2018 Walter Fetter Lages <w.fetter@ieee.org>
+ Copyright (c) 2018,2019 Walter Fetter Lages <w.fetter@ieee.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <kdl/chainiksolverpos_lma.hpp>
#include <kdl_parser/kdl_parser.hpp>
-#define sqr(x) (x*x)
-
-//DEBUG
-#include <kdl/frames_io.hpp>
-#include <kdl//kinfam_io.hpp>
+#define sqr(x) ((x)*(x))
class Q2dTeleop
{
ros::Publisher elbowCmdPub_;
KDL::Frame goal_;
+ KDL::Chain chain_;
KDL::ChainIkSolverPos_LMA *ikSolverPos_;
KDL::JntArray q_;
if (!kdl_parser::treeFromString(robotDescription,tree))
ROS_ERROR_STREAM("Failed to construct KDL tree.");
- KDL::Chain chain;
- if (!tree.getChain("origin_link","tool_link",chain))
+ if (!tree.getChain("origin_link","tool_link",chain_))
ROS_ERROR_STREAM("Failed to get chain from KDL tree.");
- q_.resize(chain.getNrOfJoints());
+ q_.resize(chain_.getNrOfJoints());
goal_.Identity();
goal_.p.x(0.61);
Eigen::Matrix<double,6,1> L;
L << 1.0 , 1.0 , 1.0, 0.01, 0.01, 0.01;
-
- ikSolverPos_=new KDL::ChainIkSolverPos_LMA(chain,L);
- ikSolverPos_->display_information=true;
-
-/*
- std::cout << "q_=" << q_ << std::endl;
- std::cout << "goal=" << goal_ << std::endl;
-
- KDL::JntArray q_out=q_;
- int error=0;
- if((error=ikSolverPos_->CartToJnt(q_,goal_,q_out)) < 0)
- ROS_ERROR_STREAM("Failed to compute invere kinematics: (" << error << ") "
- << ikSolverPos_->strError(error));
- q_=q_out;
- std::cout << "q_=" << q_ << std::endl;
-*/
+
+ // A copy of chain_ is not created inside!
+ ikSolverPos_=new KDL::ChainIkSolverPos_LMA(chain_,L);
+ ikSolverPos_->display_information=false;
}
Q2dTeleop::~Q2dTeleop(void)
publish();
}
+#define KDL_IK
void Q2dTeleop::publish(void)
{
-/*
- std::cout << "q_=" << q_ << std::endl;
- std::cout << "goal=" << goal_ << std::endl;
-
+#ifdef KDL_IK
KDL::JntArray q_out=q_;
int error=0;
if((error=ikSolverPos_->CartToJnt(q_,goal_,q_out)) < 0)
ROS_ERROR_STREAM("Failed to compute invere kinematics: (" << error << ") "
<< ikSolverPos_->strError(error));
q_=q_out;
- std::cout << "q_=" << q_ << std::endl;
-*/
-
+#else
+ // Algebric inverse kinematics
const double l1=0.343;
const double l2=0.267;
double c1=(sqr(goal_.p.x())+sqr(goal_.p.y())-sqr(l1)-sqr(l2))/2/l1/l2;
q_(1)=q1b;
}
}
-
+#endif
+
std_msgs::Float64 shoulderCmd;
std_msgs::Float64 elbowCmd;