Use MoveIt 2 for Inverse Kinematics - LCAS/RBT1001 GitHub Wiki
In this part of the workshop, you are going to learn how to use MoveIt 2 to find Inverse Kinematics solution for your arm.
MoveIt 2 is the robotics manipulation platform for ROS 2 which contains many state-of-the-art implementations of algorithms for kinematics, motion planning, manipulation, control and navigation.
1. MoveIt 2 Demo Interactive Tool
Follow the tutorial at https://moveit.picknik.ai/humble/doc/tutorials/quickstart_in_rviz/quickstart_in_rviz_tutorial.html
Note: ignore the Getting Started section, as the installation and setup is already done for you.
2. Visualise an example code for computing IK and Jacobian
Open the file /home/lcas/ws/src/moveit2_tutorials/doc/examples/robot_model_and_robot_state/src/robot_model_and_robot_state_tutorial.cpp
.
Particularly, here it computes the forward kinematics transform, similarly to what tf2 does:
// Forward Kinematics
// ^^^^^^^^^^^^^^^^^^
// Now, we can compute forward kinematics for a set of random joint
// values. Note that we would like to find the pose of the
// "panda_link8" which is the most distal link in the
// "panda_arm" group of the robot.
kinematic_state->setToRandomPositions(joint_model_group);
const Eigen::Isometry3d& end_effector_state = kinematic_state->getGlobalLinkTransform("panda_link8");
/* Print end-effector pose. Remember that this is in the model frame */
RCLCPP_INFO_STREAM(LOGGER, "Translation: \n" << end_effector_state.translation() << "\n");
RCLCPP_INFO_STREAM(LOGGER, "Rotation: \n" << end_effector_state.rotation() << "\n");
Once a configuration for the robot end effect is provided, it can search for an Inverse Kinematics solution:
// Inverse Kinematics
// ^^^^^^^^^^^^^^^^^^
// We can now solve inverse kinematics (IK) for the Panda robot.
// To solve IK, we will need the following:
//
// * The desired pose of the end-effector (by default, this is the last link in the "panda_arm" chain):
// end_effector_state that we computed in the step above.
// * The timeout: 0.1 s
double timeout = 0.1;
bool found_ik = kinematic_state->setFromIK(joint_model_group, end_effector_state, timeout);
// Now, we can print out the IK solution (if found):
if (found_ik)
{
kinematic_state->copyJointGroupPositions(joint_model_group, joint_values);
for (std::size_t i = 0; i < joint_names.size(); ++i)
{
RCLCPP_INFO(LOGGER, "Joint %s: %f", joint_names[i].c_str(), joint_values[i]);
}
}
else
{
RCLCPP_INFO(LOGGER, "Did not find IK solution");
}
Note that the solution cannot always be found, because it uses a numerical method based on Newton's Method.
You can run this code by launching: ros2 launch moveit2_tutorials robot_model_and_robot_state_tutorial.launch.py
If you open the file /home/lcas/ws/src/moveit_resources/panda_moveit_config/config/kinematics.yaml
you can see that one can specify the Inverse Kinematics Solver of their choice for that specific robot. For example, you can use a different solver that is more efficient by replacing with the following:
panda_arm:
kinematics_solver: bio_ik/BioIKKinematicsPlugin
kinematics_solver_search_resolution: 0.005
kinematics_solver_timeout: 0.005
kinematics_solver_attempts: 1.0