diff --git a/python/initial_python_solution/.blit_test.py.swp b/python/initial_python_solution/.blit_test.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..5c52e18edb5224f1c6bd60b1766faf468b66fb90 Binary files /dev/null and b/python/initial_python_solution/.blit_test.py.swp differ diff --git a/python/initial_python_solution/.manipulator_visual_motion_analyzer.py.swp b/python/initial_python_solution/.manipulator_visual_motion_analyzer.py.swp index 12b2cf4aa8c3ea2f063d13812214aa29f1ac0189..6dfe2a96bb05e401c7327f20ce338af45f733479 100644 Binary files a/python/initial_python_solution/.manipulator_visual_motion_analyzer.py.swp and b/python/initial_python_solution/.manipulator_visual_motion_analyzer.py.swp differ diff --git a/python/initial_python_solution/blit_test.py b/python/initial_python_solution/blit_test.py index d0a97298e9a823b5f94348b10c782f696def9b47..b6832cf6cae4d284c2edaa1545be8e07267062c0 100644 --- a/python/initial_python_solution/blit_test.py +++ b/python/initial_python_solution/blit_test.py @@ -1,5 +1,6 @@ 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) diff --git a/python/initial_python_solution/dark_background_example.py b/python/initial_python_solution/dark_background_example.py new file mode 100644 index 0000000000000000000000000000000000000000..df4705fe580e35d85b12a9c28272d61f6d42d968 --- /dev/null +++ b/python/initial_python_solution/dark_background_example.py @@ -0,0 +1,18 @@ +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() diff --git a/python/initial_python_solution/manipulator_visual_motion_analyzer.py b/python/initial_python_solution/manipulator_visual_motion_analyzer.py index 3cea2701b7776da660e13f6492dca66e2dc9aeb3..23a428da562b03b6b72f0ae07e0145bf91670251 100644 --- a/python/initial_python_solution/manipulator_visual_motion_analyzer.py +++ b/python/initial_python_solution/manipulator_visual_motion_analyzer.py @@ -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 diff --git a/python/initial_python_solution/robot_stuff/.InverseKinematics.py.swp b/python/initial_python_solution/robot_stuff/.InverseKinematics.py.swp deleted file mode 100644 index a9ec7ce2e024e479f6e20b5e8b5460644f0e31c2..0000000000000000000000000000000000000000 Binary files a/python/initial_python_solution/robot_stuff/.InverseKinematics.py.swp and /dev/null differ diff --git a/python/initial_python_solution/robot_stuff/.forw_kinm.py.swp b/python/initial_python_solution/robot_stuff/.forw_kinm.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..c0aefbb19e9fc5f2403b0c03a9d5e4906deb177d Binary files /dev/null and b/python/initial_python_solution/robot_stuff/.forw_kinm.py.swp differ diff --git a/python/initial_python_solution/robot_stuff/InverseKinematics.py b/python/initial_python_solution/robot_stuff/InverseKinematics.py index 8cbe712bd58bf4ef3b8e7dd4251d6192d8464bcc..9cd579d94725f7e951d9a585bbc5869f95604d50 100644 --- a/python/initial_python_solution/robot_stuff/InverseKinematics.py +++ b/python/initial_python_solution/robot_stuff/InverseKinematics.py @@ -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() diff --git a/python/initial_python_solution/robot_stuff/__pycache__/InverseKinematics.cpython-310.pyc b/python/initial_python_solution/robot_stuff/__pycache__/InverseKinematics.cpython-310.pyc index 47e56460692494af368d10f7e35571c312e88590..2396b89a46501036d462e70fa75232ab54f4e46f 100644 Binary files a/python/initial_python_solution/robot_stuff/__pycache__/InverseKinematics.cpython-310.pyc and b/python/initial_python_solution/robot_stuff/__pycache__/InverseKinematics.cpython-310.pyc differ diff --git a/python/initial_python_solution/robot_stuff/__pycache__/forw_kinm.cpython-310.pyc b/python/initial_python_solution/robot_stuff/__pycache__/forw_kinm.cpython-310.pyc index 83515247013d576e7357d50aa88d446cd98cef1c..fef8c56c5d57b61d99de335ea07b479488fdf269 100644 Binary files a/python/initial_python_solution/robot_stuff/__pycache__/forw_kinm.cpython-310.pyc and b/python/initial_python_solution/robot_stuff/__pycache__/forw_kinm.cpython-310.pyc differ diff --git a/python/initial_python_solution/robot_stuff/forw_kinm.py b/python/initial_python_solution/robot_stuff/forw_kinm.py index 267373b677b03903ea5fdad41ead95d577acfb11..dbf3d3e077bbd38e7084b3f0c8325d5679a2da36 100644 --- a/python/initial_python_solution/robot_stuff/forw_kinm.py +++ b/python/initial_python_solution/robot_stuff/forw_kinm.py @@ -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