-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from BerkeleyAutomation/replayer-fix
Replayer fix
- Loading branch information
Showing
5 changed files
with
157 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import socket | ||
|
||
import rclpy | ||
from rosbag2_py import Recorder, RecordOptions, StorageOptions | ||
from rclpy.node import Node | ||
import time | ||
from std_srvs.srv import Empty | ||
from threading import Thread | ||
|
||
|
||
class DatasetRecorder(Node): | ||
""" | ||
A class for replaying datasets in ROS2. | ||
Args: | ||
dataset_name (str): The name of the dataset to be replayed. | ||
Attributes: | ||
publisher (Publisher): The publisher for sending step information. | ||
dataset (Dataset): The loaded RLDS dataset. | ||
logger (Logger): The logger for logging information. | ||
feature_spec (DatasetFeatureSpec): The feature specification for the dataset. | ||
episode (Episode): The current episode being replayed. | ||
""" | ||
def __init__(self): | ||
super().__init__("fogros2_rt_x_recorder") | ||
|
||
self.new_episode_notification_service = self.create_service(Empty, 'new_episode_notification_service', self.new_episode_notification_service_callback) | ||
self.episode_recorder = Recorder() | ||
|
||
self.logger = self.get_logger() | ||
self.episode_counter = 1 | ||
self.init_recorder() | ||
self.logger.info("Recording started") | ||
|
||
def new_episode_notification_service_callback(self, request, response): | ||
self.logger.info("Received request to start new episode") | ||
self.stop_recorder() | ||
self.start_new_recorder() | ||
return response | ||
|
||
def init_recorder(self): | ||
self.start_new_recorder() | ||
|
||
def start_new_recorder(self): | ||
self.logger.info(f"starting episode #: {self.episode_counter}") | ||
storage_options = StorageOptions( | ||
uri=f"rosbags/episode_{self.episode_counter}", | ||
storage_id="sqlite3" | ||
) | ||
record_options = RecordOptions() | ||
record_options.all = True | ||
self.thread = Thread(target=self.episode_recorder.record, args=(storage_options, record_options)).start() | ||
self.episode_counter += 1 | ||
|
||
def stop_recorder(self): | ||
self.episode_recorder.cancel() | ||
|
||
def main(args=None): | ||
|
||
rclpy.init(args=args) | ||
node = DatasetRecorder() | ||
|
||
rclpy.spin(node) | ||
|
||
node.destroy_node() | ||
rclpy.shutdown() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters