cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Factory Line Automation Part 3

No ratings

 

Step 3: Creating Machine Processes

 

Having data and properties without moving parts would be useless. We already setup services on how to perform an inspection in the last guide. This time around, let's form processes to create our products and generate any alerts whenever we've finished production. We won't show too much into our recipe (it's a family secret), but we will highlight some concepts to help with making our machine process smoother.

We won't go into creating an SMT line. For a complete guide on how to create such an application you can view our Monitor an SMT Assembly Line guide.

 

Events and Subscriptions

 

Let's create events for the cook time being done and a subscriptions on how to handle these scenarios.

 

  1. Open the Fizos.BrautsMachine.ThingTemplate template and go to the Events tab.
  2. Click the + Add button and create the below alerts.

NameData ShapeDescription
CookCompletedAlertEventThis alert is fired when the machine has completed a batch of our product
TemperatureReachedAlertEventThis alert is fired when the machine has reached the desired temperature.

 

3. Save these changes and replicate them with the Fizos.SausageMachine.ThingTemplate template.

We now have alerts for the machines (alerts on properties and custom alerts). We can create subscriptions on the individual machines that will later inherit these alerts. One way to have a standard amongst these machines is to create a service in the template that will be called from subscriptions.

 

Let's create the simple services from now, and later, we will call these services from subscriptions. We will also use Schedules initiate the overall process. This can be a daily process, a timed process, or a process based on alerts and subscriptions. To keep this guide simple, we'll make this a process that runs every 3 hours. Create the below services in each of the Fizos.BrautsMachine.ThingTemplate and Fizos.SausageMachine.ThingTemplate templates:
  

 NameInputReturnTypeOverrideAsyncDescription
StartCookingProcessN/ANothingYesYesStart overall product cooking process.Triggedby schedule.
StartCookingIngredientsN/ANothingYesYesStart cooking the ingredients for the product.Triggedby subscription.

 

  1. Add the following code for the StartCookingProcess service:
// Mix our family secret recipe 
// Add in meats 
// Add heat 
me.TemperatureReached({ 
     aackTimestamp: new Date(), 
     alertType: "Completed", 
     ackBy: "CookUser", 
     ack: true, 
     name: "TemperatureAlert", 
     sourceProperty: "Service", 
     description: "Optimal cooking temperature reached", 
     message: "The desired cooking temperature has been reached. Begin next process.", 
     priority: 1 
}); 
// Perform top secret cooking techniques 

 

2. Add the following code for the StartCookingIngredients service:

// Temperature has already been reached 

if(true) { 
      // IF COOK COMPLETED 
      me.CookCompleted({ 
           ackTimestamp: new Date(), 
           alertType: "Information", 
           ackBy: "CookUser", 
           ack: true, 
           name: "CookingAlert", 
           sourceProperty: "Service", 
           description: "Cooking process has completed", 
           message: "The cooking time has completed. Move to next machine.", 
           priority: 1 
      }); 
} else { 
//ELSE IF COOKING FAILED OR HALTED 
      me.CookCompleted({ 
           ackTimestamp: new Date(), 
           alertType: "Exception", 
           ackBy: "CookUser", 
           ack: true, 
           name: "CookingAlert", 
           sourceProperty: "Service", 
           description: "Cooking process has failed", 
           message: "The cooking process has stopped. See logs for failure cause.", 
           priority: 1 
      }); 
} 

 

Let's keep in mind, these services will be triggered by by a schedule or a subscription to an alert. There will be no manual processed performed here. We also allowed for these services to be overridden, in order to allow more customization for machines that might need to be treated differently. These services are also not on the main machine templates, which allows us to create templates for machines that might have a different role in the process, ie, packaging or freeze drying.

 

 

 

Step 4: Automating Processes

 

Let's create the schedule that will start the cooking process.

  1. In the ThingWorx Composer, click the + New in the top left of the screen.

    select_new.png

     

  2. Select Schedules in the dropdown.

    create_new_scheduler.png

 

3. Name the new Schedule Fizos.MachineCooking.Schedule and set the Project (ie, PTCDefaultProject).

4. For the Run As User field, select the Fizos.Machine.User that was provided in the download.

5. Click Save and your entity should match the below configuration.

new_machine_schedule.png

 

 

6. For the Schedule field, set it to 0 0 0/3 * * ?. This will run the process every 3 hours.

