我想做的是调用Python中的C++方法返回一个2D数组。Python文件名是:BAXTARAR1.1.PY和C++文件名是:巴西克.cpp. 下面是我如何编译我的c++程序:
g++ -c -fPIC baxIK.cpp -o baxIK.o
g++ -shared -Wl,-soname,baxIK.so -o baxIK.so baxIK.o
是C++程序的相关部分:
^{pr2}$其思想是返回一个Nx7数组供Python接收。Python代码如下:
def sendArm(xGoal, yGoal, zGoal, right, lj):
print "Goals %f %f %f" % (xGoal, yGoal, zGoal)
output = ctypes.CDLL(os.path.dirname('baxIK.so'))
output.compute.restype = POINTER(c_float)
output.compute.argtypes = [c_float, c_float, c_float, c_float, c_float, c_float, c_float]
res = output.compute(xGoal, yGoal, zGoal, 0.707, 0, 0.7, 0)
print(res)
我得到的错误是在线的
output.compute.restype = POINTER(c_float)
回溯如下:
File "/home/eadom/ros_ws/src/baxter_examples/scripts/BaxterArm1.py", line 60, in sendArm
output.compute.restype = POINTER(c_float)
File "/usr/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: python: undefined symbol: compute
我不知道该怎么解决这个问题。另外,有人能检查一下这个,看看我是否正确地发送了2D数组?因为它只是发送一个1D数组,但我找不到任何关于发送2D数组的内容。我很感激你的帮助。在
终于成功了!问题是
(os.path.dirname('baxIK.so')
返回了一个空字符串,所以我把它放在了完整的目录中。我通过用llapack编译g++修复了前面提到的另一个问题,现在我正在修复最后一个细节。我希望这对其他人有帮助。在相关问题 更多 >
编程相关推荐