Routines

Routines offer the executable code for the project in a controller. A routine is similar to a program file or subroutine in a controller.
Each program has a main routine by default. This is the first routine to execute when the controller triggers the associated task and calls the associated program. Use a ladder diagram instruction or structured text, such as JSR, to call other routines. You can create more subroutines. The number of routines per program is dependent on the controller memory.
IMPORTANT: When creating a main routine, it must use the Name
main
. Changing the name of a main routine after creation, removes its designation as a main routine.
TIP: The main routine, current routine, and phase state routine are not valid targets as arguments for a JSR instruction, and do not appear in the list of ladder diagram and structured text routines.
Specify an optional fault routine for each program in each task. The controller executes the optional fault routine if it encounters an instruction-execution fault in any of the routines in the program.
FactoryTalk Design Studio Copilot and routines
Use these prompts with FactoryTalk Design Studio Copilot and routines.
  • Create routine
    Prompts
    :
    • Create structured text routine [routine name].
    • Create routine [routine name] as a ST routine.
    • Create routine [routine name] as an LD routine.
    • Create routine [routine name].
    FactoryTalk Design Studio Copilot response
    : The routine creates. (Sometimes FactoryTalk Design Studio Copilot asks you to specify the routine type and after you respond, creates the routine.)
    TIP: If you do not specify a location, sometimes FactoryTalk Design Studio Copilot follows up with a question asking where you want the routine created.
  • Delete a routine
    Prompt
    : Delete routine [routine name].
    FactoryTalk Design Studio Copilot response
    : The routine deletes.
  • Create code
    Prompts
    :
    • If an empty structured text routine is already created, enter this prompt: Create code in [routine name] for controlling [describe code].
      TIP: Add
      using Rockwell examples
      or
      use examples
      at the end of your code creation prompt to have FactoryTalk Design Studio Copilot use more robust code examples that Rockwell Automation has added to the dataset
    • If a structured text routine with code is already created, asking FactoryTalk Design Studio Copilot to create code in the routine sometimes overwrites the existing code. If you want to add code to an existing routine, use prompts that contain
      Add code for motor control to the end of routine [routine name]
      or
      Insert code on line [line number] of routine [routine name].
    FactoryTalk Design Studio Copilot response
    : The code creates.
  • Change routine types
    Prompts
    :
    • Change [routine name] to structured text.
    • Change [routine name] to ST.
    • Change [routine name] to STX.
      TIP: If code is already present in the routine, the code changes to match the routine type. If you don’t want this type of change, you can add the prompt“Change back” to revert to the earlier type.
    • Change [routine name] to ladder diagram.
    • Change [routine name] to LD.
    • Change [routine name] to different type.
      TIP: FactoryTalk Design Studio Copilot responds by asking you to specify the routine type. Once you respond, the routine changes to that type.
    FactoryTalk Design Studio Copilot response
    : The routine changes types.
  • Understand code
    Prompts
    :
    • For detailed explanation: Explain [routine name].
    • For high level summary: Summarize [routine name].
    • For high level summary with a bullet list of functionalities: Tell me about [routine name].
    • To get FactoryTalk Design Studio Copilot thoughts on a routine: What do you think about [routine name]?
    • To get FactoryTalk Design Studio Copilot thoughts on ways to optimize the code: How would you optimize [routine name]?
    FactoryTalk Design Studio Copilot response
    : FactoryTalk Design Studio Copilot explains the code.
  • Commute Code
    Prompts
    :
    • Add comments to [routine name].
    • Update comments in [routine name].
    FactoryTalk Design Studio Copilot response
    : The code commutes.
TIP: FactoryTalk Design Studio and FactoryTalk Design Studio Copilot do not support editing and modifying code when online with a controller.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal