ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Moveit Motion planning API, waypoints not increasing with time [closed]

asked 2021-05-19 10:13:07 -0500

Io gravatar image

I just started trying to work with the motion planner api as per https://ros-planning.github.io/moveit.... To actually try executing it I followed this with

  moveit::planning_interface::MoveGroupInterface move_group_interface(PLANNING_GROUP);
  moveit::planning_interface::MoveGroupInterface::Plan my_plan;
  my_plan.trajectory_ = response.trajectory;
  move_group_interface.execute(my_plan);

The error given when trying to actually move the robot :

[ INFO] [1621434276.856536029]: Execution request received
[ERROR] [1621434276.857951441]: Trajectory message contains waypoints that are not strictly increasing in time.
[ WARN] [1621434276.858424280]: Controller scaled_pos_joint_traj_controller failed with error INVALID_GOAL: Trajectory message contains waypoints that are not strictly increasing in time.
[ WARN] [1621434276.858571201]: Controller handle scaled_pos_joint_traj_controller reports status FAILED
[ INFO] [1621434276.858625647]: Completed trajectory execution with status FAILED ...
[ INFO] [1621434276.858725778]: Execution completed: FAILED
[ INFO] [1621434276.858971024]: ABORTED: Solution found but controller failed during execution

When I worked just with the move_group_interface and encountered this error, the solution was to eliminate a first current waypoint and let the robot figure it out.

In this case, however, I am not sure if it's the same cause, what state would that be? If i comment out planning_scene->getCurrentStateNonConst().setToDefaultValues(joint_model_group, "up");, the robot doesn't start from its starting upwards pose. I am not yet familiar with how the api works, excuse me if there's an obvious solution to it.

I am using a UR5, ubuntu 18.04, ros melodic.

Any help is appreciated, be it ideas , links etc.

my node:

#include <pluginlib/class_loader.h>
#include <ros/ros.h>

#include <moveit/robot_model_loader/robot_model_loader.h>
#include <moveit/planning_interface/planning_interface.h>
#include <moveit/planning_scene/planning_scene.h>
#include <moveit/kinematic_constraints/utils.h>
#include <moveit_msgs/DisplayTrajectory.h>
#include <moveit_msgs/PlanningScene.h>
#include <moveit_visual_tools/moveit_visual_tools.h>

#include <boost/scoped_ptr.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>

# include <moveit/move_group_interface/move_group_interface.h>
#include <moveit/planning_scene_interface/planning_scene_interface.h>

#define foreach BOOST_FOREACH



int main(int argc, char** argv)
{
  const std::string node_name = "motion_planning_api";
  ros::init(argc, argv, node_name);
  ros::AsyncSpinner spinner(1);
  spinner.start();
  ros::NodeHandle node_handle("~");

  const std::string PLANNING_GROUP = "manipulator";
  robot_model_loader::RobotModelLoader robot_model_loader("robot_description");
  const moveit::core::RobotModelPtr& robot_model = robot_model_loader.getModel();

  moveit::core::RobotStatePtr robot_state(new moveit::core::RobotState(robot_model));
  const moveit::core::JointModelGroup* joint_model_group = robot_state->getJointModelGroup(PLANNING_GROUP);

  planning_scene::PlanningScenePtr planning_scene(new planning_scene::PlanningScene(robot_model));


  planning_scene->getCurrentStateNonConst().setToDefaultValues(joint_model_group, "up");

  boost::scoped_ptr<pluginlib::ClassLoader<planning_interface::PlannerManager>> planner_plugin_loader;
  planning_interface::PlannerManagerPtr planner_instance;
  std::string planner_plugin_name;

  if (!node_handle.getParam("planning_plugin", planner_plugin_name))
    ROS_FATAL_STREAM("Could not find planner plugin name");
  try
  {
    planner_plugin_loader.reset(new pluginlib::ClassLoader<planning_interface::PlannerManager>(
        "moveit_core", "planning_interface::PlannerManager"));
  }
  catch (pluginlib::PluginlibException& ex)
  {
    ROS_FATAL_STREAM("Exception while creating planning plugin loader " << ex.what());
  }
  try
  {
    planner_instance.reset(planner_plugin_loader->createUnmanagedInstance(planner_plugin_name));
    if (!planner_instance->initialize(robot_model, node_handle.getNamespace()))
      ROS_FATAL_STREAM("Could not initialize planner instance");
    ROS_INFO_STREAM("Using planning interface '" << planner_instance->getDescription() << "'");
  }
  catch (pluginlib::PluginlibException& ex)
  {
    const std::vector<std::string>& classes = planner_plugin_loader->getDeclaredClasses();
    std::stringstream ss;
    for (const auto& cls : classes)
      ss << cls << " ";
    ROS_ERROR_STREAM("Exception while loading planner '" << planner_plugin_name << "': " << ex.what() << std::endl
                                                         << "Available plugins: " << ss.str());
  }


  namespace rvt = rviz_visual_tools;
  moveit_visual_tools::MoveItVisualTools visual_tools("base_link");
  visual_tools.loadRobotStatePub("/display_robot_state");
  visual_tools.enableBatchPublishing();
  visual_tools.deleteAllMarkers();  // clear all old markers
  visual_tools.trigger();

  visual_tools ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Io
close date 2021-05-20 05:26:13.822096

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-20 05:25:04 -0500

Io gravatar image

updated 2021-05-20 05:25:34 -0500

In my case the response.trajectory.joint_trajectory had no time_from_start for any points, so I manually set the time for each waypoint found, thus the exection could run.

edit flag offensive delete link more

Comments

Can you share a code snippet?

lorepieri gravatar image lorepieri  ( 2021-06-12 09:16:48 -0500 )edit

The way i did it, I just added for each point of each trajectory of the display_trajectory a time_from_start which is a ros::duration.

for ( t from 0 to end ){

    sz_tr = display_trajectory.trajectory[t].joint_trajectory.points.size();

    for (i from 0 to sz_tr){

      ros::Duration time_dur_ros = ros::Duration(time_dur);
      display_trajectory.trajectory[t].joint_trajectory.points[i].time_from_start = time_dur_ros;
      time_dur += 0.01; // this controls the speed of execution as well
      }
  }
Io gravatar image Io  ( 2021-06-14 11:28:27 -0500 )edit
1

You should use retime_trajectory if you want to execute the trajectory on a robot. Also consider using the MoveGroupInterface's move, plan and execute functions directly. You might not need to work this low-level.

fvd gravatar image fvd  ( 2021-06-15 00:30:01 -0500 )edit

Thank you for the reply, i shall try it like this as well.

Io gravatar image Io  ( 2021-06-16 03:32:22 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-05-19 10:13:07 -0500

Seen: 609 times

Last updated: May 20 '21