39 #include <boost/program_options/parsers.hpp>
40 #include <boost/program_options/variables_map.hpp>
44 using namespace std::chrono_literals;
54 static const std::string ROBOT_DESCRIPTION =
"robot_description";
59 RCLCPP_INFO(
getLogger(),
"Starting thread %u",
id);
60 rclcpp::Clock clock(RCL_ROS_TIME);
62 rclcpp::Time start = clock.now();
63 for (
unsigned int i = 0; i < trials; ++i)
68 double duration = (clock.now() - start).seconds();
69 RCLCPP_INFO(
getLogger(),
"Thread %u performed %lf collision checks per second",
id,
70 static_cast<double>(trials) / duration);
73 int main(
int argc,
char** argv)
75 rclcpp::init(argc, argv);
76 auto node = rclcpp::Node::make_shared(
"evaluate_collision_checking_speed");
79 unsigned int nthreads = 2;
80 unsigned int trials = 10000;
81 boost::program_options::options_description desc;
82 desc.add_options()(
"nthreads", boost::program_options::value<unsigned int>(&nthreads)->default_value(nthreads),
83 "Number of threads to use")(
84 "trials", boost::program_options::value<unsigned int>(&trials)->default_value(trials),
85 "Number of collision checks to perform with each thread")(
"wait",
86 "Wait for a user command (so the planning scene can be "
87 "updated in the background)")(
"help",
"this screen");
88 boost::program_options::variables_map vm;
89 boost::program_options::parsed_options po = boost::program_options::parse_command_line(argc, argv, desc);
90 boost::program_options::store(po, vm);
91 boost::program_options::notify(vm);
95 std::cout << desc <<
'\n';
99 rclcpp::executors::MultiThreadedExecutor executor;
100 executor.add_node(node);
105 if (vm.count(
"wait"))
109 std::cout <<
"Listening to planning scene updates. Press Enter to continue ..." <<
'\n';
113 rclcpp::sleep_for(500ms);
115 std::vector<moveit::core::RobotStatePtr> states;
116 RCLCPP_INFO(node->get_logger(),
"Sampling %u valid states...", nthreads);
117 for (
unsigned int i = 0; i < nthreads; ++i)
131 states.push_back(moveit::core::RobotStatePtr(state));
134 std::vector<std::thread*> threads;
136 for (
unsigned int i = 0; i < states.size(); ++i)
138 threads.push_back(
new std::thread([i, trials, &scene = *psm.
getPlanningScene(), &state = *states[i]] {
139 return runCollisionDetection(i, trials, scene, state);
143 for (
unsigned int i = 0; i < states.size(); ++i)
150 RCLCPP_ERROR(node->get_logger(),
"Planning scene not configured");
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void setToRandomPositions()
Set all joints to random values. Values will be within default bounds.
void update(bool force=false)
Update all transforms.
This class maintains the representation of the environment as seen by a planning instance....
void checkCollision(const collision_detection::CollisionRequest &req, collision_detection::CollisionResult &res)
Check whether the current state is in collision, and if needed, updates the collision transforms of t...
PlanningSceneMonitor Subscribes to the topic planning_scene.
const planning_scene::PlanningScenePtr & getPlanningScene()
Avoid this function! Returns an unsafe pointer to the current planning scene.
void startSceneMonitor(const std::string &scene_topic=DEFAULT_PLANNING_SCENE_TOPIC)
Start the scene monitor (ROS topic-based)
void startWorldGeometryMonitor(const std::string &collision_objects_topic=DEFAULT_COLLISION_OBJECT_TOPIC, const std::string &planning_scene_world_topic=DEFAULT_PLANNING_SCENE_WORLD_TOPIC, const bool load_octomap_monitor=true)
Start the OccupancyMapMonitor and listening for:
void runCollisionDetection(unsigned int id, unsigned int trials, const planning_scene::PlanningScene &scene, const moveit::core::RobotState &state)
int main(int argc, char **argv)
rclcpp::Logger getLogger()
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
void setNodeLoggerName(const std::string &name)
Call once after creating a node to initialize logging namespaces.
Representation of a collision checking request.
Representation of a collision checking result.
bool collision
True if collision was found, false otherwise.