Ask Your Question
0

TF transform

asked 2012-08-09 19:04:07 -0500

Astronaut gravatar image

updated 2012-08-09 23:13:35 -0500

Hello

I would like to create my own node that can navigate my robot through some objects in the environment map using laser scan. So I just want to have some locations of objects in my environment map , so I need a list of objects and coordinates.Just need a ROS node that takes a list of objects with coordinates and posts a TF transform for every object...

How to fill my yaml map file with the object parameters. I have the yaml map file already created. Any help with the fill the map and TF transform please?

This is my object node.

include "ros/ros.h"

include "std_msgs/String.h"

include "sensor_msgs/LaserScan.h"

include <vector>

sensor_msgs::LaserScan laser_scan; float min_range;

void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg) {

std::vector<float> laser;
laser = msg->ranges;

int size_laser = laser.size();
for (int i=0;i<size_laser;i++){
    if (laser[i] < 0.01){
        laser[i] = 99999;
    }
    if (laser[i] > 45){
        laser[i] = 99999;
    }
}

min_range = 2;
int index_min;
for (int i=0;i<size_laser;i++){
    if (laser[i] < min_range){
        min_range = laser[i];
        index_min = i;
    ROS_INFO("Minimum Range = %f", min_range);
    }
}

for (int j=0;j<size_laser;j++){
    if (laser[j] > min_range + 0.5){
        laser[j] = 0;
    }
}


laser_scan = *msg;
laser_scan.ranges.clear();
laser_scan.ranges = laser;

}

int main(int argc, char **argv) {

ros::init(argc, argv, "object_node");

ros::NodeHandle n;
ROS_INFO("Minimum Range = %f", min_range);
ros::Subscriber sub = n.subscribe("scan", 1000, scanCallback);
ros::Publisher laser_pub = n.advertise<sensor_msgs::LaserScan>("closest_points", 100);

ros::Rate loop_rate(10);

while (ros::ok())
{


    laser_pub.publish(laser_scan);

    ros::spinOnce();

    loop_rate.sleep();
}

return 0;

}

And this is the yaml map file

image: pow_real_time.pgm resolution: 0.050000 origin: [-100.000000, -100.000000, 0.000000] negate: 0 occupied_thresh: 0.65 free_thresh: 0.196

and this is my launch file

Perform AMCL localisation: runs several nodes to generate odometry from laser scans (ICP) & IMU, loads a map of the POW assessment area, runs AMCL, plays back a dataset for localisation, and runs the visualiser with the correct visualisation parameters configured. -->

<launch>

<node name="rosplay" pkg="rosbag" type="play" args="/home/Data/13-48-20.bag  --clock"/>

<node pkg="tf" type="static_transform_publisher" name="baselink_laser" args="0 0 0 0 0 0 /base_link /laser 10"/>
<node pkg="tf" type="static_transform_publisher" name="laser_imu" args="0 0 0 0 0 0 /laser /base_imu 10"/>
<node pkg="tf" type="static_transform_publisher" name="baselink_camera" args="0 0 0 0 0 0 /base_link /camera 10"/>

<!-- Start the map server node and specify the map file (*.pgm) and the map resolution in metres/pixel -->
<node name="map_server" pkg="map_server" type="map_server" args="$(find amcl_listener)/maps/pow_real_time.yaml"         output="screen"/>

<!--Start the Laser_scan_matcher package, to provide odometry from laser data (ICP)-->
<node pkg="laser_scan_matcher" type="laser_scan_matcher_node" 
    name="laser_scan_matcher_node" output="screen">
    <param name="use_alpha_beta" value="true"/>
    <param name="max_iterations" value="10"/>
</node>

<!-- Start the gmapping node -->
<!--node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen"/-->

<node pkg="amcl" type="amcl" name="amcl" respawn="true" output="screen">
    <param name="base_frame_id" value="base_link"/>
    <param name="odom_frame_id" value="world ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-08-09 21:40:14 -0500

updated 2012-08-09 21:46:37 -0500

As far as i understand you you need only to read from each object its location. As you staid you have the location within the yaml map. So read it with a node and then create for each on a TF object which you publish. So, somethink like this for each object:

  static tf::TransformBroadcaster br;
  tf::Transform transform;
  transform.setOrigin( tf::Vector3(object->x, object->y, object->z) );
  transform.setRotation( tf::Quaternion(object->rot->x, object->rot->y, object->rot->z) );
  br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "world", object->name));

In cases where your object coordinates are not within the world/map frame you may need to change also the "world" label.

I hope this helps a little.

P.S.: Check this tutorials

edit flag offensive delete link more

Comments

No. I have my environment map. But still I need to label the objects. My object coordinates are not within the map frame. So I need to create a file with a list of object and their coordinates or something like that?. But how? Or I just create that list in the node?

Astronaut gravatar imageAstronaut ( 2012-08-09 21:50:43 -0500 )edit

Do I label the object with their coordinate in the yaml map file or just within the node?

Astronaut gravatar imageAstronaut ( 2012-08-09 22:00:00 -0500 )edit

Well i am not really familiar with Yaml Maps. Can you giv me an example of one or two objects within that format? I assumed that you have the objects, there location and if the location is not already within the map frame the knowledge of how the object-frame is linked to the map-frame.

tlinder gravatar imagetlinder ( 2012-08-09 22:37:16 -0500 )edit

If you have this information (location, frame and frame relation) than you can use the code above.

tlinder gravatar imagetlinder ( 2012-08-09 22:38:15 -0500 )edit

I just edit the object node file, the yaml map and launch file. Ok?

Astronaut gravatar imageAstronaut ( 2012-08-09 23:14:12 -0500 )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: 2012-08-09 19:04:07 -0500

Seen: 1,474 times

Last updated: Aug 09 '12