Fix for privsubasgn error

212 views
Skip to first unread message

Alexander Frericks

unread,
Jan 4, 2017, 7:27:08 AM1/4/17
to Robotics & Machine Vision Toolboxes
Hello together,

using the RTB with MATLAB versions newer than 2014b, I encountered the following error in the symbolic code generation functions:

Assignment has more non-singleton rhs dimensions than non-singleton subscripts

Error in sym/privsubsasgn (line 1040)
                L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);


The error can be reproduced with the following minimal code example:

%Clean up
clear
;

% Load simple robot model
mdl_planar2
;

% Code Generator (disable Simulink block generation to speed-up)
CGen = CodeGenerator( p2 );
CGen.genslblock = false;

%Generate symbolic equations
CGen.geneverything;

I think I tracked the error down to the friction() function in the Link class:

 
       function  tau = friction(l, qd)

           
% (...)
                           
            tau
= l.B * abs(l.G) * qd;
           
           
if issym(l)
               
%-----------Original code:-----------------
%                 tau = tau + l.Tc;
               
               
%--------------Bugfix:---------------------
                tau
= tau +   0.5 * ( sign(qd) + 1 ) * l.Tc(1) + ...
                             
0.5 * ( sign(qd) - 1 ) * l.Tc(2);
            elseif qd
> 0
                tau
= tau + l.Tc(1);
            elseif qd
< 0
                tau
= tau + l.Tc(2);
           
end
            tau
= -abs(l.G) * tau;     % friction opposes motion
       
end % friction()


In the original code, the vector Tc, which contains the coulomb friction forces for both directions, was added to the variable tau, which is a scalar. Replacing the line with the fix above should solve the problem and preserve the originally desired behaviour.

Greetings
Alex





Peter Corke

unread,
Apr 30, 2017, 2:49:49 AM4/30/17
to Robotics & Machine Vision Toolboxes
Belated reply, but this has been fixed in RTB10, out soon

joval...@gmail.com

unread,
May 6, 2017, 6:57:37 PM5/6/17
to Robotics & Machine Vision Toolboxes
I tried this fix and it didn't work for me. 
Is there something else we can do about this problem in older versions of this toolbox? 

joval...@gmail.com

unread,
May 6, 2017, 6:57:37 PM5/6/17
to Robotics & Machine Vision Toolboxes
Never mind, I fixed my error. 
I applied the bug fix to the standalone function friction(), rather than the one in the Link() class!


On Sunday, April 30, 2017 at 2:49:49 AM UTC-4, Peter Corke wrote:

Peter Corke

unread,
May 6, 2017, 7:08:31 PM5/6/17
to Robotics & Machine Vision Toolboxes, joval...@gmail.com
There shouldn't be a standalone version of friction!  Where is it and what version are you using?
Message has been deleted

omgicantfindaname0o

unread,
Jun 22, 2018, 1:40:34 PM6/22/18
to Robotics & Machine Vision Toolboxes
There is a standalone version that opens when you type
edit friction
that is located in rvctools\contrib\arte\lib\

It states some weird stuff that got me so confused.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Torque = FRICTION(ROBOT, QD, j)
%
%  Computes torque based on viscous friction and Coulomb friction for the
%  joint j.
%
%  The torque is computed as:
%  tau = G^2*B*qd + abs(Tc)*abs(G);
%
% The viscous friction parameter for each joint j must be stored in the
% variable robot.motors.Viscous, whereas the vector robot.motors.Coulomb
% positive or negative parameters of the Coulomb friction
%
%   Author: Arturo Gil. Universidad Miguel Hernandez de Elche.
%   email: arturo.gil@umh.es date:   26/06/2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Copyright (C) 2012, by Arturo Gil Aparicio
%
% This file is part of ARTE (A Robotics Toolbox for Education).
%
% ARTE is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% ARTE is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with ARTE.  If not, see <http://www.gnu.org/licenses/>.
function  torque = friction(robot, qd, j)

%torque due to viscous friction
%torque = robot.motors.G(j)^2*robot.motors.Viscous(j)*qd(j);
torque
= robot.motors.G(j)*robot.motors.Viscous(j)*qd(j);

%Add torque due to Coulomb friction
if qd(j) > 0
    torque
= torque + abs(robot.motors.G(j))*robot.motors.Coulomb(j,1);  
elseif qd
(j) < 0
    torque
= torque + abs(robot.motors.G(j))*robot.motors.Coulomb(j,2);
end


I hope this is the only way the toolbox calculates friction:

function  tau = friction(l, qd)
%Link.friction Joint friction force
%
% F = L.friction(QD) is the joint friction force/torque for link velocity QD
    tau
= 0.0;

    tau
= l.B * qd;


   
if qd > 0
        tau
= tau + l.Tc(1);
    elseif qd
< 0
        tau
= tau + l.Tc(2);
   
end

    tau
= -tau;     % friction opposes motion
endfunction
% friction()


Cheers
Sebastian

Peter Corke

unread,
Jul 5, 2018, 9:24:06 PM7/5/18
to Robotics & Machine Vision Toolboxes
Interesting, which version of RTB are you using? I'm not seeing this issue with the latest version of RTB.

 The one that gets used in RTB, in rne() for example, is a method of the SerialLink class so there shouldn't be any confusion at run time.

You can guarantee to edit this method by specifying the class

>> edit SerialLink.friction

peter

Sebastian

unread,
Jul 6, 2018, 10:54:45 AM7/6/18
to Robotics & Machine Vision Toolboxes
I indeed do not have the latest version of the Toolbox (release 9.10 of the Toolbox and 1.1 of ARTE). I'll check whether or not this issue persists with the new version ;)

However, in your GitHub repository the issue persists.
while ne.c (https://github.com/petercorke/robotics-toolbox-matlab/blob/2ddefed1a5b90c7c220e9c5ce7ec2501278c4325/mex/ne.c) calculates friction as t += l->G * l->G * l->B * qd[j*stride]
I'm in no way proficient in C, but this looks like B * G * qd vs. G² * B * qd.
I think, in physics you just use G to calculate torque transmission, so why use G² here?

Peter Corke

unread,
Jul 6, 2018, 11:57:02 AM7/6/18
to robotics...@googlegroups.com
In RTB10 I include a subset of ARTE with Arturo’s permission.  That subset includes only data files, no code.

You could safely delete all executable code from your ARTE folder if you are just using RTB.

peter

--
You received this message because you are subscribed to a topic in the Google Groups "Robotics & Machine Vision Toolboxes" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robotics-tool-box/bt12EoKiZFc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to robotics-tool-...@googlegroups.com.
To post to this group, send email to robotics...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotics-tool-box.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages