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

Add servo solver plugin #16

Closed
wants to merge 4 commits into from

Conversation

sjahr
Copy link
Owner

@sjahr sjahr commented Jan 25, 2024

Description

This PR depends on moveit#2603 and will be redirected to the main repos once it is merged

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

/**
* @brief Initializes moveit servo
*
* @param node
Copy link

Choose a reason for hiding this comment

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

Maybe you could add a small description to node. For example, I am unsure if the node needs to be spinning to be used, but a comment such as "node is used to run servo's ROS callbacks". Maybe that would be more clear.

Eigen::Isometry3d diff_pose = current_pose.inverse() * target_pose;
Eigen::AngleAxisd axis_angle(diff_pose.linear());

constexpr double fixed_trans_vel = 0.05;
Copy link

@pac48 pac48 Jan 26, 2024

Choose a reason for hiding this comment

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

Do you think it would make sense to make these into parameters?

while (!trajectory_msg)
{
// Calculate next servo command
moveit_servo::KinematicState joint_state = servo_->getNextJointState(current_state, target_twist);
Copy link

Choose a reason for hiding this comment

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

This point may cause issues if not handled with caution. Servo has a parameter called publish_period which is the time difference used for numerical integration. So if you ask servo to move at a velocity of 1 m/s and publish_period was .1 sec, then servo will return a new position that correspondence to a .1 m offset from the current position. So you should consider setting a faction of local trajectory length. For example, if you are supposed to arrive at your next point in .3 sec, then the update period should be .3/n, where n is the number of points you want in the command queue. I would recommend n=3.

}

// Get current state
const auto current_state = planning_scene_monitor_->getStateMonitor()->getCurrentState();
Copy link

Choose a reason for hiding this comment

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

If you are certain that the current state is actually current, then I would add it into the command queue as the first state.


std::optional<trajectory_msgs::msg::JointTrajectory> trajectory_msg;
// Create servo commands until a trajectory message can be generated
while (!trajectory_msg)
Copy link

Choose a reason for hiding this comment

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

Before beginning the loop, delete any values in the command queue that are in than 1 update period in the past. So if the local planner is called at 100 Hz, then keep values as long as they are not older than 0.01 seconds.

Copy link

@pac48 pac48 left a comment

Choose a reason for hiding this comment

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

Overall looks good! I added a few comments in the main local planner solve function on how to possibly use servo's command queue more effectively. One other thing, it may be too much work to set up, but this draft PR to ros2_control shows how to add data_tamer to log the values sent to the hardware interface ros-controls/ros2_control#1255. If the command queue is setup correctly, you should see very smooth motion.

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.

2 participants