Skip to content

Commit f7f96f0

Browse files
Cleaning up plotting again
1 parent 872c6de commit f7f96f0

File tree

10 files changed

+47
-26
lines changed

10 files changed

+47
-26
lines changed

mm_run/nodes/isaac_sim_ros.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
import argparse
2+
import datetime
13
import os
24
import sys
35

6+
import numpy as np
7+
import rospy
48
from omni.isaac.kit import SimulationApp
59

10+
from mm_utils import parsing
11+
from mm_utils.logging import DataLogger
12+
613
# URDF import, configuration and simulation sample
714
simulation_app = SimulationApp({"headless": False})
815

9-
import argparse # noqa: E402
10-
11-
import numpy as np # noqa: E402
12-
import rospy # noqa: E402
1316
from omni.isaac.core.utils import extensions # noqa: E402
1417

15-
from mm_utils import parsing # noqa: E402
16-
from mm_utils.logging import DataLogger # noqa: E402
17-
1818
extensions.enable_extension("omni.isaac.ros_bridge")
1919
from mm_sim_isaac.isaac_sim_env import IsaacSimEnv # noqa: E402
2020
from omni.isaac.core.utils.rotations import euler_to_rot_matrix # noqa: E402
@@ -44,6 +44,13 @@ def main():
4444

4545
rospy.init_node("isaac_sim_ros")
4646

47+
# Create shared timestamp for logging (format: YYYY-MM-DD_HH-MM-SS)
48+
timestamp = datetime.datetime.now()
49+
session_timestamp = timestamp.strftime("%Y-%m-%d_%H-%M-%S")
50+
51+
# Set ROS parameter so control node can use the same timestamp
52+
rospy.set_param("/experiment_timestamp", session_timestamp)
53+
4754
sim = IsaacSimEnv(sim_config)
4855
robot = sim.robot
4956
world = sim.world
@@ -109,7 +116,7 @@ def main():
109116
sim.step(render=True)
110117
sim.publish_ros_topics()
111118

112-
logger.save()
119+
logger.save(session_timestamp=session_timestamp)
113120
simulation_app.close()
114121

115122

mm_run/nodes/mpc_ros.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ def __init__(self):
108108
self.logger.add("nx", self.ctrl_config["robot"]["dims"]["x"])
109109
self.logger.add("nu", self.ctrl_config["robot"]["dims"]["u"])
110110

