Bag file recorded from ROS node
Hello. I have a simple question about if its possible to record topics from within a rosnode. The goal is to autonomously have a robot collecting data for a period of time given specific locations of the environment.
My node looks like this so far but the file seems not to be created:
#!/usr/bin/python
import rospy
import rosbag
from std_msgs.msg import Int32, String
rospy.init_node("bagtest")
rate = rospy.Rate(2)
bag = rosbag.Bag('test13.bag','w')
#Set up message from String
s = String()
s.data = 'foo'
#Set up message from Int32
i = Int32()
i.data = 42
bag.write('chatter', s)
bag.write('numbers', i)
bag.close()
while not rospy.is_shutdown():
print("this is my first node")
rate.sleep()
The launch file looks like this:
<launch>
<node pkg="data_acquisition_package" type="testbag.py" name="bagtest" output="screen"></node>
</launch>
If this is not supposed to work, is there any other example of how to start recording topics given specific situations in the environment ?
Thank you in advance !