54 CartesianTwistController::CartesianTwistController() :
73 std::string tip_link, root_link;
74 nh.
param<std::string>(
"root_name", root_link,
"torso_lift_link");
75 nh.
param<std::string>(
"tip_name", tip_link,
"wrist_roll_link");
79 if (!model.initParam(
"robot_description"))
89 ROS_ERROR(
"Could not construct tree from URDF");
96 ROS_ERROR(
"Could not construct chain from URDF");
113 if (
joints_.size() != num_joints)
115 ROS_ERROR(
"Inconsistant joint count %d, %d", num_joints,
int(
joints_.size()));
119 for (
unsigned ii = 0; ii < num_joints; ++ii)
138 "Unable to start, not initialized.");
143 for (
unsigned ii = 0; ii <
joints_.size(); ++ii)
175 boost::mutex::scoped_lock lock(
mutex_);
196 unsigned num_joints =
joints_.size();
206 for (
unsigned ii = 0; ii < num_joints; ++ii)
213 double max_vel = 0.0;
214 for (
unsigned ii = 0; ii < num_joints; ++ii)
216 max_vel = std::max(std::abs(
tgt_jnt_vel_(ii)), max_vel);
219 double joint_velocity_limit = 0.5;
221 if (max_vel > joint_velocity_limit)
223 double scale = joint_velocity_limit / max_vel;
224 for (
unsigned ii = 0; ii < num_joints; ++ii)
232 for (
unsigned ii = 0; ii < num_joints; ++ii)
244 double accel_limit = 1.0;
245 double vel_delta_limit = accel_limit * dt.
toSec();
246 for (
unsigned ii = 0; ii < num_joints; ++ii)
249 if (vel_delta > vel_delta_limit)
251 scale = std::min(scale, vel_delta_limit/vel_delta);
257 ROS_ERROR_THROTTLE(1.0,
"CartesianTwistController: acceleration limit produces non-positive scale %f", scale);
264 for (
unsigned ii = 0; ii < num_joints; ++ii)
270 double dt_sec = dt.
toSec();
271 for (
unsigned ii = 0; ii < num_joints; ++ii)
277 for (
unsigned ii = 0; ii < num_joints; ++ii)
279 if (!
joints_[ii]->isContinuous())
293 for (
size_t ii = 0; ii <
joints_.size(); ++ii)
305 ROS_ERROR(
"CartesianTwistController: Cannot accept goal, controller is not initialized.");
309 if (goal->header.frame_id.empty())
316 twist(0) = goal->twist.linear.x;
317 twist(1) = goal->twist.linear.y;
318 twist(2) = goal->twist.linear.z;
319 twist(3) = goal->twist.angular.x;
320 twist(4) = goal->twist.angular.y;
321 twist(5) = goal->twist.angular.z;
323 for (
int ii=0; ii<6; ++ii)
325 if (!std::isfinite(twist(ii)))
327 ROS_ERROR_THROTTLE(1.0,
"Twist command value (%d) is not finite : %f", ii, twist(ii));
335 boost::mutex::scoped_lock lock(
mutex_);
343 ROS_ERROR(
"CartesianTwistController: Cannot start, blocked by another controller.");
350 std::vector<std::string> names;
boost::shared_ptr< KDL::ChainIkSolverVel_wdls > solver_
KDL::JntArray last_tgt_jnt_vel_
const Segment & getSegment(unsigned int nr) const
KDL::JntArray tgt_jnt_vel_
ros::Time last_command_time_
KDL_PARSER_PUBLIC bool treeFromUrdfModel(const urdf::ModelInterface &robot_model, KDL::Tree &tree)
virtual int init(ros::NodeHandle &nh, ControllerManager *manager)
Initialize the controller and any required data structures.
#define ROS_DEBUG_THROTTLE(rate,...)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
unsigned int getNrOfSegments() const
void command(const geometry_msgs::TwistStamped::ConstPtr &goal)
Controller command.
virtual int requestStart(const std::string &name)
ros::Subscriber command_sub_
boost::shared_ptr< KDL::ChainFkSolverPos_recursive > fksolver_
#define ROS_ERROR_THROTTLE(rate,...)
virtual int requestStop(const std::string &name)
const std::string & getName() const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const Joint & getJoint() const
virtual void update(const ros::Time &now, const ros::Duration &dt)
This is the update loop for the controller.
unsigned int getNrOfJoints() const
virtual std::vector< std::string > getClaimedNames()
Get the names of joints/controllers which this controller exclusively claims.
ControllerManager * manager_
void resize(unsigned int newSize)
virtual bool stop(bool force)
Attempt to stop the controller. This should be called only by the ControllerManager instance...
bool getChain(const std::string &chain_root, const std::string &chain_tip, Chain &chain) const
KDL::JntArray tgt_jnt_pos_
virtual int init(ros::NodeHandle &nh, ControllerManager *manager)
virtual bool reset()
Cleanly reset the controller to it's initial state. Some controllers may choose to stop themselves...
#define ROS_ERROR_NAMED(name,...)
virtual std::vector< std::string > getCommandedNames()
Get the names of joints/controllers which this controller commands.
virtual bool start()
Attempt to start the controller. This should be called only by the ControllerManager instance...
JointHandlePtr getJointHandle(const std::string &name)
std::vector< JointHandlePtr > joints_
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
const JointType & getType() const
KDL::Twist twist_command_
std::string twist_command_frame_