evaluate_state_operations_speed.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, 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 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 
40 #include <ros/ros.h>
41 
42 static const std::string ROBOT_DESCRIPTION = "robot_description";
43 
44 int main(int argc, char** argv)
45 {
46  ros::init(argc, argv, "evaluate_state_operations_speed");
47 
49  spinner.start();
50 
52  ros::Duration(0.5).sleep();
53 
54  moveit::core::RobotModelConstPtr robot_model = rml.getModel();
55  if (robot_model)
56  {
57  static const int N = 10000;
58  moveit::core::RobotState state(robot_model);
59 
60  printf("Evaluating model '%s' using %d trials for each test\n", robot_model->getName().c_str(), N);
61 
64 
65  printf("Evaluating FK Default ...\n");
66  for (int i = 0; i < N; ++i)
67  {
68  moveit::tools::Profiler::Begin("FK Default");
69  state.setToDefaultValues();
70  state.update();
71  moveit::tools::Profiler::End("FK Default");
72  }
73 
74  printf("Evaluating FK Random ...\n");
75  for (int i = 0; i < N; ++i)
76  {
77  moveit::tools::Profiler::Begin("FK Random");
78  state.setToRandomPositions();
79  state.update();
80  moveit::tools::Profiler::End("FK Random");
81  }
82 
83  std::vector<moveit::core::RobotState*> copies(N, (moveit::core::RobotState*)nullptr);
84  printf("Evaluating Copy State ...\n");
85  for (int i = 0; i < N; ++i)
86  {
87  moveit::tools::Profiler::Begin("Copy State");
88  copies[i] = new moveit::core::RobotState(state);
89  moveit::tools::Profiler::End("Copy State");
90  }
91 
92  printf("Evaluating Free State ...\n");
93  for (int i = 0; i < N; ++i)
94  {
95  moveit::tools::Profiler::Begin("Free State");
96  delete copies[i];
97  moveit::tools::Profiler::End("Free State");
98  }
99 
100  const std::vector<std::string>& groups = robot_model->getJointModelGroupNames();
101  for (const std::string& group : groups)
102  {
103  printf("\n");
104  const moveit::core::JointModelGroup* jmg = robot_model->getJointModelGroup(group);
105 
106  printf("%s: Evaluating FK Random ...\n", group.c_str());
107  std::string pname = group + ":FK Random";
108  for (int i = 0; i < N; ++i)
109  {
111  state.setToRandomPositions(jmg);
112  state.update();
114  }
115  }
116 
119  }
120  else
121  ROS_ERROR("Unable to initialize robot model.");
122 
123  ros::shutdown();
124  return 0;
125 }
moveit::tools::Profiler::Status
static void Status(std::ostream &out=std::cout, bool merge=true)
moveit::tools::Profiler::Begin
static void Begin(const std::string &name)
ROBOT_DESCRIPTION
static const std::string ROBOT_DESCRIPTION
Definition: evaluate_state_operations_speed.cpp:42
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ros::AsyncSpinner
ros::shutdown
ROSCPP_DECL void shutdown()
robot_model_loader::RobotModelLoader
Definition: robot_model_loader.h:80
moveit::tools::Profiler::Stop
static void Stop()
moveit::core::RobotState
moveit::core::RobotState::setToRandomPositions
void setToRandomPositions()
robot_state.h
spinner
void spinner()
moveit::tools::Profiler::Start
static void Start()
moveit::core::RobotState::update
void update(bool force=false)
moveit::core::RobotState::setToDefaultValues
void setToDefaultValues()
ROS_ERROR
#define ROS_ERROR(...)
main
int main(int argc, char **argv)
Definition: evaluate_state_operations_speed.cpp:44
moveit::core::JointModelGroup
moveit::tools::Profiler::End
static void End(const std::string &name)
ros::Duration::sleep
bool sleep() const
profiler.h
ros::Duration
moveit::tools::Profiler::Clear
static void Clear()
robot_model_loader::RobotModelLoader::getModel
const moveit::core::RobotModelPtr & getModel() const
Get the constructed planning_models::RobotModel.
Definition: robot_model_loader.h:118
robot_model_loader.h


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Thu Jan 9 2025 03:24:37