# Peter Corke Robotics Matlab Toolbox Jacobian in Simulink

I am working on getting the Peter Corke Robotics Toolbox for Matlab connected to a Panda robot via Simulink. The problem I am encountering is the fact that the variables created by the Peter Corke Toolbox are not recognized by Simulink. I want to feed a function block with joint angles and end-effector velocities and then have the block output the joint velocities. This is done via the following multiplication: $$\dot{q}=J(q)^{\dagger} \dot{p}$$. Executing this multiplication in Matlab is easy and straightfoward using the toolbox. You can get $$J$$ using robot.jacobe(q) and then take the pseudo-inverse and multiply this with the end-effector velocities $$\dot{p}$$.

The problem arises as soon as I try to execute this same multiplication in Simulink. The function block along with its inputs and outputs is shown below:

The function block contains the same script as the m-file that correctly outputs the joint velocities in Matlab. When I build the Simulink model, I get a multitude of error messages. Caused by the fact that Simulink does not recognize the SerialLink object (shown below) created by the Peter Corke Robotics Toolbox.

I've tried converting everything to a struct but then the toolbox's Jacobian function no longer works (unsurprisingly). Is there anybody that has experience with using SerialLink object in Simulink or is there a simple way to get the robot data into Simulink?

Thanks a lot in advance, for any help and or tips.

I haven't used the Robotics Toolbox before, but it seems like probably Simulink just doesn't know how to package the panda into a signal it can move over one of the Simulink wires. Simulink can do things with signals in the wire like gains, derivatives, etc., but it has to know something about those signals.

The easy solution, I think, would be to just load the panda data inside your Matlab block, using whatever technique you're already using to load it in the Matlab scripts. Here's a Mathworks post describing loading variables into the Matlab workspace, which might be useful because,

Simulink blocks like the Constant block read variables from the base workspace.

Their post is trying to load data in Matlab then start Simulink, but you're kind of the opposite in that you're running Simulink and trying to load something. However, I think you could probably use the same technique to load the data if it doesn't exist. For example:

if(exist('variableYouNeed', 'var') == false)
evalin('base', 'yourMatFile.mat');
end

You could selectively load different robots by passing a constant that you use inside your Matlab code (enum/switch) to selectively load different files.

• I get the following notification from Simulink: Function 'evalin' not supported for code generation. Oct 7, 2021 at 11:58
• @user463102 Ah then you'll have to either load the mat file before running the Simulink sim or it looks like you could mark the function as extrinsic to use it. Here's a SO post on doing the same. Oct 7, 2021 at 14:09