Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraint samplers #60

Merged
merged 25 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3403b96
Port constraint_samplers to ROS 2
vmayoral Mar 30, 2019
abd451d
constraint_samplers, adapt logger according to https://github.com/ros…
vmayoral Mar 30, 2019
8b3fdcc
moveit_core constraint-samplers - library as shared
ahcorde May 24, 2019
c48a10a
Fixing constraint samplers tests
ahcorde Apr 26, 2019
a58c4d9
Fixing constraint_samplers tests
ahcorde Apr 26, 2019
e2e067e
Fixes for building in OS X
vmayoral May 16, 2019
f9be4c1
moveit_core constraint_samplers - fixing logger variables
ahcorde May 24, 2019
d71434a
Merge branch 'master' into constraint-samplers
ahcorde May 24, 2019
e7aa185
moveit_core constraint_samples - Fix whitespace in CMakeLists.txt
ahcorde May 29, 2019
c8fb7c1
Fixing endtime to use it inline
anasarrak Jun 13, 2019
082b80f
fix passing clock.now to stamp
anasarrak Jun 13, 2019
a527755
Fix loop_time
anasarrak Jun 13, 2019
c7a3a04
Reverting back override to pr2_arm_kinematics_plugin
anasarrak Jun 13, 2019
02f0eb3
Remove updateInternalDataStructures
anasarrak Jun 13, 2019
1611306
Move constraint_sampler logger to the appropriate namespace
anasarrak Jun 13, 2019
206c27d
Moving default_contraint_sampler logger into the namespace
anasarrak Jun 13, 2019
322d452
clang-format
anasarrak Jun 13, 2019
05ad105
Update logger test_constraint_samplers
anasarrak Jun 13, 2019
87bd1d5
Constraint_sampler cmakelist formating
anasarrak Jun 14, 2019
a4c9c83
Move constraint_sampler_tools logger to .hpp
anasarrak Jun 14, 2019
23e2af6
Using ros_time instead of rcl_system_time
anasarrak Jun 14, 2019
d9872d1
Moving pr2_arm_ik logger to .h
anasarrak Jun 14, 2019
01ca1b5
adding RCL_ROS_TIME on pr2_arm_kinematics_plugin
anasarrak Jun 14, 2019
74f0720
removing dead code
anasarrak Jun 14, 2019
abf4a74
clang format
anasarrak Jun 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions moveit_core/constraint_samplers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(MOVEIT_LIB_NAME moveit_constraint_samplers)

add_library(${MOVEIT_LIB_NAME}
add_library(${MOVEIT_LIB_NAME} SHARED
src/constraint_sampler.cpp
src/constraint_sampler_manager.cpp
src/constraint_sampler_tools.cpp
Expand All @@ -9,40 +9,73 @@ add_library(${MOVEIT_LIB_NAME}
)
set_target_properties(${MOVEIT_LIB_NAME} PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}")

target_link_libraries(${MOVEIT_LIB_NAME}
ament_target_dependencies(${MOVEIT_LIB_NAME}
moveit_robot_state
moveit_kinematic_constraints
moveit_kinematics_base
moveit_planning_scene
${catkin_LIBRARIES} ${urdfdom_LIBRARIES} ${urdfdom_headers_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(${MOVEIT_LIB_NAME} ${catkin_EXPORTED_TARGETS})
urdf
urdfdom
urdfdom_headers
visualization_msgs
)

target_link_libraries(${MOVEIT_LIB_NAME}
moveit_robot_trajectory
moveit_robot_state
moveit_kinematic_constraints
)

install(TARGETS ${MOVEIT_LIB_NAME}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

install(DIRECTORY include/ DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION})
install(DIRECTORY include/ DESTINATION include)

if(CATKIN_ENABLE_TESTING)
if(BUILD_TESTING)
find_package(orocos_kdl REQUIRED)
find_package(angles REQUIRED)
find_package(tf2_kdl REQUIRED)
find_package(moveit_resources REQUIRED)

include_directories(${orocos_kdl_INCLUDE_DIRS} ${angles_INCLUDE_DIRS} ${tf2_kdl_INCLUDE_DIRS} ${moveit_resources_INCLUDE_DIRS})
include_directories(${orocos_kdl_INCLUDE_DIRS} ${angles_INCLUDE_DIRS} ${tf2_kdl_INCLUDE_DIRS} ${moveit_resources_INCLUDE_DIRS})

if(WIN32)
# set(append_library_dirs "$<TARGET_FILE_DIR:${PROJECT_NAME}>;$<TARGET_FILE_DIR:${PROJECT_NAME}_TestPlugins1>")
else()
set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_BINARY_DIR}/../utils;${CMAKE_CURRENT_BINARY_DIR}/../robot_state;${CMAKE_CURRENT_BINARY_DIR}/../planning_scene;${CMAKE_CURRENT_BINARY_DIR}/../robot_model;${CMAKE_CURRENT_BINARY_DIR}/../kinematics_constraint")
endif()

catkin_add_gtest(test_constraint_samplers
ament_add_gtest(test_constraint_samplers
test/test_constraint_samplers.cpp
test/pr2_arm_kinematics_plugin.cpp
test/pr2_arm_ik.cpp
)

target_include_directories(test_constraint_samplers PUBLIC
${geometry_msgs_INCLUDE_DIRS}
)

target_link_libraries(test_constraint_samplers
moveit_constraint_samplers
moveit_kinematic_constraints
moveit_planning_scene
moveit_test_utils
moveit_utils
moveit_robot_state
${MOVEIT_LIB_NAME}
${catkin_LIBRARIES}
${angles_LIBRARIES}
${orocos_kdl_LIBRARIES}
${urdf_LIBRARIES}
${tf2_LIBRARIES}
${tf2_kdl_LIBRARIES}
${tf2_ros_LIBRARIES}
${kdl_parser_LIBRARIES}
${OCTOMAP_LIBRARIES}
${orcos_kdl_LIBRARIES}
${urdfdom_LIBRARIES}
${urdfdom_headers_LIBRARIES}
${rclcpp_headers_LIBRARIES}
${geometric_shapes_LIBRARIES}
mlautman marked this conversation as resolved.
Show resolved Hide resolved
)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <moveit/planning_scene/planning_scene.h>
#include <moveit/kinematic_constraints/kinematic_constraint.h>
#include <vector>

#include "rclcpp/rclcpp.hpp"
/**
* \brief The constraint samplers namespace contains a number of
* methods for generating samples based on a constraint or set of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <moveit/constraint_samplers/constraint_sampler.h>
#include <moveit/macros/class_forward.h>
#include "rclcpp/rclcpp.hpp"

namespace constraint_samplers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@

#include <moveit/constraint_samplers/constraint_sampler_allocator.h>
#include <moveit/macros/class_forward.h>
#include "rclcpp/rclcpp.hpp"
#include "rclcpp/clock.hpp"
#include "rclcpp/duration.hpp"

namespace constraint_samplers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@
#define MOVEIT_CONSTRAINT_SAMPLERS_CONSTRAINT_SAMPLER_TOOLS_

#include <moveit/constraint_samplers/constraint_sampler.h>
#include <visualization_msgs/MarkerArray.h>
#include <visualization_msgs/msg/marker_array.hpp>
#include "rclcpp/rclcpp.hpp"

namespace constraint_samplers
{
void visualizeDistribution(const ConstraintSamplerPtr& sampler, const robot_state::RobotState& reference_state,
const std::string& link_name, unsigned int sample_count,
visualization_msgs::MarkerArray& markers);
visualization_msgs::msg::MarkerArray& markers);

void visualizeDistribution(const moveit_msgs::msg::Constraints& constr, const planning_scene::PlanningSceneConstPtr& scene,
const std::string& group, const std::string& link_name, unsigned int sample_count,
visualization_msgs::MarkerArray& markers);
visualization_msgs::msg::MarkerArray& markers);

double countSamplesPerSecond(const ConstraintSamplerPtr& sampler, const robot_state::RobotState& reference_state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <moveit/constraint_samplers/constraint_sampler.h>
#include <moveit/macros/class_forward.h>
#include <random_numbers/random_numbers.h>
#include "rclcpp/rclcpp.hpp"

namespace constraint_samplers
{
Expand Down Expand Up @@ -507,7 +508,7 @@ class IKConstraintSampler : public ConstraintSampler
*
* @return True if IK returns successfully with the timeout, and otherwise false.
*/
bool callIK(const geometry_msgs::Pose& ik_query,
bool callIK(const geometry_msgs::msg::Pose& ik_query,
const kinematics::KinematicsBase::IKCallbackFn& adapted_ik_validity_callback, double timeout,
robot_state::RobotState& state, bool use_as_seed);
bool sampleHelper(robot_state::RobotState& state, const robot_state::RobotState& reference_state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define MOVEIT_CONSTRAINT_SAMPLERS_DEFAULT_UNION_CONSTRAINT_SAMPLER_

#include <moveit/constraint_samplers/constraint_sampler.h>
#include "rclcpp/rclcpp.hpp"

namespace constraint_samplers
{
Expand Down
4 changes: 3 additions & 1 deletion moveit_core/constraint_samplers/src/constraint_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@

#include <moveit/constraint_samplers/constraint_sampler.h>

rclcpp::Logger LOGGER_CONSTRAINT_SAMPLERS = rclcpp::get_logger("moveit").get_child("constraint_samplers");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to put this inside namespace. the methods themselves could be put in a single large namespace block as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


constraint_samplers::ConstraintSampler::ConstraintSampler(const planning_scene::PlanningSceneConstPtr& scene,
const std::string& group_name)
: is_valid_(false), scene_(scene), jmg_(scene->getRobotModel()->getJointModelGroup(group_name)), verbose_(false)
{
if (!jmg_)
{
ROS_ERROR_NAMED("constraint_samplers", "A JointModelGroup should have been specified for the constraint sampler");
RCLCPP_ERROR(LOGGER_CONSTRAINT_SAMPLERS, "A JointModelGroup should have been specified for the constraint sampler");
}
}

Expand Down
34 changes: 18 additions & 16 deletions moveit_core/constraint_samplers/src/constraint_sampler_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <moveit/constraint_samplers/union_constraint_sampler.h>
#include <sstream>

rclcpp::Logger LOGGER_CONTRAINT_SAMPLERS_MANAGER = rclcpp::get_logger("moveit").get_child("constraint_samplers");

constraint_samplers::ConstraintSamplerPtr
constraint_samplers::ConstraintSamplerManager::selectSampler(const planning_scene::PlanningSceneConstPtr& scene,
const std::string& group_name,
Expand All @@ -61,16 +63,16 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
if (!jmg)
return constraint_samplers::ConstraintSamplerPtr();
std::stringstream ss;
ss << constr;
ROS_DEBUG_NAMED("constraint_samplers",
ss << constr.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a way to print the whole message as a string anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that the full constraint should be printed here instead of only the name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such implementation for ROS2. I have asked that on the following issue : ros2/common_interfaces#69 (comment) redirected to ros2/rosidl#259

RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER,
"Attempting to construct constrained state sampler for group '%s', using constraints:\n%s.\n",
jmg->getName().c_str(), ss.str().c_str());

ConstraintSamplerPtr joint_sampler; // location to put chosen joint sampler if needed
// if there are joint constraints, we could possibly get a sampler from those
if (!constr.joint_constraints.empty())
{
ROS_DEBUG_NAMED("constraint_samplers", "There are joint constraints specified. "
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "There are joint constraints specified. "
"Attempting to construct a JointConstraintSampler for group '%s'",
jmg->getName().c_str());

Expand Down Expand Up @@ -108,7 +110,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
JointConstraintSamplerPtr sampler(new JointConstraintSampler(scene, jmg->getName()));
if (sampler->configure(jc))
{
ROS_DEBUG_NAMED("constraint_samplers", "Allocated a sampler satisfying joint constraints for group '%s'",
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Allocated a sampler satisfying joint constraints for group '%s'",
jmg->getName().c_str());
return sampler;
}
Expand All @@ -121,7 +123,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
JointConstraintSamplerPtr sampler(new JointConstraintSampler(scene, jmg->getName()));
if (sampler->configure(jc))
{
ROS_DEBUG_NAMED("constraint_samplers",
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER,
"Temporary sampler satisfying joint constraints for group '%s' allocated. "
"Looking for different types of constraints before returning though.",
jmg->getName().c_str());
Expand All @@ -142,7 +144,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
// should be used
if (ik_alloc)
{
ROS_DEBUG_NAMED("constraint_samplers", "There is an IK allocator for '%s'. "
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "There is an IK allocator for '%s'. "
"Checking for corresponding position and/or orientation constraints",
jmg->getName().c_str());

Expand Down Expand Up @@ -177,7 +179,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
{
// assign the link to a new constraint sampler
used_l[constr.position_constraints[p].link_name] = iks;
ROS_DEBUG_NAMED("constraint_samplers", "Allocated an IK-based sampler for group '%s' "
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Allocated an IK-based sampler for group '%s' "
"satisfying position and orientation constraints on link '%s'",
jmg->getName().c_str(), constr.position_constraints[p].link_name.c_str());
}
Expand Down Expand Up @@ -209,7 +211,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
if (use)
{
used_l[constr.position_constraints[p].link_name] = iks;
ROS_DEBUG_NAMED("constraint_samplers", "Allocated an IK-based sampler for group '%s' "
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Allocated an IK-based sampler for group '%s' "
"satisfying position constraints on link '%s'",
jmg->getName().c_str(), constr.position_constraints[p].link_name.c_str());
}
Expand Down Expand Up @@ -238,7 +240,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
if (use)
{
used_l[constr.orientation_constraints[o].link_name] = iks;
ROS_DEBUG_NAMED("constraint_samplers", "Allocated an IK-based sampler for group '%s' "
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Allocated an IK-based sampler for group '%s' "
"satisfying orientation constraints on link '%s'",
jmg->getName().c_str(), constr.orientation_constraints[o].link_name.c_str());
}
Expand All @@ -258,7 +260,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
}
else if (used_l.size() > 1)
{
ROS_DEBUG_NAMED("constraint_samplers",
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER,
"Too many IK-based samplers for group '%s'. Keeping the one with minimal sampling volume",
jmg->getName().c_str());
// find the sampler with the smallest sampling volume; delete the rest
Expand Down Expand Up @@ -290,7 +292,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
// we now check to see if we can use samplers from subgroups
if (!ik_subgroup_alloc.empty())
{
ROS_DEBUG_NAMED("constraint_samplers", "There are IK allocators for subgroups of group '%s'. "
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "There are IK allocators for subgroups of group '%s'. "
"Checking for corresponding position and/or orientation constraints",
jmg->getName().c_str());

Expand Down Expand Up @@ -321,12 +323,12 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
// if some matching constraints were found, construct the allocator
if (!sub_constr.orientation_constraints.empty() || !sub_constr.position_constraints.empty())
{
ROS_DEBUG_NAMED("constraint_samplers", "Attempting to construct a sampler for the '%s' subgroup of '%s'",
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Attempting to construct a sampler for the '%s' subgroup of '%s'",
it->first->getName().c_str(), jmg->getName().c_str());
ConstraintSamplerPtr cs = selectDefaultSampler(scene, it->first->getName(), sub_constr);
if (cs)
{
ROS_DEBUG_NAMED("constraint_samplers", "Constructed a sampler for the joints corresponding to group '%s', "
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Constructed a sampler for the joints corresponding to group '%s', "
"but part of group '%s'",
it->first->getName().c_str(), jmg->getName().c_str());
some_sampler_valid = true;
Expand All @@ -336,7 +338,7 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
}
if (some_sampler_valid)
{
ROS_DEBUG_NAMED("constraint_samplers", "Constructing sampler for group '%s' as a union of %zu samplers",
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Constructing sampler for group '%s' as a union of %zu samplers",
jmg->getName().c_str(), samplers.size());
return ConstraintSamplerPtr(new UnionConstraintSampler(scene, jmg->getName(), samplers));
}
Expand All @@ -345,12 +347,12 @@ constraint_samplers::ConstraintSamplerManager::selectDefaultSampler(const planni
// if we've gotten here, just return joint sampler
if (joint_sampler)
{
ROS_DEBUG_NAMED("constraint_samplers", "Allocated a sampler satisfying joint constraints for group '%s'",
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "Allocated a sampler satisfying joint constraints for group '%s'",
jmg->getName().c_str());
return joint_sampler;
}

ROS_DEBUG_NAMED("constraint_samplers", "No constraints sampler allocated for group '%s'", jmg->getName().c_str());
RCLCPP_DEBUG(LOGGER_CONTRAINT_SAMPLERS_MANAGER, "No constraints sampler allocated for group '%s'", jmg->getName().c_str());

return ConstraintSamplerPtr();
}
Loading