Ask Your Question
0

recode in python

asked 2015-08-18 01:16:08 -0600

unicornair gravatar image

updated 2015-08-18 01:42:59 -0600

I got trouble in this code coz I just know python,Is there any one that could help me recode this in python?I'm very grateful!

 #include <ros/ros.h>
#include <geometry_msgs/PointStamped.h>
#include <tf/transform_listener.h>

void transformPoint(const tf::TransformListener& listener){
  //we'll create a point in the base_laser frame that we'd like to transform to the base_link frame
  geometry_msgs::PointStamped laser_point;
  laser_point.header.frame_id = "base_laser";

  //we'll just use the most recent transform available for our simple example
  laser_point.header.stamp = ros::Time();

  //just an arbitrary point in space
  laser_point.point.x = 1.0;
  laser_point.point.y = 0.2;
  laser_point.point.z = 0.0;

  try{
    geometry_msgs::PointStamped base_point;
    listener.transformPoint("base_link", laser_point, base_point);

    ROS_INFO("base_laser: (%.2f, %.2f. %.2f) -----> base_link: (%.2f, %.2f, %.2f) at time %.2f",
        laser_point.point.x, laser_point.point.y, laser_point.point.z,
        base_point.point.x, base_point.point.y, base_point.point.z, base_point.header.stamp.toSec());
  }
  catch(tf::TransformException& ex){
    ROS_ERROR("Received an exception trying to transform a point from \"base_laser\" to \"base_link\": %s", ex.what());
  }
}

int main(int argc, char** argv){
  ros::init(argc, argv, "robot_tf_listener");
  ros::NodeHandle n;

  tf::TransformListener listener(ros::Duration(10));

  //we'll transform a point once every second
  ros::Timer timer = n.createTimer(ros::Duration(1.0), boost::bind(&transformPoint, boost::ref(listener)));

  ros::spin();

}
edit retag flag offensive close merge delete

Comments

Please format your code sample so that it is readable.

ahendrix gravatar imageahendrix ( 2015-08-18 01:25:20 -0600 )edit

sorry for that, here I changed

unicornair gravatar imageunicornair ( 2015-08-18 01:44:23 -0600 )edit

You've copied and pasted the code verbatim from the RobotSetup TF Tutorial. It should work; can you be more specific about the trouble you're having?

ahendrix gravatar imageahendrix ( 2015-08-18 01:51:41 -0600 )edit

I don't know the C++ syntax and roscpp APIs,like these transformPoint(const tf::TransformListener& listener) ros::Timer timer = n.createTimer(ros::Duration(1.0), boost::bind(&transformPoint, boost::ref(listener)) I think I have already grasped the TF but here it's a new puzzled me

unicornair gravatar imageunicornair ( 2015-08-18 02:18:42 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-08-18 01:52:51 -0600

ahendrix gravatar image

If you want to rewrite this in python, I would start with the TF Tutorials for python.

edit flag offensive delete link more

Comments

I have already finished learning TF,but roscpp makes me puzzled,I have cognition for it

unicornair gravatar imageunicornair ( 2015-08-18 02:22:30 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-08-18 01:16:08 -0600

Seen: 253 times

Last updated: Aug 18 '15