moveit2
The MoveIt Motion Planning Framework for ROS 2.
prismatic_joint_model.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
38 #include <limits>
39 
40 namespace moveit
41 {
42 namespace core
43 {
44 PrismaticJointModel::PrismaticJointModel(const std::string& name, size_t joint_index, size_t first_variable_index)
45  : JointModel(name, joint_index, first_variable_index), axis_(0.0, 0.0, 0.0)
46 {
47  type_ = PRISMATIC;
48  variable_names_.push_back(getName());
49  variable_bounds_.resize(1);
50  variable_bounds_[0].position_bounded_ = true;
51  variable_bounds_[0].min_position_ = -std::numeric_limits<double>::max();
52  variable_bounds_[0].max_position_ = std::numeric_limits<double>::max();
55 }
56 
58 {
59  return 1;
60 }
61 
62 double PrismaticJointModel::getMaximumExtent(const Bounds& other_bounds) const
63 {
64  return variable_bounds_[0].max_position_ - other_bounds[0].min_position_;
65 }
66 
67 void PrismaticJointModel::getVariableDefaultPositions(double* values, const Bounds& bounds) const
68 {
69  // if zero is a valid value
70  if (bounds[0].min_position_ <= 0.0 && bounds[0].max_position_ >= 0.0)
71  {
72  values[0] = 0.0;
73  }
74  else
75  {
76  values[0] = (bounds[0].min_position_ + bounds[0].max_position_) / 2.0;
77  }
78 }
79 
80 bool PrismaticJointModel::satisfiesPositionBounds(const double* values, const Bounds& bounds, double margin) const
81 {
82  return !(values[0] < bounds[0].min_position_ - margin || values[0] > bounds[0].max_position_ + margin);
83 }
84 
85 void PrismaticJointModel::getVariableRandomPositions(random_numbers::RandomNumberGenerator& rng, double* values,
86  const Bounds& bounds) const
87 {
88  values[0] = rng.uniformReal(bounds[0].min_position_, bounds[0].max_position_);
89 }
90 
91 void PrismaticJointModel::getVariableRandomPositionsNearBy(random_numbers::RandomNumberGenerator& rng, double* values,
92  const Bounds& bounds, const double* near,
93  const double distance) const
94 {
95  values[0] = rng.uniformReal(std::max(bounds[0].min_position_, near[0] - distance),
96  std::min(bounds[0].max_position_, near[0] + distance));
97 }
98 
99 bool PrismaticJointModel::enforcePositionBounds(double* values, const Bounds& bounds) const
100 {
101  if (values[0] < bounds[0].min_position_)
102  {
103  values[0] = bounds[0].min_position_;
104  return true;
105  }
106  else if (values[0] > bounds[0].max_position_)
107  {
108  values[0] = bounds[0].max_position_;
109  return true;
110  }
111  return false;
112 }
113 
114 double PrismaticJointModel::distance(const double* values1, const double* values2) const
115 {
116  return fabs(values1[0] - values2[0]);
117 }
118 
119 void PrismaticJointModel::interpolate(const double* from, const double* to, const double t, double* state) const
120 {
121  state[0] = from[0] + (to[0] - from[0]) * t;
122 }
123 
124 void PrismaticJointModel::computeTransform(const double* joint_values, Eigen::Isometry3d& transf) const
125 {
126  double* d = transf.data();
127  d[0] = 1.0;
128  d[1] = 0.0;
129  d[2] = 0.0;
130  d[3] = 0.0;
131 
132  d[4] = 0.0;
133  d[5] = 1.0;
134  d[6] = 0.0;
135  d[7] = 0.0;
136 
137  d[8] = 0.0;
138  d[9] = 0.0;
139  d[10] = 1.0;
140  d[11] = 0.0;
141 
142  d[12] = axis_.x() * joint_values[0];
143  d[13] = axis_.y() * joint_values[0];
144  d[14] = axis_.z() * joint_values[0];
145  d[15] = 1.0;
146 
147  // transf.setIdentity();
148  // transf.translation() = Eigen::Vector3d(axis_ * joint_values[0]);
149 }
150 
151 void PrismaticJointModel::computeVariablePositions(const Eigen::Isometry3d& transf, double* joint_values) const
152 {
153  joint_values[0] = transf.translation().dot(axis_);
154 }
155 
156 } // end of namespace core
157 } // end of namespace moveit
A joint from the robot. Models the transform that this joint applies in the kinematic chain....
Definition: joint_model.h:117
VariableIndexMap variable_index_map_
Map from variable names to the corresponding index in variable_names_ (indexing makes sense within th...
Definition: joint_model.h:506
JointType type_
The type of joint.
Definition: joint_model.h:491
Bounds variable_bounds_
The bounds for each variable (low, high) in the same order as variable_names_.
Definition: joint_model.h:500
std::vector< VariableBounds > Bounds
The datatype for the joint bounds.
Definition: joint_model.h:131
const std::string & getName() const
Get the name of the joint.
Definition: joint_model.h:145
double getMaximumExtent() const
Definition: joint_model.h:459
std::vector< std::string > variable_names_
The full names to use for the variables that make up this joint.
Definition: joint_model.h:497
void getVariableRandomPositionsNearBy(random_numbers::RandomNumberGenerator &rng, double *values, const Bounds &other_bounds, const double *near, const double distance) const override
Provide random values for the joint variables (within specified bounds). Enough memory is assumed to ...
bool satisfiesPositionBounds(const double *values, const Bounds &other_bounds, double margin) const override
Check if the set of position values for the variables of this joint are within bounds,...
void interpolate(const double *from, const double *to, const double t, double *state) const override
Computes the state that lies at time t in [0, 1] on the segment that connects from state to to state....
void getVariableDefaultPositions(double *values, const Bounds &other_bounds) const override
Provide a default value for the joint given the joint variable bounds. Most joints will use the defau...
void getVariableRandomPositions(random_numbers::RandomNumberGenerator &rng, double *values, const Bounds &other_bounds) const override
Provide random values for the joint variables (within specified bounds). Enough memory is assumed to ...
Eigen::Vector3d axis_
The axis of the joint.
void computeTransform(const double *joint_values, Eigen::Isometry3d &transf) const override
Given the joint values for a joint, compute the corresponding transform. The computed transform is gu...
void computeVariablePositions(const Eigen::Isometry3d &transf, double *joint_values) const override
Given the transform generated by joint, compute the corresponding joint values. Make sure the passed ...
double distance(const double *values1, const double *values2) const override
Compute the distance between two joint states of the same model (represented by the variable values)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW PrismaticJointModel(const std::string &name, size_t joint_index, size_t first_variable_index)
unsigned int getStateSpaceDimension() const override
Get the dimension of the state space that corresponds to this joint.
bool enforcePositionBounds(double *values, const Bounds &other_bounds) const override
Force the specified values to be inside bounds and normalized. Quaternions are normalized,...
Main namespace for MoveIt.
Definition: exceptions.h:43
double distance(const urdf::Pose &transform)
Definition: pr2_arm_ik.h:55
name
Definition: setup.py:7