Main Content

writeAsFunction

Create rigidBodyTree code generating function

Since R2021a

    Description

    writeAsFunction(robot,filename) creates a function file that constructs the rigidBodyTree object. The created function supports code generation.

    example

    Examples

    collapse all

    Load a robot model as a rigidBodyTree object.

    robot = loadrobot("kinovaGen3")
    robot = 
      rigidBodyTree with properties:
    
         NumBodies: 8
            Bodies: {[1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]}
              Base: [1x1 rigidBody]
         BodyNames: {'Shoulder_Link'  'HalfArm1_Link'  'HalfArm2_Link'  'ForeArm_Link'  'Wrist1_Link'  'Wrist2_Link'  'Bracelet_Link'  'EndEffector_Link'}
          BaseName: 'base_link'
           Gravity: [0 0 0]
        DataFormat: 'struct'
    
    

    Show the robot model in a figure.

    show(robot);

    Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 25 objects of type patch, line. These objects represent base_link, Shoulder_Link, HalfArm1_Link, HalfArm2_Link, ForeArm_Link, Wrist1_Link, Wrist2_Link, Bracelet_Link, EndEffector_Link, Shoulder_Link_mesh, HalfArm1_Link_mesh, HalfArm2_Link_mesh, ForeArm_Link_mesh, Wrist1_Link_mesh, Wrist2_Link_mesh, Bracelet_Link_mesh, base_link_mesh.

    Create a code generating function that constructs the rigidBodyTree object.

    writeAsFunction(robot,'KG3Codegen')

    Construct the robot model using the generated function.

    rbt = KG3Codegen
    rbt = 
      rigidBodyTree with properties:
    
         NumBodies: 8
            Bodies: {[1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]  [1x1 rigidBody]}
              Base: [1x1 rigidBody]
         BodyNames: {'Shoulder_Link'  'HalfArm1_Link'  'HalfArm2_Link'  'ForeArm_Link'  'Wrist1_Link'  'Wrist2_Link'  'Bracelet_Link'  'EndEffector_Link'}
          BaseName: 'base_link'
           Gravity: [0 0 0]
        DataFormat: 'struct'
    
    

    Show the robot model in a figure.

    show(rbt);

    Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 17 objects of type patch, line. These objects represent base_link, Shoulder_Link, HalfArm1_Link, HalfArm2_Link, ForeArm_Link, Wrist1_Link, Wrist2_Link, Bracelet_Link, EndEffector_Link.

    Input Arguments

    collapse all

    Robot model, specified as a rigidBodyTree object.

    Name of the function file, specified as a string scalar or character vector. The name must be a valid MATLAB name (must start with a letter and contain only letters, numbers and underscores).

    Example: "iiwa14Codegen"

    Data Types: char | string

    Version History

    Introduced in R2021a

    See Also

    Functions

    Objects