Skip to content

Commit

Permalink
split pose and orientation position plotters
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoussan committed Jan 23, 2024
1 parent 6aa793f commit 9009dab
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 67 deletions.
4 changes: 2 additions & 2 deletions localization/graph_vio/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

- start plotting VIO!
- run new localizer using a bag file, save results to bag!
- does this already exist??? test!
- update script! make sure it works! (AAA)
- fix plotting orientations and positions in same plots! (A)
- add plotting graph vio states! (B)
- add super init calls to inherited pose states!
- finish plot vio script! (AA)
- Avoid iterating through bag multiple times!!!
Expand Down
79 changes: 14 additions & 65 deletions tools/localization_analysis/scripts/multipose_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import matplotlib
from orientation_plotter import OrientationPlotter
from position_plotter import PositionPlotter
import plot_conversions
import pose
import vector3d_plotter
from multivector3d_plotter import MultiVector3dPlotter

matplotlib.use("pdf")
import matplotlib.pyplot as plt
Expand All @@ -41,7 +42,8 @@ def __init__(self, xlabel, ylabel, title, individual_plots = False):
self.ylabel = ylabel
self.title = title
self.individual_plots = individual_plots
self.vector3d_plotters = []
self.orientations_plotter = MultiVector3dPlotter(xlabel, ylabel, title, individual_plots)
self.positions_plotter = MultiVector3dPlotter(xlabel, ylabel, title, individual_plots)

# Add poses to position and orientation plots
def add_poses(self,
Expand All @@ -54,15 +56,15 @@ def add_poses(self,
markeredgewidth=None,
markersize=1,
):
self.add_poses_positions(name, timestamped_poses,
self.add_pose_positions(name, timestamped_poses,
colors,
linestyle,
linewidth,
marker,
markeredgewidth,
markersize)

self.add_poses_orientations(name, timestamped_poses,
self.add_pose_orientations(name, timestamped_poses,
colors,
linestyle,
linewidth,
Expand All @@ -73,7 +75,7 @@ def add_poses(self,


# Add poses to position plots.
def add_poses_positions(
def add_pose_positions(
self,
name,
timestamped_poses,
Expand All @@ -87,24 +89,23 @@ def add_poses_positions(

xyz_vectors = plot_conversions.xyz_vectors_from_poses(timestamped_poses)
times = plot_conversions.times_from_timestamped_objects(timestamped_poses)
position_plotter = vector3d_plotter.Vector3dPlotter(
position_plotter = PositionPlotter(
name,
times,
xyz_vectors[0],
xyz_vectors[1],
xyz_vectors[2],
["Pos. (X)", "Pos. (Y)", "Pos. (Z)"],
colors,
linestyle,
linewidth,
marker,
markeredgewidth,
markersize,
)
self.add_vector3d_plotter(position_plotter)
self.positions_plotter.add(position_plotter)

# Add poses to orientation plots
def add_poses_orientations(
def add_pose_orientations(
self,
name,
timestamped_poses,
Expand All @@ -130,62 +131,10 @@ def add_poses_orientations(
markeredgewidth,
markersize,
)
self.add_vector3d_plotter(orientation_plotter)
self.orientations_plotter.add(orientation_plotter)

# Helper function to add vector 3d plotters that should be called during plotting.
def add_vector3d_plotter(self, vector3d_plotter):
self.vector3d_plotters.append(vector3d_plotter)

# Plot each of the added y values. Optionally plot individual axes on seperate plots
# Plot each of the added pose values. Plots positions and orientations in different plots. Optionally plot individual axes on seperate plots
# if individual_plots set to True.
def plot(self, pdf, individual_plots=True):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_xyz()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()

if individual_plots:
self.plot_xs(pdf)
self.plot_ys(pdf)
self.plot_zs(pdf)

# Plot x values.
def plot_xs(self, pdf):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_x()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()

# Plot y values.
def plot_ys(self, pdf):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_y()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()

# Plot z values.
def plot_zs(self, pdf):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_z()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()
self.positions_plotter.plot(pdf, individual_plots)
self.orientations_plotter.plot(pdf, individual_plots)
98 changes: 98 additions & 0 deletions tools/localization_analysis/scripts/multivector3d_plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/python
#
# Copyright (c) 2017, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
#
# All rights reserved.
#
# The Astrobee platform is licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import matplotlib
from vector3d_plotter import Vector3dPlotter
import plot_conversions
import pose
import vector3d_plotter

matplotlib.use("pdf")
import matplotlib.pyplot as plt
import numpy as np
import sys

# Plotter that allows plotting multiple vector3d values in the same plots.
# Pass vector3d values to plot using the add function.
# Optionally also plot individual plots for each vector component (x/y/z) if individual plots is true.
class MultiVector3dPlotter:
def __init__(self, xlabel, ylabel, title, individual_plots = False):
self.xlabel = xlabel
self.ylabel = ylabel
self.title = title
self.individual_plots = individual_plots
self.vector3d_plotters = []

# Adds vector3d plotter to be plot
def add(self, vector3d_plotter):
self.vector3d_plotters.append(vector3d_plotter)

# Plot each of the vector3d values. Optionally plot individual axes on seperate plots
# if individual_plots set to True.
def plot(self, pdf, individual_plots=True):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_xyz()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()

if individual_plots:
self.plot_xs(pdf)
self.plot_ys(pdf)
self.plot_zs(pdf)

# Plot x values.
def plot_xs(self, pdf):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_x()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()

# Plot y values.
def plot_ys(self, pdf):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_y()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()

# Plot z values.
def plot_zs(self, pdf):
plt.figure()
for vector3d_plotter in self.vector3d_plotters:
vector3d_plotter.plot_z()
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.title(self.title)
plt.legend(prop={"size": 6})
pdf.savefig()
plt.close()
49 changes: 49 additions & 0 deletions tools/localization_analysis/scripts/position_plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/python
#
# Copyright (c) 2017, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
#
# All rights reserved.
#
# The Astrobee platform is licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from vector3d_plotter import Vector3dPlotter

# Class for plotting XYZ position values on the same and separate plots.
class PositionPlotter(Vector3dPlotter):
def __init__(
self,
name,
times,
x_vals,
y_vals,
z_vals,
colors=["r", "b", "g"],
linestyle="-",
linewidth=1,
marker=None,
markeredgewidth=None,
markersize=1,
):
super(PositionPlotter, self).__init__(name,
times,
x_vals,
y_vals,
z_vals,
["Position (X)", "Position (Y)", "Position (Z)"],
colors,
linestyle,
linewidth,
marker,
markeredgewidth,
markersize)

0 comments on commit 9009dab

Please sign in to comment.