This tutorial shows how to train more advanced patterns in Studio, like nested patterns and user defined patterns.
How to Create a Nested Pattern
A nested pattern is a pattern within a pattern. This may be useful when packing things like bottles, because bottles may be packed tighter if the spaces between the bottles are filled with more bottles.
Take a look at the images below. The nested pattern is a combination of patterns A and B. This section of the tutorial will demonstrate how to create the behavior tree for a nested pattern.
In order to tell the robot which pattern to build three variables must be created.
- NestedPattern Variable - This variable will tell the robot to perform the inside pattern (B) instead of the outside pattern (A)
- PatternACount - This variable will keep track of how many times Pattern A has been performed. This will help the robot decide when to switch to the other pattern.
- PatternBCount - This variable will keep track of how many times Pattern B has been performed. This will help the robot decide when to switch to the other pattern.
1. To create a variable, click on the User Variables button in the Task Bar and then click on +Variable.
2. When creating a variable, it is important to give it a name that will help the user understand for what the variable will be used and how it will be used. In this case the NestedPattern variable will be of type Boolean (only two values: True or False) and the PatternCount variables will be Integer (only whole numbers: 0,1,2…).
3. Now, create the outside pattern by following the steps on How To Create A Pattern . Once this has been completed, label it Pattern A.
4. Make a couple of additions to the tree from the previous patterns example so that nested patterns will work.
The logic is as follows: every time the pattern sequence is executed, a counter is incremented. When the counter reaches a specific value, the robot will know to switch patterns and reset the counter. The additions are:
- Increment Counter
- After the Retract node add a set to node
- Label it “Increment A”
- Select the PatternACount and set it to increment. This will increment the count every time this node is performed. In this example, every time the pattern retracts it will increment the count so the robots knows how many times that particular sequence was performed.
- Check Counter Condition
- After the Increment A node add a do if node.
- Label it Check Count.
- Select the PatternACount variable and make it true when the count is >= than 4. The robot should only perform this sequence 4 times for the row, this condition should only be true if the variable is equal to or greater than 4. However, this number should match the number of columns in the row and is specific to this example. If the condition is met then the node will execute its children, otherwise it will skip.
- Change Pattern
- Add a child to the do if node and make it a set to node.
- Label it Change Pattern.
- Select the NestedPattern variable and set it to true. This will tell the robot to stop executing this pattern and start executing the inside pattern (B). This value will be used later.
- Reset Counter
- Add another child to the do if node and make it a set to node.
- Label it Reset A.
- Select the PartACount variable and set it to 0. This will reset the count so the robot can start using it once it returns to performing this pattern.
The behavior tree should change from looking like the tree on the left to the tree on the right.
Note: Applying the Object Mass can be done in the same SET TO node as Grip.
Note: A Hub is a pose above the Pattern where Sawyer moves to avoid bumping any fixtures and move into the orientation for picking. The frame of the Hub is set to either the base frame or the fixed frame of the pattern.
5. Now it’s time to create the inside pattern. Follow the steps for How To Create A Pattern. Make sure the variable set up are for Pattern B (i.e. PatternBCount instead of PatternACount in both the Increment and Reset Nodes).
6. Use the 3D view to verify that the patterns are nested together.
7. Add a condition node as a parent to each of the pattern nodes.
- The condition for pattern A should be true when the NestedPattern variable is false.
- The condition for pattern B should be true when the NestedPattern variable is true.
8. The last step is to initialize all variables at the beginning of the task. Add a SET TO node to the Initialize sequence and configure it as follows:
9. Use the picture below as a reference for how the tree should be structured.
How to Create a User Defined Pattern
A user defined pattern is helpful for repeating a sequence in which the iterations don’t follow a grid pattern, such as a circular pattern. This is also helpful when the orientation and location of points may vary but the sequence of actions is the same.
1. Position the arm at the first location. Click on the Frames button in the Task Bar to create new custom frames. For each location create a frame by clicking Add.
The frames will appear in the 3D view as shown below.
2. Once all of the frames have been created, go to the pattern node and create the sequence of actions which must be repeated. On the pattern node,select User Defined as the pattern type and start adding the custom frames in the Available Frames section.
3. Train the Approach, Action, and Retract move to nodes as children of the pattern node. This step is similar to all of types of patterns.
4. Configure the remainder of the behavior tree as desired with the appropriate move to, set to, and wait nodes to create a pick or place. The user defined pattern has been set.
- Always label frames which are used User Patterns. It makes it easier to configure and debug.
- Configure all end effectors properly.
- Errors often occur because one of the poses may be close to a joint limit. Always try to train poses where joints are as close to the middle as possible.
- In case of errors, use Adjust Poses and change some of the Pick and some of the Retract poses.
- When in the Adjust Poses screen, sometimes the Retract move to node may not be visible at the bottom of the screen when at 100% zoom. Zoom out to see it.