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

Conversation

vmayoral
Copy link
Contributor

Copy link
Member

@henningkayser henningkayser left a 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;
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

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);
Copy link
Member

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.

Copy link
Contributor

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;
Copy link
Member

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()

Copy link
Contributor

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){
Copy link
Member

Choose a reason for hiding this comment

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

clang-format

Copy link
Contributor

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();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
loop_time = time.seconds() - start_time.seconds();
loop_time = (rclcpp::Clock().now() - start_time).seconds();

Then we don't need to introduce time.

Copy link
Contributor

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();
Copy link
Member

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.

Copy link
Contributor

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)
Copy link
Member

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.

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@ahcorde
Copy link
Contributor

ahcorde commented May 24, 2019

@mlautman Done!

@ahcorde ahcorde mentioned this pull request May 24, 2019
14 tasks
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")
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

fix whitespace

Copy link
Contributor

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");
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.

@@ -39,6 +39,8 @@
#include <cassert>
#include <boost/bind.hpp>

rclcpp::Logger LOGGER_DEFAULT_CONTRAINT_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.

put Inside namespace

Copy link
Contributor

Choose a reason for hiding this comment

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

@anasarrak
Copy link
Contributor

@mlautman and @henningkayser review the changes please

Copy link
Member

@henningkayser henningkayser left a 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,
Copy link
Member

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

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 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.

Suggested change
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);

Copy link
Contributor

Choose a reason for hiding this comment

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

looks good to me

Copy link
Contributor

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",
Copy link
Member

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.

Copy link
Contributor

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;
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

@mlautman mlautman left a comment

Choose a reason for hiding this comment

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

see review

@anasarrak
Copy link
Contributor

@mlautman look at the changes

@anasarrak
Copy link
Contributor

Ping @mlautman @henningkayser

@ahcorde
Copy link
Contributor

ahcorde commented Jun 24, 2019

friendly ping @mlautman @henningkayser @davetcoleman

@mlautman mlautman merged commit a802f49 into moveit:master Jun 25, 2019
JafarAbdi pushed a commit to JafarAbdi/moveit2 that referenced this pull request Oct 28, 2019
…r_manager_loader

Port constraint_sampler_manager_loader to ROS2
MikeWrock pushed a commit to MikeWrock/moveit2 that referenced this pull request Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants