-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark for 'getJacobian' (#2326)
- Loading branch information
1 parent
3e5af1b
commit 47d92ef
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
moveit_core/robot_state/test/robot_state_jacobian_benchmark.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2023, PickNik Robotics. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the Willow Garage nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
/* Author: Mario Prats */ | ||
|
||
// To run this benchmark, 'cd' to the build/moveit_core/robot_state directory and directly run the binary. | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <moveit/robot_model/robot_model.h> | ||
#include <moveit/robot_state/robot_state.h> | ||
#include <moveit/utils/robot_model_test_utils.h> | ||
#include <random_numbers/random_numbers.h> | ||
|
||
// Robot and planning group for which the Jacobian will be benchmarked. | ||
constexpr char TEST_ROBOT[] = "panda"; | ||
constexpr char TEST_GROUP[] = "panda_arm"; | ||
|
||
static void BM_MoveItJacobian(benchmark::State& st) | ||
{ | ||
// Load a test robot model. | ||
const moveit::core::RobotModelPtr& robot_model = moveit::core::loadTestingRobotModel(TEST_ROBOT); | ||
|
||
// Make sure the group exists, otherwise exit early with an error. | ||
if (!robot_model->hasJointModelGroup(TEST_GROUP)) | ||
{ | ||
st.SkipWithError("The planning group doesn't exist."); | ||
return; | ||
} | ||
|
||
// Robot state. | ||
moveit::core::RobotState kinematic_state(robot_model); | ||
const moveit::core::JointModelGroup* jmg = kinematic_state.getJointModelGroup(TEST_GROUP); | ||
|
||
// Provide our own random number generator to setToRandomPositions to get a deterministic sequence of joint | ||
// configurations. | ||
random_numbers::RandomNumberGenerator rng(0); | ||
|
||
for (auto _ : st) | ||
{ | ||
// Time only the jacobian computation, not the forward kinematics. | ||
st.PauseTiming(); | ||
kinematic_state.setToRandomPositions(jmg, rng); | ||
kinematic_state.updateLinkTransforms(); | ||
st.ResumeTiming(); | ||
kinematic_state.getJacobian(jmg); | ||
} | ||
} | ||
|
||
BENCHMARK(BM_MoveItJacobian); |