I need to convert these parallel robot algorithms to Julia from Matlab, but I cannot get the forward kinematics to work

It wasn’t requested and it probably is better not to make stylistic changes until you have working code and good tests, but if you are looking later to make your code more idiomatically Julia, here is a quick translation of your Rot function. The biggest point here is that you don’t need to define and name things that you are just going to return later.

A secondary point is the use of a markdown string to document the function. By using a string here instead of comments, a user can later use ?Rot to get the doc on the function.

Finally, I would just use the variable name “axis” to make the code more clear. Related to this, I removed the type declaration from axis so that somebody can call this function with other things that might be roughly comparable to a string. That allows, for example, Rot(:x, 34). A similar thing applies to the angle itself since there might be things other than numbers that work here. All you really care about is that θ can be used as an argument to deg2rad. The user of Rot might extend deg2rad somehow and it would be cool if your function would be extended in the same moment.

md"""
This function calculates the rotation matrix for the given angle and specified axis of rotation. The input
should be some angle in degrees. r,p,y coordinates should be input as u,v,w or equivalently x,y,z.
"""
function Rot(axis, θ)
    θ = deg2rad(θ)
    if axis == "x" || String(axis) == "x"
        return [1 0 0; 0 cos(θ) -sin(θ); 0 sin(θ) cos(θ)]
    elseif axis == "y" || String(axis) == "y"
        return [cos(θ) 0 sin(θ); 0 1 0; -sin(θ) 0 cos(θ)]
    else 
        return [cos(θ) -sin(θ) 0; sin(θ) cos(θ) 0; 0 0 1]
    end
end

[/quote]

1 Like