Added talker.py and ability to bag files

This commit is contained in:
GLEN TURNER (8GT6)
2015-06-01 12:39:59 -04:00
parent 9002afaeb8
commit d5282805da
9 changed files with 218 additions and 60 deletions

View File

@@ -23,8 +23,7 @@ class Bagger(object):
else:
bag_file = os.path.join(self.data_path, msg.data)
self.proc = subprocess.Popen(["rosbag", "record",
"kinect2/depth_lowres/points", "kinect2/rgb_lowres/image",
"tf", "imu/data", "-o", bag_file], preexec_fn=os.setsid)
"--all", "-o", bag_file], preexec_fn=os.setsid)
self.pub.publish("STARTED")

33
src/bagger.py~ Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
import rospkg
import subprocess
import os
import signal
class Bagger(object):
def __init__(self):
rospy.init_node("bagger", anonymous=True)
rospy.Subscriber("bag_publisher", String, self.callback)
self.pub = rospy.Publisher("bag_notifier", String, queue_size=10)
self.proc = None
rospack = rospkg.RosPack()
self.data_path = os.path.join(rospack.get_path("rosbridge_GUI_example"), "data")
def callback(self, msg):
if msg.data == "STOP" and self.proc is not None:
os.killpg(self.proc.pid, signal.SIGINT)
self.pub.publish("STOPPED")
else:
bag_file = os.path.join(self.data_path, msg.data)
self.proc = subprocess.Popen(["rosbag", "record",
"kinect2/depth_lowres/points", "kinect2/rgb_lowres/image",
"tf", "imu/data", "-o", bag_file], preexec_fn=os.setsid)
self.pub.publish("STARTED")
if __name__ == '__main__':
Bagger()
rospy.spin()

20
src/talker.py Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import String
def talker():
pub = rospy.Publisher('chatter', String, queue_size=10)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass

0
src/talker.py~ Normal file
View File