7. Switch to the Subscriptions tab and add a new subscription.

8. Name this new subscription StartCooking and select ScheduledEvent as the event input.

new_factory_subscription.png

 

9. Add the following code to the source section:

 

var index = 0; 
var brauts = Resources["SearchFunctions"].SearchThingsByTemplate({ 
          thingTemplate: "Fizos.BrautsMachine.ThingTemplate" 
}); 
var sausage = Resources["SearchFunctions"].SearchThingsByTemplate({ 
          thingTemplate: "Fizos.SausageMachine.ThingTemplate" 
}); 

for(index = 0; index < brauts.rows.length; index++) { 
          brauts.StartCookingProcess(); 
} 

for(index = 0; index < brauts.rows.length; index++) { 
          sausage.StartCookingProcess(); 
} 

// This will begin the process to start each machines cooking process. 
// The process itself will then be ran by alerts, subscriptions, and services 

 

So far the process will go as the following:

  1. A scheduler will search for all Things that inherit from the Fizos.BrautsMachine.ThingTemplate and Fizos.SausageMachine.ThingTemplate templates.
  2. Each list of these entities will have it's StartCookingProcess service called.
  3. When a temperature value is reached inside of the StartCookingProcess service, the TemperatureReached alert will be triggered.
  4. A subscription waiting for this event at the Thing level (which we create in the next section), will call the StartCookingIngredients service.
  5. This StartCookingIngredients service will finish the cooking part of the process and trigger a CookCompleted alert with a status update.
  6. A subscription waiting for this event at the Thing level (which we create in the next section), can call for another machine to take over the process.

 

We now have our moving parts. Let's create some examples to see how it can unfold.

 

 

 

Step 5: Handling Cooking Machines

 

We have many of our main features compeleted. Now we need to handle situations where our machine status needs to be a part of how we handle the cooking process. While much of this work can be handled in a remote process using one of our SDKs or extensions, our events and subscriptions can be a great method to do this also.

 

Creating Cooking Entities

 

  1. In the ThingWorx Composer, click the + New in the top left of the screen.

    select_new.png

     

  2. Select Thing in the dropdown.

    create_new_thing.png

     

  3. Set the Project (ie, PTCDefaultProject) and in the name field, enter Fizos.BrautsMachine.M02X35.

  4. In the Base Thing Template field, enter Fizos.BrautsMachine.ThingTemplate.

  5. Click Save.

    new_machine1.png

 

6. In the ThingWorx Composer, click the + New in the top left of the screen.

select_new.png

 

 

7. Select Thing in the dropdown.

create_new_thing.png

 

 

8. In the name field, enter Fizos.SausageMachine.KGYX20.

9. In the Base Thing Template field, enter Fizos.SausageMachine.ThingTemplate.

10, Click Save.

new_machine2.png

 

 

Creating Cooking Subscriptions

 

These steps will need to be in both of the entities we just created.

 

  1. Switch to the Subscriptions tab and add a new subscription.

  2. Name this new subscription TemperatureReady and select TemperatureReached as the event input.

    machine_temp_subscription.png

 

3. Add the following code to the source section:

//The temperature is high enough. Start cooking

me.StartCookingIngredients();

 

You now have a system (when enabled) will run every three hours. It will start our secret cooking process (that can be added in the service or created remotely).

 

To make things more fun. Add some logging or fun code to see how this works step by step.

 

To make things more realistic to a real world scenario, add subscriptions for our property alerts on the status or state properties.

 

 

 

Step 6: Next Steps

 

Congratulations! You've successfully completed the Factory Line Automation guide.

In this guide, you learned how to:

 

  • Create automated machine processes
  • Use services, alerts, and subscriptions to handle processes without human interaction
  • Integrating complex logic with straight forward step by step systems

 

The next guide in the Complex and Automatic Food and Beverage Systems learning path is Automated Distribution and Logistics

 

Learn More

 

We recommend the following resources to continue your learning experience:

 

 Capability     Guide
BuildThingWorx Solutions in Food Industry
BuildDesign Your Data Model
BuildImplement Services, Events, and Subscriptions

 

Additional Resources

 

If you have questions, issues, or need additional information, refer to:

 

 Resource       Link
CommunityDeveloper Community Forum

 

Version history
Last update:
‎Nov 16, 2022 03:57 PM
Updated by:
Labels (1)
Contributors