Machine Code Progression
There are several different ways to plan your machine code. The following is just one option that has evolved over time as it has been applied to several different projects across multiple industries. While the goal is to have the machine running and making products, the code for ‘Auto’ should be the last code written. Planning and coding the basic functionality of the machine will lead to a much better overall system and maintainable machine.
An important design decision needs to be made early on. Will the machine implement multiple modes, and where will the code be that causes movement on the machine? This document is written with the idea that movement will only occur in the Execute state, and therefore multiple modes are used to facilitate this idea. Once a specific function has been completed, then the state machine will transition to Completed and continue to Idle where the Mode can change based on the current condition of the machine.
Overview
-
Planning and gaining a common understanding of the machine operation and terminology. This section should involve all stakeholders.
-
Planning and developing the individual Components based on the items identified in Section I. This section involves programming to control the hardware, or to interact with other external software. All the components for a machine should be reusable and therefore the planning of these components is crucial to ensure their longevity across multiple machines.
-
Planning and developing the Machine Module and Equipment Modules. This is where the components are brought together to make a unique machine. This is where the state machine will be coded to handle multiple modes and how the components will interact with each other.
Planning
Identify Equipment Modules and Components
-
Break the machine into mechanically dependent sections. If parts of the machine are physically connected, then they will most likely be required to follow the same state machine and therefore be in the same Equipment Module.
-
Identify the Components that exist within each Equipment Module.
-
Identify Components that are optional add-ons and isolate these into their own Equipment Modules to create modularity.
-
Identify and list the Components (Cylinders, Servos, Valves, Temperature Controllers, etc.)
-
From the full list, create a list of unique Components and consider which components will be building blocks for other components.
-
Identify the Modes of Operation that will be needed for the Machine.
Default modes within PackML Other possible modes Invalid Home Production Pre-Positioning Maintenance Pre-Production Manual Post-Production Setup Clean In Place Dry Cycle Teach -
Once the required Modes are identified, list the Equipment Modules and Components that will make use of each mode and a brief explanation of what functionality is expected.
Mode Equipment Module Components Functionality ALL Machine Module Stack Light Indicate Current Mode or Machine Error state Production Unwind Solenoid Brake Energize / De-energize Production Unwind Cylinder Clamp Extend Manual Unwind Cylinder Clamp Extend / Retract
State Machine planning
The Machine Module will control each of the Equipment Modules by sending commands and monitoring their statuses. The sequential operation of the overall machine can therefore be defined within the Execute method of the Machine Module.
-
Create a sequence of operations for each Equipment Module under the Machine Module.
This will also be where the Machine Module handles the interaction between the Equipment Modules to prevent mechanical collisions, and the transfer of parts and data from one EM to the next.
-
Within each Equipment Module create a sequence of operations that will handle commands from the Machine Module and control the components of the Equipment Module.
-
Define any homing or other movement priorities that will need to be managed.
Warning
Are there any possible mechanical collisions?
Consider Servos or Cylinders that must be moved to a specific position or range before another item can be moved. -
Define Critical alarms within components that will immediately stop the entire machine
a. Estops, Door switches, power failure, etc. -
Define Critical alarms within components that will immediately stop just an Equipment Module.
-
Define Errors that will immediately stop the entire machine
a. Drive Errors
b. Hardware errors -
Define Errors that will immediately stop just an Equipment Module
- Define Warnings for other items such as temperature and tank level tolerances.
- Decide if the default configuration for Alarm Responses will suit your needs, if not then define what will be needed. Alarm Responses can be customized for each Module and Component.
Components
In this you will be planning for how to interact with the components using interfaces. Using the functionality descriptions above create common interfaces for command and status (Extend/Retract, Energize/De-energize, Home/Homed, Reset/Ready, Start, Stop, Running, etc.).
Identify what commands and statuses are common among components and consider how they can be grouped together.
Assume that a component will have multiple interfaces, some that are shared among most components, some that are shared with only a small number of components, and likely one that is unique to a component. The important part is to identify the commands and statuses that a component will have and place them into an interface. This will encourage the use of programming to the interface, create consistency across variable names, and create reusability and modularity.
All components should be created in a way that allows them to be used without the SPT Framework and should be able to be declared in MAIN for individual testing and validation purposes.
-
Define the methods and properties of the Components. The commands will be the methods that can be called to control the component, and the statuses will be the properties that can be read to determine the current state of the component.
Cylinder 1 2 3
Extend / Extended Retract / Retracted Home / Homed
Servo Basic 1 2 3 4 5 6 7 8
Move to Position Move at Velocity Home / Homed Jog in Direction Move to Position Move to Enumerated Positions Move at Velocity Move at Enumerated Velocity
Servo Advanced 1 2 3
Reference (Some axes require a valid reference before any movement) Discover Hardware Limits Discover Software Limits
Valve 1 2
Open / Opened Close / Closed
Temp Controller 1 2 3 4 5 6
Basic: Change setpoint Move to set point Advanced: Discover Tuning Parameters (Auto-Tune)
-
Identify and create the Enumerated positions or values for each component
-
Identify and create the Machine Parameters for each component
-
Identify and create a Structure for the recipe values of each component
-
If hardware is available, then configure the hardware parameters and add the necessary code for the manual controls to send commands to the hardware and monitor for feedback.
Tip
Keeping the hardware layer separate from the control layer will allow for more flexibility and modularity. For example, not all servos use the same internal command bit to jog forward; therefore, abstracting the Command/Status layer from the hardware control layer allows the lower layer to be replaced when the hardware changes, but the Command/Status layer can remain the same. The downside to this is that the extra layers create more complexity when troubleshooting.
-
Create a tmc file for each Component type (Cylinder, Servo, etc)
Start with the basic 5 Severity levels
Add specific alarms as needed
Add hardware errors, specifically, the ones you encounter during startup.
Modules
Once the list of components is completed, move up to the Equipment Modules and repeat the process for creating their interfaces.
Identify what commands and statuses are common among Equipment Modules.
Similar to the Components, an Equipment Module will likely have multiple interfaces, some that are shared among other Equipment Modules, and likely one that is unique. The important part is to identify the commands and statuses that an Equipment Module will have and place them into an interface. This will encourage the use of programming to the interface, create consistency across variable names, and create reusability and modularity.
-
Define Equipment Modules and the Components they will contain.
-
Create the Function Blocks that will be the MM and EMs.
- Instantiate the Function Blocks along with their Components.
-
Implement the basic CyclicLogic and Initialize methods for each.
In MAIN, add code for Mode and State control or use the Visu from the SPT Framework library. -
Implement Manual Mode for the Components basic functionality. Most of the machine process should be able to be commanded in Manual. Add the necessary error detection and recovery
-
Implement Maintenance Mode for the Components advanced functionality.
Note
Consider the commands that could cause damage to the machine and need to be done with extreme caution.
1 2 3
Moving into collision areas Moving beyond software or hardware limits Opening certain valves
-
Implement Home mode
Create the sequence across all EMs that will place the components in a known positionImplement priorities if necessary to avoid any possible collisions
Reference all axes and place them in a defined position
Extend or retract all cylinders
Open or close all valves -
Implement the ‘Pre’ modes These modes are used for turning on heaters and placing axes or cylinders into recipe positions in preparation for ‘Production Mode’
Note
The use of a Pre-Production mode can be used to place the Machine Module in a mode to control the Equipment Modules and walk them through their various ‘Pre’ modes. As there is no need for an Equipment Module of axes to wait for an Equipment Module of heaters to preheat, each EM can have its own mode that is controlled by the Machine Module.