Skip to content
Snippets Groups Projects
Commit 2019c224 authored by m-guberina's avatar m-guberina
Browse files

got 30fps without tkinter. if i do the same in tkinter, then the past drawings...

got 30fps without tkinter. if i do the same in tkinter, then the past drawings are not removed, and the thing is slow still. ideally there is a really simple fix for this, but it remains to be found
parent 2409bd0c
No related branches found
No related tags found
No related merge requests found
Showing
with 50 additions and 9 deletions
No preview for this file type
import matplotlib.pyplot as plt
import numpy as np
import time
x = np.linspace(0, 2 * np.pi, 100)
......@@ -30,7 +31,8 @@ ax.draw_artist(ln)
# renderer to the GUI framework so you can see it
fig.canvas.blit(fig.bbox)
for j in range(100):
for j in range(1000):
start = time.time()
# reset the background back in the canvas state, screen unchanged
fig.canvas.restore_region(bg)
# update the artist, neither the canvas state nor the screen have changed
......@@ -41,5 +43,8 @@ for j in range(100):
fig.canvas.blit(fig.bbox)
# flush any pending GUI events, re-painting the screen if needed
fig.canvas.flush_events()
end = time.time()
print("time on rendering", end - start)
print("fps: ", 1/ (end - start))
# you can put a pause in if you want to slow things down
# plt.pause(.1)
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('dark_background')
fig, ax = plt.subplots()
L = 6
x = np.linspace(0, L)
ncolors = len(plt.rcParams['axes.prop_cycle'])
shift = np.linspace(0, L, ncolors, endpoint=False)
for s in shift:
ax.plot(x, np.sin(x + s), 'o-')
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.set_title("'dark_background' style sheet")
plt.show()
......@@ -405,10 +405,10 @@ def update_points(new_val):
ik_env.p_e_point_plots[robot_index].set_data([ik_env.data[robot_index]['p_es'][index][0]], [ik_env.data[robot_index]['p_es'][index][1]])
ik_env.p_e_point_plots[robot_index].set_3d_properties([ik_env.data[robot_index]['p_es'][index][2]])
canvas_ee.draw()
#canvas_manipulator.draw()
canvas_manipulator.draw()
# NEW
# might need to manually update all artists here from ax_something
canvas_manipulator.blit(fig_manipulator.bbox)
#canvas_manipulator.blit(fig_manipulator.bbox)
canvas_manip_graphs.draw()
canvas_imu.draw()
# TODO update may not be needed as we're going by slider here
......
File added
......@@ -6,6 +6,7 @@ from robot_stuff.utils import *
# general imports
import numpy as np
import matplotlib.pyplot as plt
# ######################################### NOTE #########################
# i'm half-adding another robot for the purposes of the plot.
......@@ -144,7 +145,7 @@ class InverseKinematicsEnv:
self.drawingInited = False
if self.drawingInited == False:
plt.ion()
#plt.ion()
self.fig = plt.figure()
#self.ax = self.fig.add_subplot(111, projection='3d')
self.ax = self.fig.add_subplot(111, projection='3d')
......@@ -156,13 +157,30 @@ class InverseKinematicsEnv:
color_link = 'black'
self.robot.initDrawing(self.ax, color_link)
self.drawingInited = True
plt.pause(0.1)
# put this here for good measure
self.robot.drawStateAnim()
self.bg = self.fig.canvas.copy_from_bbox(self.fig.bbox)
# manual blitting basically
# restore region
self.fig.canvas.restore_region(self.bg)
# updating all the artists (set new properties (position bla))
self.robot.drawStateAnim()
# now you need to manually draw all the artist (otherwise you update everything)
# thank god that's just lines, all in a list.
# btw, that should definitely be a dictionary, not a list,
# this makes the code fully unreadable (although correct).
for link in self.robot.lines:
for line in link:
self.ax.draw_artist(line)
self.fig.canvas.blit(self.fig.bbox)
# NOTE: this might not work
self.ax.set_title(str(self.n_of_tries_for_point) + 'th iteration toward goal')
drawPoint(self.ax, self.goal, 'red', 'o')
# if no draw it is kinda faster
#self.fig.canvas.draw()
# this is even faster
self.fig.canvas.update()
#self.fig.canvas.update()
self.fig.canvas.flush_events()
......
No preview for this file type
No preview for this file type
......@@ -133,10 +133,10 @@ class Robot_raw:
z_hat = self.joints[j].HomMat[0:3,2]
p = self.joints[j].HomMat[0:3,3]
line_x, = self.ax.plot(np.array([]),np.array([]),np.array([]), 'r')
line_y, = self.ax.plot(np.array([]),np.array([]),np.array([]), 'g')
line_z, = self.ax.plot(np.array([]),np.array([]),np.array([]), 'b')
line_p, = self.ax.plot(np.array([]),np.array([]),np.array([]), self.color_link)
line_x, = self.ax.plot(np.array([]),np.array([]),np.array([]), 'r')#, animated=True)
line_y, = self.ax.plot(np.array([]),np.array([]),np.array([]), 'g')#, animated=True)
line_z, = self.ax.plot(np.array([]),np.array([]),np.array([]), 'b')#, animated=True)
line_p, = self.ax.plot(np.array([]),np.array([]),np.array([]), self.color_link)#, animated=True)
self.lines += [[line_x, line_y, line_z, line_p]]
avg_link_lenth += self.joints[j].d + self.joints[j].r
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment