gps_fusion.py now shows second order system results with the Displayer (position, not yet uncertainty)

This commit is contained in:
Andreas Tsouchlos
2022-04-21 17:17:01 +02:00
parent b95561011b
commit 04a9db824c
3 changed files with 67 additions and 31 deletions

View File

@@ -3,16 +3,13 @@ from matplotlib.animation import FuncAnimation
import numpy as np
#
# Displayer class
#
class Displayer:
def __init__(self, width, height):
def __init__(self, width, height, frame_interval=50):
self._fig, self._ax = plt.subplots()
self._fig.set_figwidth(width)
self._fig.set_figheight(height)
self._frame_interval = frame_interval
self._object_map = {}
self._circle_map = {}
self._objects = []
@@ -31,14 +28,12 @@ class Displayer:
return self._objects
#
# Functions for initalization
#
def set_axis_limits(self, min, max):
self._xlim = (min, max)
self._ylim = (min, max)
def set_axis_limits(self, xlim, ylim):
self._xlim = xlim
self._ylim = ylim
def register_object(self, obj_name, obj_color='r'):
@@ -49,22 +44,18 @@ class Displayer:
self._objects.append(self._circle_map[obj_name])
#
# Functions to be used in the animation callback
#
def move_object(self, obj_name, x, y):
self._object_map[obj_name].set_data([x, y])
self._circle_map[obj_name].center = (x, y)
def move_object(self, obj_name, position):
self._object_map[obj_name].set_data(position)
self._circle_map[obj_name].center = position
def set_circle_radius(self, obj_name, r):
self._circle_map[obj_name].radius = r
#
# Start the animation
#
def animate(self, n_steps, anim_callback):
@@ -72,6 +63,10 @@ class Displayer:
anim_callback(self, t)
return self._objects
anim = FuncAnimation(self._fig, anim_callback_wrapper, frames=np.linspace(0, n_steps-1, n_steps),
init_func=self.__init_animation, blit=True)
anim = FuncAnimation(self._fig,
anim_callback_wrapper,
n_steps,
interval=self._frame_interval,
init_func=self.__init_animation,
blit=True)
plt.show()