40#include <benchmark/benchmark.h>
42#include <kdl_parser/kdl_parser.hpp>
43#include <kdl/treejnttojacsolver.hpp>
54Eigen::Isometry3d createTestIsometry()
57 return Eigen::Translation3d(1, 2, 3) * Eigen::AngleAxisd(0.13 * M_PI, Eigen::Vector3d::UnitX()) *
58 Eigen::AngleAxisd(0.29 * M_PI, Eigen::Vector3d::UnitY()) *
59 Eigen::AngleAxisd(0.42 * M_PI, Eigen::Vector3d::UnitZ());
66static void multiplyAffineTimesMatrixNoAlias(benchmark::State& st)
68 Eigen::Isometry3d isometry = createTestIsometry();
69 Eigen::Affine3d result;
72 benchmark::DoNotOptimize(result.affine().noalias() = isometry.affine() * isometry.matrix());
73 benchmark::ClobberMemory();
78static void multiplyMatrixTimesMatrixNoAlias(benchmark::State& st)
80 Eigen::Isometry3d isometry = createTestIsometry();
81 Eigen::Isometry3d result;
84 benchmark::DoNotOptimize(result.matrix().noalias() = isometry.matrix() * isometry.matrix());
85 benchmark::ClobberMemory();
90static void multiplyIsometryTimesIsometryNoAlias(benchmark::State& st)
92 Eigen::Isometry3d isometry = createTestIsometry();
93 Eigen::Isometry3d result;
96 benchmark::DoNotOptimize(result.affine().noalias() = isometry.affine() * isometry.matrix());
97 benchmark::ClobberMemory();
102static void multiplyMatrixTimesMatrix(benchmark::State& st)
104 Eigen::Isometry3d isometry = createTestIsometry();
105 Eigen::Isometry3d result;
108 benchmark::DoNotOptimize(result.matrix() = isometry.matrix() * isometry.matrix());
109 benchmark::ClobberMemory();
113static void multiplyIsometryTimesIsometry(benchmark::State& st)
115 Eigen::Isometry3d isometry = createTestIsometry();
116 Eigen::Isometry3d result;
119 benchmark::DoNotOptimize(result = isometry * isometry);
120 benchmark::ClobberMemory();
125static void inverseIsometry3d(benchmark::State& st)
127 Eigen::Isometry3d isometry = createTestIsometry();
128 Eigen::Isometry3d result;
131 benchmark::DoNotOptimize(result = isometry.inverse());
132 benchmark::ClobberMemory();
137static void inverseAffineIsometry(benchmark::State& st)
139 Eigen::Affine3d affine = createTestIsometry();
140 Eigen::Affine3d result;
143 benchmark::DoNotOptimize(result = affine.inverse(Eigen::Isometry));
144 benchmark::ClobberMemory();
149static void inverseAffine(benchmark::State& st)
151 Eigen::Affine3d affine = createTestIsometry();
152 Eigen::Affine3d result;
155 benchmark::DoNotOptimize(result = affine.inverse());
156 benchmark::ClobberMemory();
161static void inverseMatrix4d(benchmark::State& st)
163 Eigen::Affine3d affine = createTestIsometry();
164 Eigen::Affine3d result;
167 benchmark::DoNotOptimize(result = affine.matrix().inverse());
168 benchmark::ClobberMemory();
174 void SetUp(const ::benchmark::State& )
override
176 std::ignore = rcutils_logging_set_logger_level(
"moveit_robot_model.robot_model", RCUTILS_LOG_SEVERITY_WARN);
182 std::vector<moveit::core::RobotState> states;
184 for (
size_t i = 0; i < num; i++)
190 std::vector<moveit::core::RobotState> states;
192 for (
size_t i = 0; i < num; i++)
193 states.emplace_back(state);
199 std::vector<size_t> result(num);
200 std::iota(result.begin(), result.end(), 0);
202 std::mt19937 generator;
203 std::shuffle(result.begin(), result.end(), generator);
215 auto states = constructStates(st.range(0));
216 benchmark::DoNotOptimize(states);
217 benchmark::ClobberMemory();
230 auto states = constructStates(st.range(0), state);
231 benchmark::DoNotOptimize(states);
232 benchmark::ClobberMemory();
239 auto states = constructStates(st.range(0));
240 auto permutation = randomPermutation(states.size());
243 for (
auto i : permutation)
245 states[i].setToRandomPositions();
258 st.SkipWithError(
"The planning group doesn't exist.");
263 random_numbers::RandomNumberGenerator rng(0);
283 st.SkipWithError(
"The planning group doesn't exist.");
287 if (!kdl_parser::treeFromUrdfModel(*robot_model->getURDF(), kdl_tree))
289 st.SkipWithError(
"Can't create KDL tree.");
293 KDL::TreeJntToJacSolver jacobian_solver(kdl_tree);
294 KDL::Jacobian jacobian(kdl_tree.getNrOfJoints());
295 KDL::JntArray kdl_q(kdl_tree.getNrOfJoints());
299 random_numbers::RandomNumberGenerator rng(0);
308 jacobian_solver.JntToJac(kdl_q, jacobian, tip_link);
324 ->RangeMultiplier(10)
326 ->Unit(benchmark::kMillisecond);
328 ->RangeMultiplier(10)
330 ->Unit(benchmark::kMillisecond);
const std::vector< std::string > & getLinkModelNames() const
Get the names of the links that are part of this joint group.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
bool getJacobian(const JointModelGroup *group, const LinkModel *link, const Eigen::Vector3d &reference_point_position, Eigen::MatrixXd &jacobian, bool use_quaternion_representation=false) const
Compute the Jacobian with reference to a particular point on a given link, for a specified group.
void copyJointGroupPositions(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the position values of the variables that make up the group into another loca...
const JointModelGroup * getJointModelGroup(const std::string &group) const
Get the model of a particular joint group.
void updateLinkTransforms()
Update the reference frame transforms for links. This call is needed before using the transforms of l...
void setToRandomPositions()
Set all joints to random values. Values will be within default bounds.
void update(bool force=false)
Update all transforms.
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &package_name, const std::string &urdf_relative_path, const std::string &srdf_relative_path)
Loads a robot model given a URDF and SRDF file in a package.
BENCHMARK(multiplyAffineTimesMatrixNoAlias)
BENCHMARK_REGISTER_F(RobotStateBenchmark, update) -> RangeMultiplier(10) ->Range(10, 10000) ->Unit(benchmark::kMillisecond)
BENCHMARK_DEFINE_F(RobotStateBenchmark, construct)(benchmark
constexpr char PANDA_TEST_ROBOT[]
constexpr char PANDA_TEST_GROUP[]
std::vector< moveit::core::RobotState > constructStates(size_t num, const moveit::core::RobotState &state)
std::vector< moveit::core::RobotState > constructStates(size_t num)
moveit::core::RobotModelPtr robot_model
void SetUp(const ::benchmark::State &) override
std::vector< size_t > randomPermutation(size_t num)