如何在python中的两个函数之间传递数组?

时间:2019-07-02 13:10:34

标签: python arrays function

我希望将三个数组:xLinespaceyLinespacezLinespace从函数cubicSplineInterpolate传递给函数trajectoryMover。但是我不确定如何使用python实现此目的。将数组传递给第二个函数后,我打算同时遍历每个数组以更改机器人的位置。我需要在每个函数中将数组设置为参数吗?

class example_application:

    def cubicSplineInterpolate(self, x_axis, y_axis, z_axis):

        m=1
        xLinespace=[]
        yLinespace=[]
        zLinespace=[]
        while m<len(x_axis):
            for t in np.arange(m-1,m,1/float(100)):
                xLinespace.append(self.func(x_axis[m-1],x_axis[m],t,U[m-1],U[m],m-1,m))
                yLinespace.append(self.func(y_axis[m-1],y_axis[m],t,V[m-1],V[m],m-1,m))
                zLinespace.append(self.func(z_axis[m-1],z_axis[m],t,W[m-1],W[m],m-1,m))
            m=m+1

    def trajectoryMover(self):
        newPose = Pose()
        xLinespace=[]
        yLinespace=[]
        zLinespace=[]
        x_axis = [0.01, 0.02, 0.033, 0.0044, 0.0001, 0.10]
        y_axis = [0.002, 0.00033, 0.1014, 0.01512, 0.14316, 0.015143]
        z_axis = [0.003, 0.2124, 0.15417, 0.15615, 0.01241, 0.151561]
        self.cubicSplineInterpolate(x_axis,y_axis,z_axis)
        print(self.cubicSplineInterpolate.xLinespace)

        for x, y, z in zip(x_axis, y_axis, z_axis):

            newPose.position.x = x
            newPose.position.y = y
            newPose.position.z = z
            newPose.orientation.x = -0.907106781172
            newPose.orientation.y = -0.0707106781191
            newPose.orientation.z = 2.59734823723e-06
            newPose.orientation.w = -2.59734823723e-06
            self.set_position_cartesian.publish(newPose)
            rospy.loginfo(newPose)
            rospy.sleep(1)

1 个答案:

答案 0 :(得分:1)

从评论中:如果const browser = await puppeteer.connect({browserURL: 'http://127.0.0.1:9222'}); 呼叫json/version

class example_application:

trajectoryMover

还要注意(尽管不是很重要):我相信PEP8表示函数应使用下划线分隔,即trajectory_mover和cubic_spline_interpolate()