-
Notifications
You must be signed in to change notification settings - Fork 523
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
Constraint samplers #60
Conversation
vmayoral
commented
Mar 30, 2019
- Unit tests (pending on addressing Unit tests in moveit2 failing AcutronicRobotics/moveit2#13)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general, just some minor changes.
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
ros::WallTime end = ros::WallTime::now() + ros::WallDuration(1.0); | ||
//TODO RCLCPP::WallTimer has not a .now() function, and there is no wallDuration (they use std::chrono::nanoseconds) | ||
// I'll use rclcpp::time, but this is something to fix. | ||
rclcpp::Duration duration(1,0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this solution is good. We could instantiate rclcpp::Duration
inline, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
visualization_msgs::Marker mk; | ||
mk.header.stamp = ros::Time::now(); | ||
visualization_msgs::msg::Marker mk; | ||
mk.header.stamp = stamp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be set directly from rclcpp::Clock().now()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ROS_ERROR_NAMED("constraint_samplers", "IK solver failed with error %d", error.val); | ||
else if (verbose_) | ||
ROS_INFO_NAMED("constraint_samplers", "IK failed"); | ||
error.val != moveit_msgs::msg::MoveItErrorCodes::TIMED_OUT){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop_time = (ros::Time::now() - start_time).toSec(); | ||
RCLCPP_WARN(LOGGER, "%d, %f", count, q_init(free_angle_)); | ||
time = rclcpp::Clock().now(); | ||
loop_time = time.seconds() - start_time.seconds(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loop_time = time.seconds() - start_time.seconds(); | |
loop_time = (rclcpp::Clock().now() - start_time).seconds(); |
Then we don't need to introduce time
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -92,7 +92,7 @@ class PR2ArmIKSolver : public KDL::ChainIkSolverPos | |||
#if KDL_VERSION_LESS(1, 4, 0) | |||
void updateInternalDataStructures(); | |||
#else | |||
void updateInternalDataStructures() override; | |||
void updateInternalDataStructures(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should override be removed? This condition shouldn't be broken by the port and we should try to avoid loosening these kind of checks. Also, the if/else block is redundant with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateInternalDataStructures depends from orocos_kdl, we can see it on melodic here http://docs.ros.org/melodic/api/orocos_kdl/html/classKDL_1_1ChainJntToJacSolver.html#a8c6fe8ec5cd73c65699143e4a5df9bef, the problem is, that this function is not implemented on ros2, looking into https://github.com/ros2/orocos_kinematics_dynamics/tree/ros2/orocos_kdl it seems like is no more needed. This function is used only on the tests, and it seems like the function is empty.
I removed the entire function and the define here: 02f0eb3
${urdfdom_headers_LIBRARIES} | ||
) | ||
endif() | ||
# if(BUILD_TESTING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to uncomment tests and just let them fail for now so we can fix them later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmayoral Let's get the test fixes cherry picked in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlautman Done! |
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding relative paths is a bad idea.
I would recommend that for every library in this package that is used else ware you set a <lib_name>_lib_dir
environment variable that can then be used by the tests
A good example is the rcl_lib_dir
I have taken the time to show how it is used below:
/home/mike/ws_ros2/src/ros2/rcl/rcl/CMakeLists.txt:
78
79: # rcl_lib_dir is passed as APPEND_LIBRARY_DIRS for each ament_add_gtest call so
80 # the librcl that they link against is on the library path.
81 # This is especially important on Windows.
82 # This is overwritten each loop, but which one it points to doesn't really matter.
83: set(rcl_lib_dir "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
84
/home/mike/ws_ros2/src/ros2/rcl/rcl/test/CMakeLists.txt:
16
17: set(extra_lib_dirs "${rcl_lib_dir}")
18
/home/mike/ws_ros2/src/ros2/rcl/rcl/test/CMakeLists.txt:
34 rcl_add_custom_gtest(test_client${target_suffix}
35 SRCS rcl/test_client.cpp
36: INCLUDE_DIRS ${osrf_testing_tools_cpp_INCLUDE_DIRS}
37 ENV ${rmw_implementation_env_var}
38 APPEND_LIBRARY_DIRS ${extra_lib_dirs}
The example uses rcl_add_custom_gtest but it should work just as well with ament_add_gtest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind I prefer to merge this. And then I will fix them all together. Because we have other merged that use this style. I can open an issue to avoid forgetting it.
test/test_constraint_samplers.cpp | ||
test/pr2_arm_kinematics_plugin.cpp | ||
test/pr2_arm_ik.cpp | ||
) | ||
|
||
target_include_directories(test_constraint_samplers PUBLIC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -36,13 +36,15 @@ | |||
|
|||
#include <moveit/constraint_samplers/constraint_sampler.h> | |||
|
|||
rclcpp::Logger LOGGER_CONSTRAINT_SAMPLERS = rclcpp::get_logger("moveit").get_child("constraint_samplers"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -39,6 +39,8 @@ | |||
#include <cassert> | |||
#include <boost/bind.hpp> | |||
|
|||
rclcpp::Logger LOGGER_DEFAULT_CONTRAINT_SAMPLERS = rclcpp::get_logger("moveit").get_child("constraint_samplers"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put Inside namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On ROS2 is not implemented, for melodic we can get it on http://docs.ros.org/melodic/api/orocos_kdl/html/classKDL_1_1ChainJntToJacSolver.html#a8c6fe8ec5cd73c65699143e4a5df9bef, looking into ros2 code, there is not similar function https://github.com/ros2/orocos_kinematics_dynamics/tree/ros2/orocos_kdl
@mlautman and @henningkayser review the changes please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anasarrak Just some small changes left, then +1 from me
error_code.val = error_code.PLANNING_FAILED; | ||
return false; | ||
} | ||
KDL::Frame pose_desired; | ||
tf2::fromMsg(ik_pose, pose_desired); | ||
KDL::Frame pose_desired = KDL::Frame(KDL::Rotation::Quaternion(ik_pose.orientation.x, ik_pose.orientation.y, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use fromMsg() from tf2_kdl.h once geometry2 is ported to ROS2. Please add a TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually an implementation for such transformation on
https://github.com/ros2/geometry2/blob/234725f30ade83caa4bcf019ee854199aa31bef5/tf2_kdl/include/tf2_kdl/tf2_kdl.h#L273-L282, you have to pass a PoseStamped instead of a pose, so I suggest the following changes.
KDL::Frame pose_desired = KDL::Frame(KDL::Rotation::Quaternion(ik_pose.orientation.x, ik_pose.orientation.y, | |
geometry_msgs::msg::PoseStamped ik_pose_stamped; | |
ik_pose_stamped.pose = ik_pose; | |
tf2::Stamped<KDL::Frame> pose_desired; | |
tf2::fromMsg(ik_pose_stamped, pose_desired); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anasarrak I'm going to merge this but I would like to see this in a follow up PR
@@ -673,8 +673,8 @@ TEST_F(LoadPlanningModelsPr2, PoseConstraintSamplerManager) | |||
if (s->sample(ks, ks_const, 1)) | |||
succ++; | |||
} | |||
ROS_INFO("Success rate for IK Constraint Sampler with position & orientation constraints for one arm: %lf", | |||
(double)succ / (double)NT); | |||
// ROS_INFO("Success rate for IK Constraint Sampler with position & orientation constraints for one arm: %lf", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This info should be printed, either by a logger or using std::cout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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; |
There was a problem hiding this comment.
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.
moveit_core/constraint_samplers/src/constraint_sampler_tools.cpp
Outdated
Show resolved
Hide resolved
moveit_core/constraint_samplers/src/constraint_sampler_tools.cpp
Outdated
Show resolved
Hide resolved
moveit_core/constraint_samplers/src/default_constraint_samplers.cpp
Outdated
Show resolved
Hide resolved
moveit_core/constraint_samplers/src/union_constraint_sampler.cpp
Outdated
Show resolved
Hide resolved
moveit_core/constraint_samplers/test/pr2_arm_kinematics_plugin.cpp
Outdated
Show resolved
Hide resolved
moveit_core/constraint_samplers/test/pr2_arm_kinematics_plugin.cpp
Outdated
Show resolved
Hide resolved
moveit_core/constraint_samplers/test/pr2_arm_kinematics_plugin.cpp
Outdated
Show resolved
Hide resolved
moveit_core/constraint_samplers/test/test_constraint_samplers.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see review
@mlautman look at the changes |
Ping @mlautman @henningkayser |
friendly ping @mlautman @henningkayser @davetcoleman |
…r_manager_loader Port constraint_sampler_manager_loader to ROS2