M-File Help: CodeGenerator | View code for CodeGenerator |
Class for code generation
Objects of the CodeGenerator class automatcally generate robot specific code, as either M-functions or real-time capable SerialLink blocks.
The various methods return symbolic expressions for robot kinematic and dynamic functions, and optionally support side effects such as:
% load robot model mdl_twolink
cg = CodeGenerator(twolink); cg.geneverything();
% a new class has been automatically generated in the robot directory. addpath robot
tl = @robot(); % this class is a subclass of SerialLink, and thus polymorphic with % SerialLink but its methods have been overloaded with robot-specific code, % for example T = tl.fkine([0.2 0.3]); % uses concise symbolic expressions rather than the generalized A-matrix % approach
% The Simulink block library containing robot-specific blocks can be % opened by open robot/robotslib.slx % and the blocks dragged into your own models.
gencoriolis | generate Coriolis/centripetal code |
genfdyn | generate forward dynamics code |
genfkine | generate forward kinematics code |
genfriction | generate joint frictionc code |
gengravload | generarte gravity load code |
geninertia | general inertia matrix code |
geninvdyn | generate forward dynamics code |
genjacobian | generate Jacobian code |
geneverything | generate code for all of the above |
basepath | basic working directory of the code generator |
robjpath | subdirectory for specialized MATLAB functions |
sympath | subdirectory for symbolic expressions |
slib | filename of the Simulink library |
slibpath | subdirectory for the Simulink library |
verbose | print code generation progress on console (logical) |
saveresult | save symbolic expressions to .mat-files (logical) |
logfile | print modeling progress to specified text file (string) |
genmfun | generate executable M-functions (logical) |
genslblock | generate Embedded MATLAB Function blocks (logical) |
rob | SerialLink object to generate code for (1x1). |
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
Construct a code generator object
cGen = CodeGenerator(rob) is a code generator object for the SerialLink object rob.
cGen = CodeGenerator(rob, options) as above but with options described below.
The following option sets can be passed as an optional parameter:
'default' | set the options: verbose, saveResult, genMFun, genSLBlock |
'debug' | set the options: verbose, saveResult, genMFun, genSLBlock and create a logfile named 'robModel.log' in the working directory |
'silent' | set the options: saveResult, genMFun, genSLBlock |
'disk' | set the options: verbose, saveResult |
'workspace' | set the option: verbose; just outputs symbolic expressions to workspace |
'mfun' | set the options: verbose, saveResult, genMFun |
'slblock' | set the options: verbose, saveResult, genSLBlock |
If 'optionSet' is ommitted, then 'default' is used. The options control the code generation and user information:
'verbose' | write code generation progress to command window |
'saveResult | save results to hard disk (always enabled, when genMFun and genSLBlock are set) |
'logFile', logfile | write code generation progress to specified logfile |
'genMFun' | generate robot specific m-functions |
'genSLBlock' | generate real-time capable robot specific Simulink blocks |
Any option may also be modified individually as optional parameter value pairs.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
Adds generated code to search path
cGen.addpath() adds the generated m-functions and block library to the MATLAB function search path.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
Generate code for Coriolis force
coriolis = cGen.gencoriolis() is a symbolic matrix (NxN) of centrifugal and Coriolis forces/torques.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninertia, CodeGenerator.genfkine
Generate code for forward dynamics
Iqdd = cGen.genfdyn() is a symbolic vector (1xN) of joint inertial reaction forces/torques.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninertia, CodeGenerator.genfkine
Generate code for forward kinematics
T = cGen.genfkine() generates a symbolic homogeneous transform matrix (4x4) representing the pose of the robot end-effector in terms of the symbolic joint coordinates q1, q2, ...
[T, allt] = cGen.genfkine() as above but also generates symbolic homogeneous transform matrices (4x4xN) for the poses of the individual robot joints.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninvdyn, CodeGenerator.genjacobian
Generate code for joint friction
f = cGen.genfriction() is the symbolic vector (1xN) of joint friction forces.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninvdyn, CodeGenerator.genfdyn
Generate code for gravitational load
g = cGen.gengravload() is a symbolic vector (1xN) of joint load forces/torques due to gravity.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
codegenerator, CodeGenerator.geninvdyn, CodeGenerator.genfdyn
Generate code for inertia matrix
i = cGen.geninertia() is the symbolic robot inertia matrix (NxN).
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninvdyn, CodeGenerator.genfdyn
Generate code for inverse dynamics
tau = cGen.geninvdyn() is the symbolic vector (1xN) of joint forces/torques.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.genfdyn, CodeGenerator.genfkine
Generate code for robot Jacobians
j0 = cGen.genjacobian() is the symbolic expression for the Jacobian matrix (6xN) expressed in the base coordinate frame.
[j0, Jn] = cGen.genjacobian() as above but also returns the symbolic expression for the Jacobian matrix (6xN) expressed in the end-effector frame.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.genfkine
Generate M-functions for Coriolis matrix
cGen.genmfuncoriolis() generates a robot-specific M-function to compute the Coriolis matrix.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.gencoriolis, CodeGenerator.geninertia
Generate M-function for forward dynamics
cGen.genmfunfdyn() generates a robot-specific M-function to compute the forward dynamics.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninvdyn
Generate M-function for forward kinematics
cGen.genmfunfkine() generates a robot-specific M-function to compute forward kinematics.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.genjacobian
Generate M-function for joint friction
cGen.genmfunfriction() generates a robot-specific M-function to compute joint friction.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.gengravload
Generate M-functions for gravitational load
cGen.genmfungravload() generates a robot-specific M-function to compute gravitation load forces and torques.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninertia
Generate M-function for robot inertia matrix
cGen.genmfuninertia() generates a robot-specific M-function to compute robot inertia matrix.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.gencoriolis
Generate M-functions for inverse dynamics
cGen.genmfuninvdyn() generates a robot-specific M-function to compute inverse dynamics.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninvdyn
Generate M-functions for robot Jacobian
cGen.genmfunjacobian() generates a robot-specific M-function to compute robot Jacobian.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.gencoriolis
Generat Simulink block for Coriolis matrix
cGen.genslblockcoriolis() generates a robot-specific Simulink block to compute Coriolis/centripetal matrix.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.gencoriolis
Generate Simulink block for forward dynamics
cGen.genslblockfdyn() generates a robot-specific Simulink block to compute forward dynamics.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.genfdyn
Generate Simulink block for forward kinematics
cGen.genslblockfkine() generates a robot-specific Simulink block to compute forward kinematics.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.genfkine
Generate Simulink block for joint friction
cGen.genslblockfriction() generates a robot-specific Simulink block to compute the joint friction model.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.genfriction
Generate Simulink block for gravitational load
cGen.genslblockgravload() generates a robot-specific Simulink block to compute gravitational load.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
See also CodeGenerator.CodeGenerator, CodeGenerator.gengravload
Generate Simulink block for inertia matrix
cGen.genslbgenslblockinertia() generates a robot-specific Simulink block to compute robot inertia matrix.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninertia
Generate Simulink block for inverse dynamics
cGen.genslblockinvdyn() generates a robot-specific Simulink block to compute inverse dynamics.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.geninvdyn
Generate Simulink block for robot Jacobians
cGen.genslblockjacobian() generates a robot-specific Simulink block to compute robot Jacobians (world and tool frame).
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
CodeGenerator.CodeGenerator, CodeGenerator.genjacobian
Print CodeGenerator logs.
count = CGen.logmsg( FORMAT, A, ...) is the number of characters written to the CGen.logfile. For the additional arguments see fprintf.
Matlab ships with a function for writing formatted strings into a text file or to the console (fprintf). The function works with single target identifiers (file, console, string). This function uses the same syntax as for the fprintf function to output log messages to either the Matlab console, a log file or both.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany http://www.rst.e-technik.tu-dortmund.de
multidfprintf, fprintf, sprintf
Cleanup generated files
cGen.purge() deletes all generated files, first displays a question dialog to make sure the user really wants to delete all generated files.
cGen.purge(1) as above but skips the question dialog.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
Removes generated code from search path
cGen.rmpath() removes generated m-functions and block library from the MATLAB function search path.
Joern Malzahn 2012 RST, Technische Universitaet Dortmund, Germany. http://www.rst.e-technik.tu-dortmund.de
© 1990-2012 Peter Corke.