python - Dynamic updating a Matplotlib 3D plot -


i trying update 3d plot using matplotlib. collecting data using ros. want update plot data. have looked around , found this, dynamically updating plot in matplotlib

but cannot work. new python , not full understand how works yet. apologize if code disgusting.

i keep error.

[error] [walltime: 1435801577.604410] bad callback: <function usbl_move @ 0x7f1e45c4c5f0> traceback (most recent call last):   file "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 709, in _invoke_callback     cb(msg, cb_args)   file "/home/nathaniel/simulation/src/move_videoray/src/move_filtered.py", line 63, in usbl_move     if filter(pos.pose.position.x,pos.pose.position.y,current.position.z):   file "/home/nathaniel/simulation/src/move_videoray/src/move_filtered.py", line 127, in filter     plt.draw()   file "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 555, in draw     get_current_fig_manager().canvas.draw()   file "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 349, in draw     tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)   file "/usr/lib/pymodules/python2.7/matplotlib/backends/tkagg.py", line 13, in blit     tk.call("pyaggimagephoto", photoimage, id(aggimage), colormode, id(bbox_array)) runtimeerror: main thread not in main loop 

this code trying run

#!/usr/bin/env python   '''     ths program moves videoray model in rviz using      data /usble_pose node     based on "using urdf robot_state_publisher" tutorial  '''  import rospy import roslib import math import tf #import outlier_filter geometry_msgs.msg import twist, vector3, pose, posestamped, transformstamped matplotlib import matplotlib_fname mpl_toolkits.mplot3d import axes3d import sys matplotlib.pyplot import plot numpy import mean, std import matplotlib mpl  import numpy np import pandas pd import random import matplotlib.pyplot plt #plt.ion() import matplotlib mpl.rc("savefig", dpi=150) import matplotlib.animation animation import time  #filter stuff #window size n = 10 #make starting values #random distance md =[random.random() _ in range(0, n)] #random points x_list = [random.random() _ in range(0, n)] y_list =[random.random() _ in range(0, n)] #set graph fig = plt.figure() ax = fig.add_subplot(111, projection='3d') #ax.scatter(filt_x,filt_y,filt_depth,color='b') #ax.scatter(outlier_x,outlier_y,outlier_depth,color='r')  ax.set_xlabel('x') ax.set_ylabel('y') ax.set_zlabel('z') ax.set_title('xy outlier rejection \n mahalanobis distance , rolling mean3')    #set robot @ center   #//move videoray using data /pose_only node def usbl_move(pos,current):       broadcaster = tf.transformbroadcaster()     if filter(pos.pose.position.x,pos.pose.position.y,current.position.z):         current.position.x = pos.pose.position.x         current.position.y = pos.pose.position.y       broadcaster.sendtransform( (current.position.x,current.position.y,current.position.z),                                  (current.orientation.x,current.orientation.y,current.orientation.z,current.orientation.w),                                      rospy.time.now(), "odom", "body" )   #move videoray using data /pose_only node   def pose_move(pos,current):      #pos.position.z in kpa, has convereted depth     # p  = p0 + pgz ----> pos.position.z = p0 + pg*z_real     z_real = -1*(pos.position.z -101.325)/9.81;      #update movement     broadcaster = tf.transformbroadcaster()     current.orientation.x = pos.orientation.x     current.orientation.y = pos.orientation.y     current.orientation.z = pos.orientation.z     current.orientation.w = pos.orientation.w     current.position.z = z_real     broadcaster.sendtransform( (current.position.x,current.position.y,current.position.z),                                  (current.orientation.x,current.orientation.y,current.orientation.z,current.orientation.w),                                      rospy.time.now(), "odom", "body" )    #call fitle date  def filter(x,y,z):     # update window     is_good = false     x_list.append(x)     y_list.append(y)     x_list.pop(0)     y_list.pop(0)     #get covariance matrix     v = np.linalg.inv(np.cov(x_list,y_list,rowvar=0))     #get mean vector     r_mean = mean(x_list), mean(y_list)       #subtract mean vector point     x_diff = np.array([i - r_mean[0] in x_list])     y_diff = np.array([i - r_mean[1] in y_list])     #combinded , transpose x,y diff matrix     diff_xy = np.transpose([x_diff, y_diff])     # calculate mahalanobis distance     dis = np.sqrt(np.dot(np.dot(np.transpose(diff_xy[n-1]),v),diff_xy[n-1]))     # update window      md.append( dis)     md.pop(0)     #find mean , standard standard deviation of standard deviation list     mu  = np.mean(md)     sigma = np.std(md)     #threshold find if outlier     if dis < mu + 1.5*sigma:         #filt_x.append(x)         #filt_y.append(y)         #filt_depth.append(z)         ax.scatter(x,y,z,color='b')         is_good =  true     else:         ax.scatter(x,y,z,color='r')     plt.draw()     return is_good     if __name__ == '__main__':     #set node     rospy.init_node('move_unfiltered', anonymous=true)     #make broadcaster foir tf frame     broadcaster = tf.transformbroadcaster()     #make intilial values     current = pose()     current.position.x = 0     current.position.y = 0     current.position.z = 0     current.orientation.x = 0     current.orientation.y = 0     current.orientation.z = 0     current.orientation.w = 0     #send tf frame     broadcaster.sendtransform( (current.position.x,current.position.y,current.position.z),                                  (current.orientation.x,current.orientation.y,current.orientation.z,current.orientation.w),                                      rospy.time.now(), "odom", "body" )      #listen information      rospy.subscriber("/usbl_pose", posestamped, usbl_move,current)     rospy.subscriber("/pose_only", pose, pose_move, current);     rospy.spin() 


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -