Incorperated rsi visualiser code.
This commit is contained in:
parent
1d60fa3bd7
commit
346fdc8c55
0
src/RSIPI/__init__.py
Normal file
0
src/RSIPI/__init__.py
Normal file
@ -1,4 +1,5 @@
|
||||
from .rsi_client import RSIClient
|
||||
from .kuka_visualizer import KukaRSIVisualizer
|
||||
|
||||
class RSICommandLineInterface:
|
||||
"""Command-Line Interface for controlling RSI Client."""
|
||||
@ -73,6 +74,10 @@ class RSICommandLineInterface:
|
||||
self.running = False
|
||||
elif cmd == "help":
|
||||
self.show_help()
|
||||
elif cmd == "visualize" and len(parts) >= 2:
|
||||
csv_file = parts[1]
|
||||
export = ("export" in parts)
|
||||
self.visualize(csv_file, export)
|
||||
else:
|
||||
print("❌ Unknown command. Type 'help' for a list of commands.")
|
||||
|
||||
@ -136,6 +141,18 @@ Available Commands:
|
||||
set_alert_threshold <deviation|force> <value>
|
||||
""")
|
||||
|
||||
def visualize(self, csv_file, export=False):
|
||||
try:
|
||||
visualizer = KukaRSIVisualizer(csv_file)
|
||||
visualizer.plot_trajectory()
|
||||
visualizer.plot_joint_positions()
|
||||
visualizer.plot_force_trends()
|
||||
|
||||
if export:
|
||||
visualizer.export_graphs()
|
||||
print(f"✅ Visualisations exported for '{csv_file}'")
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to visualize '{csv_file}': {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
config_file = "RSI_EthernetConfig.xml"
|
||||
|
||||
@ -5,6 +5,7 @@ import json
|
||||
import matplotlib.pyplot as plt
|
||||
from .rsi_client import RSIClient
|
||||
from .graphing import RSIGraphing
|
||||
from .kuka_visualizer import KukaRSIVisualizer
|
||||
|
||||
class RSIAPI:
|
||||
"""RSI API for programmatic control, including alerts, logging, graphing, and data retrieval."""
|
||||
@ -196,3 +197,19 @@ class RSIAPI:
|
||||
plt.savefig(f"{filename}.pdf")
|
||||
|
||||
return f"✅ Report saved as {filename}.{format_type}"
|
||||
|
||||
def visualize_csv_log(self, csv_file, export=False):
|
||||
"""
|
||||
Visualize CSV log file directly via RSIAPI.
|
||||
|
||||
Args:
|
||||
csv_file (str): Path to CSV log file.
|
||||
export (bool): Whether to export the plots.
|
||||
"""
|
||||
visualizer = KukaRSIVisualizer(csv_file)
|
||||
visualizer.plot_trajectory()
|
||||
visualizer.plot_joint_positions()
|
||||
visualizer.plot_force_trends()
|
||||
|
||||
if export:
|
||||
visualizer.export_graphs()
|
||||
@ -85,5 +85,23 @@ class TestRSIPI(unittest.TestCase):
|
||||
response_threshold = self.api.set_alert_threshold("deviation", 3.5)
|
||||
self.assertIn("✅ Deviation alert threshold set to 3.5", response_threshold)
|
||||
|
||||
def test_visualization_methods(self):
|
||||
csv_file = "test_log.csv"
|
||||
# Create a dummy CSV file for testing
|
||||
pd.DataFrame({
|
||||
"RIst.X": [0, 1, 2], "RIst.Y": [0, 1, 2], "RIst.Z": [0, 1, 2],
|
||||
"AIPos.A1": [10, 20, 30], "PosCorr.X": [0.1, 0.2, 0.3]
|
||||
}).to_csv(csv_file, index=False)
|
||||
|
||||
try:
|
||||
self.api.visualize_csv_log(csv_file, export=True)
|
||||
except Exception as e:
|
||||
self.fail(f"Visualisation test failed: {e}")
|
||||
finally:
|
||||
import os, shutil
|
||||
os.remove(csv_file)
|
||||
if os.path.exists("exports"):
|
||||
shutil.rmtree("exports")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue
Block a user