creating a global planner with the trajectory in the odometry frame

asked 2020-06-10 21:07:23 -0500

mateusguilherme gravatar image

Hello

I am trying to implement a global trajectory planner, but I want to send a goal in the Odometry frame and I want the trajectory to also be created in the odometry frame.

The goal is a known point that is 1 or 2 meters in front of my robot, so I would like the whole trajectory and its execution to take place in the odometry frame.

In the example below, I created a trajectory planner that creates a simple line between the start point and the end point (in the future it will be improved), however the planner is publishing this trajectory in the MAP frame.

I used this tutorial to create my planner: Writing A Global Path Planner As Plugin in ROS

   #include <pluginlib/class_list_macros.h>
     #include "planejador_header.h"

     //register this planner as a BaseGlobalPlanner plugin
     PLUGINLIB_EXPORT_CLASS(planejador::Planejador, nav_core::BaseGlobalPlanner)

     using namespace std;

     //Default Constructor
     namespace planejador {

     Planejador::Planejador (){
     }

     Planejador::Planejador(std::string name, costmap_2d::Costmap2DROS* costmap_ros){
       initialize(name, costmap_ros);
     }

     void Planejador::initialize(std::string name, costmap_2d::Costmap2DROS* costmap_ros){
     }

     bool Planejador::makePlan(const geometry_msgs::PoseStamped& start, const geometry_msgs::PoseStamped& goal,  std::vector<geometry_msgs::PoseStamped>& plan ){

        plan.push_back(new_start);
        plan.push_back(new_goal);


    ROS_INFO(" Start -> Frame_ID:%s, x: %.2f, y: %.2f, quatX: %.2f, quatY: %.2f, quatZ: %.2f, quatW: %.2f ", start.header.frame_id.c_str(), start.pose.position.x, start.pose.position.y, start.pose.orientation.x, start.pose.orientation.y, start.pose.orientation.z, start.pose.orientation.w);
     ROS_INFO("Goal -> Frame_ID:%s, x: %.2f, y: %.2f, quatX: %.2f, quatY: %.2f, quatZ: %.2f, quatW: %.2f ", goal.header.frame_id.c_str(), goal.pose.position.x, goal.pose.position.y, goal.pose.orientation.x, goal.pose.orientation.y, goal.pose.orientation.z, goal.pose.orientation.w);

      return true;
     }
     };

let's say my robot is exactly stopped at point x: 0 and y: 0 in the odometry frame and I want it to move to point x: -1 y: -1 in the Odometry frame, I then publish the message:

rostopic pub /move_base/goal move_base_msgs/MoveBaseActionGoal "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: 'odom'
goal_id:
  stamp:
    secs: 0
    nsecs: 0
  id: ''
goal:
  target_pose:
    header:
      seq: 0
      stamp:
        secs: 0
        nsecs: 0
      frame_id: 'odom'
    pose:
      position:
        x: -1.0
        y: -1.0
        z: 0.0
      orientation:
        x: 0.0
        y: 0.0
        z: 0.0
        w: 1.0"

after publishing the message with the above goal, I notice that my planner generated a trajectory in the MAP frame and not in the ODOMETRY frame as I would like.

[ INFO] [1591835655.041000784, 25.846000000]: Start -> Frame_ID:map, x: 0.05, y: -0.04, quatX: -0.00, quatY: -0.00, quatZ: -0.00, quatW: 1.00 
[ INFO] [1591835655.041009404, 25.846000000]: Goal -> Frame_ID:map, x: -0.95, y: -1.04, quatX: 0.00, quatY: -0.00, quatZ: -0.00, quatW: 1.00

the following video shows what happens: https://www.youtube.com/watch?v=0MiZjbwbQtE

any suggestion?

edit retag flag offensive close merge delete

Comments

You can use TF to convert the map goals into the odometry frame and then work in the odometry frame (e.g. move start and goal from map to odom frame, then do whatever stuff you want to do in the planner to make a path, and publish that / return it at the end of the function).

Its a good point that the initial poses given to you are in the map frame, I don't think in ROS1 there's any way around that, but I could be mistaken. If you look into the move_base code, you should see if the goal requests to the action server have a check on the frame or not. If it doesn't then you can also hand it a odom frame goal and it'll be transferred here.

stevemacenski gravatar image stevemacenski  ( 2020-06-10 22:55:02 -0500 )edit

ok, and how could i get the TF values? Should I declare a TF topic subscriber? Where exactly should I declare the topic's subscriber, within the makeplan function?

mateusguilherme gravatar image mateusguilherme  ( 2020-06-11 06:41:53 -0500 )edit

sorry for my inexperience, i found the lookupTransform method, thanks.

mateusguilherme gravatar image mateusguilherme  ( 2020-06-15 08:11:13 -0500 )edit