Main Content

writeAsFunction

Create rigidBodyTree code generating function

    Description

    example

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

    Examples

    collapse all

    Load a robot model as a rigidBodyTree object.

    robot = loadrobot("kinovaGen3")
    robot = 
      rigidBodyTree with properties:
    
         NumBodies: 8
            Bodies: {[1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]}
              Base: [1×1 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);

    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: {[1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]  [1×1 rigidBody]}
              Base: [1×1 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);

    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

    See Also

    Functions

    Objects

    Introduced in R2021a