I'm using the Matlab API for Python because I want to use the robotics toolbox.

3 views (last 30 days)
The function I made works fine on Matlab but isn't working on Python.
Matlab function
function [values_rad]= CapstoneRobot(x, y, z, th1, th2, th3, th4, th5)
d1 = 14; a2 = 22; a3 = 22; a5=5;
position = transl(x, y, z);
L1 = link([pi/2 0 0 14]);
L2 = link([0 22 0 0]);
L3 = link([pi/2 0 0 0]);
L4 = link([pi/2 0 0 22]);
L5 = link([0 5 0 0]);
RRR_EX = robot({L1 L2 L3 L4 L5});
ic = double([th1 th2 th3 th4 th5]);
values_rad = double(ikine(RRR_EX, position, ic, [1 1 1 1 1 0]));
the Python code
import matlab.engine
eng = matlab.engine.start_matlab()
t= eng.CapstoneRobot(16, 16, 16, 0.7854, 1.1111, -0.8795, 0, -0.0704)
print(t)
Error
Traceback (most recent call last):
File "C:/Users/Jinadasa_J/Desktop/Ishira/Maty.py", line 4, in <module>
t= eng.CapstoneRobot(16, 16, 16, 0.7854, 1.1111, -0.8795, 0, -0.0704)
File "C:\Python27\lib\site-packages\matlab\engine\matlabengine.py", line 84, in __call__
_stderr, feval=True).result()
File "C:\Python27\lib\site-packages\matlab\engine\futureresult.py", line 68, in result
return self.__future.result(timeout)
File "C:\Python27\lib\site-packages\matlab\engine\fevalfuture.py", line 82, in result
self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
MatlabExecutionError:
File C:\Program Files\MATLAB\R2017a\toolbox\robot\tr2diff.m, line 38, in tr2diff
File C:\Program Files\MATLAB\R2017a\toolbox\robot\ikine.m, line 98, in ikine
File C:\Users\Jinadasa_J\Desktop\Ishira\CapstoneRobot.m, line 12, in CapstoneRobot
*Integers can only be combined with integers of the same class, or scalar doubles*

Answers (1)

Robert Snoeberger
Robert Snoeberger on 6 Apr 2017
Based on the complaint about integers in the error message, I'm guessing that you need to make everything floats (add decimal point) when you call CapstoneRobot.
t = eng.CapstoneRobot(16.0, 16.0, 16.0, 0.7854, 1.1111, -0.8795, 0.0, -0.0704)
  1 Comment
Arpeet Sojitra
Arpeet Sojitra on 19 Aug 2021
Thank you very much because I am getting similar error but I forgot to add decimal points in my script and I have also four script but I didn't use decimal points but still works. I don' know why??

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!