111+
# Get shared timestamp from ROS parameter (set by sim node)
112+
# Wait for sim node to set it
113+
while not rospy.has_param("/experiment_timestamp"):
114+
rospy.sleep(0.1)
115+
self.session_timestamp = rospy.get_param("/experiment_timestamp")
116+
111117
# ROS Related
112118
self.robot_interface = MobileManipulatorROSInterface()
113119
self.vicon_tool_interface = ViconObjectInterface(
@@ -186,7 +192,7 @@ def __init__(self):
186192
def shutdownhook(self):
187193
self.ctrl_c = True
188194
self.robot_interface.brake()
189-
self.logger.save()
195+
self.logger.save(session_timestamp=self.session_timestamp)
190196

191197
def _publish_cmd_vel(self, event):
192198
if self.mpc_plan is not None:

mm_run/nodes/planner_test_ros.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import datetime
23
import logging
34
import os
45
import sys
@@ -81,6 +82,11 @@ def __init__(self):
8182

8283
# init logger
8384
self.logger = DataLogger(config.copy(), name="control")
85+
86+
# Create timestamp for logging
87+
timestamp = datetime.datetime.now()
88+
self.session_timestamp = timestamp.strftime("%Y-%m-%d_%H-%M-%S")
89+
8490
# ROS Related
8591
self.robot_interface = MobileManipulatorROSInterface()
8692
self.vicon_tool_interface = ViconObjectInterface(
@@ -124,7 +130,7 @@ def __init__(self):
124130
def shutdownhook(self):
125131
self.ctrl_c = True
126132
self.robot_interface.brake()
127-
self.logger.save()
133+
self.logger.save(session_timestamp=self.session_timestamp)
128134

129135
def _publish_planner_data(self, event):
130136
self.sot_lock.acquire()

mm_run/nodes/sim_ros.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def main():
6464
# initial time, state, input
6565
t = 0.0
6666

67+
# Create shared timestamp for logging (format: YYYY-MM-DD_HH-MM-SS)
68+
session_timestamp = timestamp.strftime("%Y-%m-%d_%H-%M-%S")
69+
70+
# Set ROS parameter so control node can use the same timestamp
71+
rospy.init_node("sim_ros")
72+
rospy.set_param("/experiment_timestamp", session_timestamp)
73+
6774
# init logger
6875
logger = DataLogger(config, name="sim")
6976
logger.add("sim_timestep", sim.timestep)
@@ -75,7 +82,6 @@ def main():
7582
logger.add("nu", sim_config["robot"]["dims"]["u"])
7683

7784
# ros interface
78-
rospy.init_node("sim_ros")
7985
ros_interface = SimulatedMobileManipulatorROSInterface()
8086
ros_interface.publish_time(t)
8187

@@ -123,7 +129,7 @@ def main():
123129
t, _ = sim.step(t)
124130
time.sleep(sim.timestep)
125131

126-
logger.save()
132+
logger.save(session_timestamp=session_timestamp)
127133

128134

129135
if __name__ == "__main__":

mm_run/scripts/experiment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ def main():
223223

224224
time.sleep(sim.timestep)
225225

226-
logger.save()
226+
session_timestamp = timestamp.strftime("%Y-%m-%d_%H-%M-%S")
227+
logger.save(session_timestamp=session_timestamp)
227228

228229

229230
if __name__ == "__main__":

mm_utils/src/mm_utils/logging.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from datetime import datetime
21
from pathlib import Path
32

43
import numpy as np
@@ -53,16 +52,16 @@ def append(self, key, value):
5352
# Start new list
5453
self.data[key] = [a]
5554

56-
def save(self):
55+
def save(self, session_timestamp):
5756
"""Save the data and configuration to a timestamped directory.
5857
5958
Directory structure:
6059
<base_directory>/<session_timestamp>/<name>/
6160
data.npz
6261
config.yaml
62+
63+
:param session_timestamp: Timestamp string in format "%Y-%m-%d_%H-%M-%S".
6364
"""
64-
# Create timestamped directory for this logging session
65-
session_timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
6665
dir_path = self.base_directory / session_timestamp / self.name
6766
dir_path.mkdir(parents=True, exist_ok=True)
6867

mm_utils/src/mm_utils/plotting/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
- Utility functions: Logger construction
99
"""
1010

11-
from mm_utils.plotting.core import DataPlotter, construct_logger
12-
from mm_utils.plotting.mpc import MPCPlotterMixin
13-
from mm_utils.plotting.trajectory import TrajectoryPlotterMixin
11+
from mm_utils.plotting.plot_mpc import MPCPlotterMixin
12+
from mm_utils.plotting.plot_trajectory import TrajectoryPlotterMixin
13+
from mm_utils.plotting.plotting_core import DataPlotter, construct_logger
1414

1515
__all__ = [
1616
"DataPlotter",
File renamed without changes.
File renamed without changes.

mm_utils/src/mm_utils/plotting/core.py renamed to mm_utils/src/mm_utils/plotting/plotting_core.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import mm_control.MPC as MPC
1717
from mm_utils import math, parsing
1818
from mm_utils.math import wrap_pi_array
19-
from mm_utils.plotting.mpc import MPCPlotterMixin
20-
from mm_utils.plotting.trajectory import TrajectoryPlotterMixin
19+
from mm_utils.plotting.plot_mpc import MPCPlotterMixin
20+
from mm_utils.plotting.plot_trajectory import TrajectoryPlotterMixin
2121

2222
# =============================================================================
2323
# UTILITY FUNCTIONS
@@ -227,8 +227,6 @@ def _post_processing(self):
227227
nq = self.data["nq"]
228228
qs = self.data["xs"][:, :nq]
229229

230-
print(self.data["xs"].shape)
231-
232230
# keyed by obstacle names or "self"
233231
names = ["self", "static_obstacles"]
234232
params = {"self": [], "static_obstacles": []}
@@ -355,7 +353,6 @@ def _post_processing(self):
355353
self.data["mpc_ee_predictions"] = []
356354
self.data["mpc_base_predictions"] = []
357355

358-
print(self.data["mpc_x_bars"].shape)
359356
for t_index in range(N):
360357
x_bar = self.data["mpc_x_bars"][t_index]
361358
ee_bar, base_bar = self.controller._getEEBaseTrajectories(x_bar)
@@ -493,7 +490,6 @@ def _get_statistics(self):
493490
"max": run_time_states[1],
494491
"min": run_time_states[2],
495492
}
496-
print(self.data["statistics"]["constraints_violation"]["num"])
497493

498494
def summary(self, stat_names):
499495
"""get a summary of statistics

0 commit comments

Comments
 (0)