Skip to content

Commit

Permalink
8/18
Browse files Browse the repository at this point in the history
Add debug_publisher to let user to echo value for training(LiDAR data, reward...)
  • Loading branch information
StanleyChueh committed Aug 18, 2024
1 parent be8983a commit 5153955
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions turtlebot3_rl/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'console_scripts': [
'train = turtlebot3_rl.train:main',
'test = turtlebot3_rl.test:main',
'debug = turtlebot3_rl.debug_publisher:main',
],
},
)
Expand Down
25 changes: 25 additions & 0 deletions turtlebot3_rl/turtlebot3_rl/debug_publisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import rclpy
from rclpy.node import Node
from std_msgs.msg import String

class DebugPublisher(Node):
def __init__(self):
super().__init__('debug_publisher')
self.debug_pub = self.create_publisher(String, 'debug_info', 10)

def publish_debug_info(self, scan_data, action, reward, done):
# Truncate scan data for display and round for clarity
scan_str = ', '.join([f'{x:.2f}' for x in scan_data[:10]])
action_str = ', '.join([f'{x:.2f}' for x in action])

# Format the message
debug_msg = String()
debug_msg.data = (
f"Scan Data: [{scan_str}]...\n"
f"Action: [{action_str}]\n"
f"Reward: {reward:.2f}\n"
f"Done: {done}\n"
"=============================="
)

self.debug_pub.publish(debug_msg)

0 comments on commit 5153955

Please sign in to comment.