Remove hardcoding rosbag path

This commit is contained in:
Laurent George 2018-06-08 08:59:30 +02:00
parent df2561b0b3
commit 587c7b36a0
4 changed files with 8 additions and 7 deletions

View File

@ -153,9 +153,9 @@ Example for backward :
The carla_ros_bridge could also be used to record all published topics into a rosbag:
roslaunch carla_ros_bridge client_with_rviz.launch enable_rosbag:=True
roslaunch carla_ros_bridge client_with_rviz.launch rosbag_fname:=/tmp/save_session.bag
This command will create a rosbag in /tmp/output_{date}.bag
This command will create a rosbag /tmp/save_session.bag
You can of course also use rosbag record to do the same, but using the ros_bridge to do the recording you have the guarentee that all the message are saved without small desynchronization that could occurs when using *rosbag record* in an other process.

View File

@ -1,7 +1,7 @@
<launch>
<arg name='enable_rosbag' default='False'/>
<arg name='rosbag_fname' default=''/>
<param name="rosbag_fname" value="$(arg rosbag_fname)"/>
<rosparam file="$(find carla_ros_bridge)/config/settings.yaml" command="load" />
<param name="carla_autopilot" type="boolean" value="True" />
<param name='enable_rosbag' type="boolean" value="$(arg enable_rosbag)"/>
<node pkg="carla_ros_bridge" name="carla_ros_bridge" type="client.py" output="screen"/>
</launch>

View File

@ -7,6 +7,7 @@ import time
from tf2_msgs.msg import TFMessage
import rosbag
import rospy
import os
from carla_ros_bridge.bridge import CarlaRosBridge
@ -14,8 +15,8 @@ from carla_ros_bridge.bridge import CarlaRosBridge
class CarlaRosBridgeWithBag(CarlaRosBridge):
def __init__(self, *args, **kwargs):
super(CarlaRosBridgeWithBag, self).__init__(*args, **kwargs)
timestr = time.strftime("%Y%m%d-%H%M%S")
self.bag = rosbag.Bag('/tmp/output_{}.bag'.format(timestr), mode='w')
rosbag_fname = rospy.get_param('rosbag_fname')
self.bag = rosbag.Bag(rosbag_fname, mode='w')
def send_msgs(self):
for publisher, msg in self.msgs_to_publish:

View File

@ -24,7 +24,7 @@ def main():
rospy.loginfo("Connected")
bridge_cls = CarlaRosBridgeWithBag if rospy.get_param(
'enable_rosbag') else CarlaRosBridge
'rosbag_fname', '') else CarlaRosBridge
with bridge_cls(client=client, params=params) as carla_ros_bridge:
rospy.on_shutdown(carla_ros_bridge.on_shutdown)
carla_ros_bridge.run()