Hello experts,
i am trying to write a node in cpp that keeps track of the positions that my Turtlebot already traveled to. the reason is that I want my node to compare any given nav goals against the said (visited) pose list and accepts the given nav goal if it is not already in the list. - what im trying to achieve here is a 2D full coverage method. (got to be a challenge to me!!!)
im using a kobuki base, hokuyo lidar, gmapping to build a map in ros indigo.
According to tutorials i came up with the code to retrieve the robot's pose in the /map frame, now i wanna save it and as im new to cpp programming, can anyone can help me with the piece of code that i need to add to my node in order to make it happen?
a piece of the Code where pose is looked up:
tf::StampedTransform transform;
try{
ros::Time now=ros::Time::now();
listener.waitForTransform("/map","/base_link",now,ros::Duration(3.0));
listener.lookupTransform("/map","/base_link",ros::Time(0), transform);
ROS_INFO("Got a transform! x = %f, y = %f",transform.getOrigin().x(),transform.getOrigin().y()); //to check results
}
catch (tf::TransformException ex){
ROS_ERROR("%s" ,ex.what());
}
UPDATE:
Today I made a fresh installed of hector_slam on my Indigo to work with trajectory_server, everything works perfect with hector_mapping as i get a consistent map, good pose updates, etc. But the hector_trajectory_server doesnt seem to work. i use the same instructions as Stefan gave below in his comment along with hector_mapping.
My tf tree: map > base_link > laser
output of rosservice call trajectory
is a series of
header:
seq: 0
stamp:
secs: 1454454715
nsecs: 262124169
frame_id: /map
pose:
position:
x: 0.0
y: 0.0
z: 0.0
orientation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
UPDATE2 Launch file:
<launch>
<arg name="tf_map_scanmatch_transform_frame_name" default="scanmatcher_frame"/>
<arg name="base_frame" default="/base_link"/>
<arg name="odom_frame" default="/base_link"/>
<arg name="pub_map_odom_transform" default="true"/>
<arg name="scan_subscriber_queue_size" default="5"/>
<arg name="scan_topic" default="scan"/>
<arg name="map_size" default="2048"/>
<arg name="trajectory_source_frame_name" default="/base_link"/>
<arg name="trajectory_update_rate" default="4"/>
<arg name="trajectory_publish_rate" default="0.25"/>
<arg name="map_file_base_name" default="hector_slam_map"/>
<arg name="map_file_path" default="$(find test_nav)/maps"/>
<node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">
<!-- Frame names -->
<param name="map_frame" value="/map" />
<param name="base_frame" value="$(arg base_frame)" />
<param name="odom_frame" value="$(arg odom_frame)" />
<!-- Tf use -->
<param name="use_tf_scan_transformation" value="true"/>
<param name="use_tf_pose_start_estimate" value="false"/>
<param name="pub_map_scanmatch_transform" value="false"/>
<param name="pub_map_odom_transform" value="$(arg pub_map_odom_transform)"/>
<!-- Map size / start point -->
<param name="map_resolution" value="0.05"/>
<param name="map_size" value="$(arg map_size)"/>
<param name="map_start_x" value="0.5"/>
<param name="map_start_y" value="0.5" />
<param name="map_multi_res_levels" value="2" />
<!-- Map update parameters -->
<param name="update_factor_free" value="0.4"/>
<param name="update_factor_occupied" value="0.9" />
<param name="map_update_distance_thresh" value="0.4"/>
<param name="map_update_angle_thresh" value="0.06" />
<param name="laser_z_min_value" value = "-1.0" />
<param name="laser_z_max_value" value = "1.0" />
<param name="laser_max_dist" value = "5.3" />
<param name="laser_min_dist" value = "0.1" />
<!-- Advertising config -->
<param name="advertise_map_service" value="true"/>
<param name="scan_subscriber_queue_size" value="$(arg scan_subscriber_queue_size)"/>
<param name="scan_topic" value="$(arg scan_topic)"/>
<!-- Debug parameters -->
<!--
<param name="output_timing" value="false"/>
<param name="pub_drawings" value="true"/>
<param name="pub_debug_output" value="true"/>
-->
<param name="tf_map_scanmatch_transform_frame_name" value="$(arg tf_map_scanmatch_transform_frame_name)" />
</node>
<node pkg="hector_trajectory_server" type="hector_trajectory_server" name="hector_trajectory_server" output="screen">
<param name="target_frame_name" type="string" value="/map" />
<param name="source_frame_name" type="string" value="$(arg trajectory_source_frame_name)" />
<param name="trajectory_update_rate" type="double" value="$(arg trajectory_update_rate)" />
<param name="trajectory_publish_rate" type="double" value="$(arg trajectory_publish_rate)" />
</node>
<node pkg="hector_geotiff" type="geotiff_node" name="hector_geotiff_node" output="screen" launch-prefix="nice -n 15">
<remap from="map" to="/dynamic_map" />
<param name="map_file_path" type="string" value="$(arg map_file_path)" />
<param name="map_file_base_name" type="string" value="$(arg map_file_base_name)" />
<param name="geotiff_save_period" type="double" value="45" />
<param name="draw_background_checkerboard" type="bool" value="true" />
<param name="draw_free_space_grid" type="bool" value="true" />
<param name="plugins" type="string" value="hector_geotiff_plugins/TrajectoryMapWriter" />
</node>
<node pkg="tf" type="static_transform_publisher" name="odom_base_broadcaster" args="0 0 0 0 0 0 /map /base_link 50"/>
<node pkg="tf" type="static_transform_publisher" name="laser_base_broadcaster" args="0 0 0 0 0 0 /base_link /laser 50"/>
</launch>
UPDATE3: here is an image created of the map created in Rviz by hector mapping. i start at the Blue marker and walk around the room to create the map, but as you can see the Path information is not there and rosservice call trajectory
is not returning anything useful either. otherwise movements relative to frames are perfect despite im using a 10HZ lidar.
Image:: hector_img.png
tf tree pub_map_odom_transform
set to true.
Is there anything that i could be missing here or something has changed in the hector slam?
Thank you!
Originally posted by sobot on ROS Answers with karma: 116 on 2015-03-15
Post score: 0
Original comments
Comment by Andromeda on 2015-03-15:
Do you publish your position over /odom
? If yes it is really easy to achieve your goal.
Anyway there are many ways to get that information. If you have odom I ll tell you what I would do in that case.
Comment by sobot on 2015-03-15:
@Andromeda well, as u can see in the code I want to save the pose with regards to the /map
frame that comes from gmapping. and yes my robot does publish the /odom
info. - i'm a bit lost in the cpp coding aspect of it. save and retrieve (for comparing).
Comment by Stefan Kohlbrecher on 2016-02-03:
So in rviz the pose of the robot is tracked correctly with regards to the /map frame?
Comment by sobot on 2016-02-03:
yes. works even better and faster than Gmapping for me.