Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

120 Commits
 
 
 
 
 
 

Repository files navigation

UR3-Analytics

Objective: Demonstrate the usage of Thingworx Analytics by using it to determine the weight of an object that a UR3 robot is holding. In this exercise, you will perform:

  1. Setup - Download and configure files and devices
  2. Data Collection - Collect joint amperage data from the UR3
  3. Modeling - Create a machine learning model
  4. Deployment - Perform automated real time predicitons

map

robot

Setup

Getting Started

To do this exercise, you need:

  1. Thingworx Foundation
  2. Thingworx Analytics
  3. Thingworx Kepware
  4. A UR robot
  5. A USB drive

Th files we will be using are located in the main.

This guide assumes basic Universal robot operation knowledge.

Import UR3-project to Thingworx

Navigate to your Thingworx composer on your browser. Click Import/Export and and browse for the file, UR3-project.twx on your hardrive.

After you select you file, click Import.

This file contains the UR3-analytics project. Navigate to the project in in composer by searching for it in the search bar.

search-thingworx

Confirm that each of the entities shown in the image below are present.

project-entities


Kepware Configuration

With Kepware installed, open the file called UR3_kepwareConfig.opf. This configuration file is setup to communicate with the UR3 but you will need to change a few things. We will find each item and then show you how add them to the Kepware configuration.

The Thingworx Host address and port number

The Thingworx host address and port is the URL used to reach the server. An example of a URL is shown below.

http://servername:PORT/Thingworx/Composer

In the case above, the host is servername and the port is PORT. (If a port is not shown in the URL, the default is 443.)

The application key

You must create an application key to give the Kepware server authorization to communicate with the Thingworx server. Navigate to your Thingworx composer on your browser.

  1. Select New and type 'app' and select application key

Create Appkey

  1. Fill out the app key general information
    A. Name the app key UR3-appkey
    B. Set the project to UR3-Analytics
    C. Under User Name Reference, select your own Thingworx username.

Name Appkey

  1. Set the expiration date for a future date.

appkey_expiration

  1. Select Save and the application key will appear under Key ID. Select the copy button to the right of the Key ID to copy it to the clipboard.

copy-key

The device ID or ip address

Connect your UR3 controller to your local network with an ethernet cable. On the UR3 teaching pendant, find the ip address of your UR3 by selecting Hamburger Menu>Settings>System>Network. Choose DHCP and once the robot is automatically assigned an ip address, select Static Address as the network method. This will keep the ip address from ever changing. The computer running your Kepware server should be on the same network as the UR3.

UR3-network

Now that you have found the items we need to add to the kepware configuration, lets go ahead and add them. Right click Project and select Properties>Thingworx. Input your host address and port number into the Host and Port fields. Paste your application key into the application key field.

Click Apply and OK.

Kepware-Thingworx

In the Kepware configuration, Under Project>Connectivity>UR_Channel, Right click UR3 and select Properties>General. Enter the ip address into the ID field.

UR3-device

Tip: Be mindful of when you are collecting data because things become slower the more data you collect. IF you are not actively needing to collect data, you can either turn off the robot or disable data collection in Kepware.

  • To turn off the robot, press the Green button in the bottom left of the teaching pendant and then off.
  • To disable data collection in Kepware, right click UR3>Select Properties>General>Data Collection>Disable.

UR Teaching Pendant Setup

Create a new Modbus client by selecting Installation>Fieldbus>MODBUS>Add MODBUS Unit. Enter the same ip address into the IP Address field. Add the following modbus signals by selecting Add New Signal.

Type Address Name
Register Input 128 TWX_Weight
Register Input 129 AnalysisDone
Register Output 130 ObjectWeight
Register Output 131 position
Register Output 132 SortingDone

UR3-device

Download the following programs to a USB drive from your computer:

Weight_Train.urp

Weight_Detection.urp

Insert the USB drive into the teaching pendant.


UR3 Data Collection

To begin data collection, navigate to the mashup in Thingworx composer by searching, UR3-analyticsmashup. Select View Mashup. This mashup will be useful when collecting data because you will see the data logged to the line chart. You can also see the actual amperage of each joint.

mashup

  1. On the teaching pendant, load the Weight_training.urp program
  2. With 5 well distributed weights in the range of 0-6.6 lbs nearby, press the play button to run the program.
  3. Follow the prompts on the teaching pendant:
    • Input object weight in lbs. (Up to 3 decimal places. Ex: 1.542 lbs).
    • When prompted, hold object inside the gripper while you simultaneously press continue. The gripper will closer, holding the object.
    • Weight for the program to finish, select yes to remove object and the program will loop, asking for a new object.
    • Repeat this until you have gven the robot at least 5 objects

Modeling

Data Understanding

In Thingworx, you can log properties in a remote thing by selecting the property and checking the logged box. In order to log properties to a value stream, the remote thing must have a value stream entity specified, in this case, UR3-valuestream is selected. The property value is logged to the value stream when the value of the logged property changes.

Kepware is set to scan for new property values every 10 ms, which can lead to many values being logged. In our case, we are only interested in certain rows of data, and not every single new value that logs to the value stream.

Though we are logging 7 properties with each data change, we will only use a small portion of this data to make the prediction. The data that will help us create the best machine learning model will match the following conditions:

  • The robot must be in a specific position.
    • We want to isolate the relationship between the joint amperage and the weight of the object.
    • The robot program sets the General_position property to 1 when in position and 0 when not in the position.
  • Only 4 of the 6 joints are meaningful.
    • In the chosen robot position, joints 1 and 6 are not helpful because their amperage hardly changes with varying payloads.
  • Negative amperage values are determined by substracting the value itself from 65535.
    • In the position we chose, the amperage is not negative or close to zero. Any values greater than 60000 should be irrelevant in this situation.
  • Velocity of all joints must be zero.
    • We made a decision to predict the weight while the robot was still. This makes data captured with the robot moving irrelevant.
    • Within UR3_remotething, a subscription sets the robot_moving boolean property to true or false, based on the joint velocity values

A Thing service called QueryPropertyHistory retrieves the logged property data. Since we only want certain data, we defined a query parameter which filters out the unwanted data when running this service. This query is a property in UR3-remotething called queryFilter. This query filters the data according to the cases presented above.

To train a machine learning model, we will use the Thingworx Analytics REST API services. The model training service will use the data retrieved after running the QueryPropertyHistory service with the aforementioned query as a parameter. We specify the multiple linear regresison algorithm because it can predict a continuous value. This allows us to predict weights that the robot has not held before. The Thingworx Analytics REST API services are executed when you select the Analytics buttons in the mashup. We will go over how to use the buttons properly in the next section.

Train Model

If you have let the robot hold 5 different weights, you should see at least 5 clusters of points on the line chart in the UR3-analyticsmashup. Confirm this before continuing on. It may look similar to the image below.

line chart

  1. If you have confirmed that you have successfully logged the data of at least 5 weights in a well distrubted range of 0-6.6 lbs, you can now select Save Dataset in the UR3-analyticsmashup. This saves the gathered data to a dataset which can be referenced by other services. The other buttons become disabled while this service executes because the new dataset will be referenced by the other buttons.
  2. Once the dataset creation is complete, the Train Model button is enabled. Select this button and a predictive model will be created.
  3. Once the model is created, you can select Validate Model. This will run a service which produces validation metrics for our predictive model.
  4. Once the validation job is complete, you can select Show Results which will retrieve the results of the model validation. The results are displayed in the table above the line chart in the mashup. These results help us understand the quality of our model. Description of model result statistics

Deployment

For model deployment, the mashup is also useful because the predicted weight is displayed in the top left of the mashup. (When running Weight_Detection.urp, the Object Weight is set to 9999 so we can filter out the data collected since the Object Weight would be an inaccurate value.)

  1. On the teaching pendant, load the Weight_Detection.urp program.
  2. With 5 weights in the range of 0-6.6 lbs nearby (these should be different weights than what you used in Data Collection), press the play button to run the program.
  3. Follow the prompts on the teaching pendant:
    • When prompted, hold object inside the gripper while you simultaneously press continue. The gripper will closer, holding the object
    • The robot will move to the same position as it did when training, but this time it will be detecting the weight. The weight will appear on the teaching pendant screen as a popup after a few seconds.
    • The robot will sort the object by weight, placing it into 1 of 3 piles. Once above the pile, the robot will move down slowly until it makes contact. Upon making contact, the robot will release the object.
    • On completion of the sorting, the program will loop and ask for a new object.
    • Repeat this as many times as you want. It might be interesting to compare the accuracy of the predicitons to the actual object weight.

If you want to start fresh and delete all the data you have collected so far, navigate to the UR3-remotething in Thingworx Composer and select Services>Expand the Generic item at the bottom of the page>find the service called PurgeAllPropertyHistory. Execute this service and specify the start and end date.


About

A guide to demonstrate the usage of Thingworx Analytics by using it to determine the weight of an object that a UR3 robot is holding.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors