Skip to content

Constraint samplers - #60

Merged
mlautman merged 25 commits into
moveit:masterfrom
AcutronicRobotics:constraint-samplers
Jun 25, 2019
Merged

mlautman merged 25 commits into
moveit:masterfrom
AcutronicRobotics:constraint-samplers

Conversation

@vmayoral

Copy link
Copy Markdown
Contributor

@henningkayser henningkayser left a comment

Copy link
Copy Markdown
Member

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.

std::stringstream ss;
ss << constr;
ROS_DEBUG_NAMED("constraint_samplers",
ss << constr.name;

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

Choose a reason for hiding this comment

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

void updateInternalDataStructures();
#else
void updateInternalDataStructures() override;
void updateInternalDataStructures();

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

Choose a reason for hiding this comment

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

@ahcorde

ahcorde commented May 24, 2019

Copy link
Copy Markdown
Contributor

@mlautman Done!

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

Copy link
Copy Markdown
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
Copy Markdown
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/pr2_arm_ik.cpp
)

target_include_directories(test_constraint_samplers PUBLIC

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

Choose a reason for hiding this comment

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


#include <moveit/constraint_samplers/constraint_sampler.h>

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

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

Choose a reason for hiding this comment

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

#include <cassert>
#include <boost/bind.hpp>

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

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

Choose a reason for hiding this comment

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

@anasarrak

Copy link
Copy Markdown
Contributor

@mlautman and @henningkayser review the changes please

@henningkayser henningkayser left a comment

Copy link
Copy Markdown
Member

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

}
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

}
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

std::stringstream ss;
ss << constr;
ROS_DEBUG_NAMED("constraint_samplers",
ss << constr.name;

Copy link
Copy Markdown
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.

@mlautman mlautman left a comment

Copy link
Copy Markdown
Contributor

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

@mlautman look at the changes

@anasarrak

Copy link
Copy Markdown
Contributor

Ping @mlautman @henningkayser

@ahcorde

ahcorde commented Jun 24, 2019

Copy link
Copy Markdown
Contributor

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