6.9 - Chaining Transformations - Adding an Upper Arm

Robot upper arm

Robot Upper-arm Model

The previous lesson demonstrated a robot arm with one linkage. This lesson will demonstrate how to chain transforms together to add a second linkage.

A Robot Arm - The Upper Arm

The upper arm of our robot is created in Blender and its local origin is set at (0,0,0) so that it can be easily rotated. It’s axis of rotation is the Z axis. Examine the image of the upper arm to the right.

The upper arm will pivot about the end of the forearm. But rotation is about the origin. We need to rotate the upper arm about the origin, and then move it to the end of the forearm. But the forearm is rotating, as well as the base. So how do we get the upper arm to the right place? We use the transforms that are positioning the forearm! Here’s the transforms we need to apply to the upper arm, in this order:

  1. Rotate it to a desired angle about its red pin.
  2. Translate it to the end of the forearm.
  3. Rotate it based on the forearm’s angle.
  4. Translate it to the base’s red pin.
  5. Rotate it according to the base’s rotation angle.

The transformation for the upper arm needs to be the following:

modelTransform
=baseRotation
*translateToPin
*rotateForearm
*translateToForearmEnd
*rotateUpperarm
Eq2

Hopefully you are seeing a pattern here!

Scene Rendering Initialization

The demo program below is a modified version of the code from the previous lesson. It adds an “upper arm” model to the robot arm. We need two new transform matrices to manipulate the upper arm. One transform will rotate the arm about it’s pivot pin. The rotation will possibly change on each new frame, so this matrix will be created in the initialization code but assigned its value in the frame rendering function. The translation matrix can be create and assigned its value once, since the distance to the end of the forearm is a constant and never changes. Study the example code and then review the code description below. If you want to experiment, the demo code is modifiable.

Show: Code   Canvas   Run Info
 
1
/**
2
 * robot_base_scene.js, By Wayne Brown, Fall 2017
3
 */
4
5
/**
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2015 C. Wayne Brown
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in all
18
 * copies or substantial portions of the Software.
19
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 * SOFTWARE.
27
 */
28
29
"use strict";
30
31
//-------------------------------------------------------------------------
32
/**
33
 * Initialize and render a scene.
34
 * @param id {string} The id of the webglinteractive directive
35
 * @param download {SceneDownload} An instance of the SceneDownload class
36
 * @param vshaders_dictionary {object} A dictionary of vertex shaders.
37
 * @param fshaders_dictionary {object} A dictionary of fragment shaders.
38
 * @param models {object} A dictionary of models.
../_static/06_robot3/robot_upperarm.html

A robot arm with 2 linkages.

Please use a browser that supports "canvas"
Forearm angle about Z axis: 0.00 :
-90.0 90.0
Upper arm angle about Z axis: 0.00 :
-90.0 90.0
Animate
Open this webgl program in a new tab or window

Concerning the pre-processing actions that happen once when the constructor code is executed:

Line(s) Description
67-68 Two new transforms are created to manipulate the upper arm.
175 The translation for the upper arm is set to a constant 8 units along Y.
74 A public class variable, self.upperarm_angle, is created to store the angle of the upper arm. It is made public so the HTML slider event handler can change its value.
170-171 Buffer objects in the GPU are created and the model data is copied to the GPU for the upper arm model.

Each time the scene needs to be rendered, the render function in lines 80-115 is called. This function is identical to the previous demo version with the following exceptions:

Line(s) Description
107 The rotation matrix for the upper arm is set because the rotation of the forearm can change on each frame.
110-111 The transform for the upper arm is calculated. Notice that the base rotation and the forearm transforms are included. Also notice the ordering of the transforms from right to left. The order of the transforms is critical.
114 The upper arm model is rendered using the calculated transform.

Self Assessment

Q-149: The transformation matrix that transforms the upper arm is calculated using seven matrices. You could pass all seven matrices to a vertex shader and let the GPU calculate the combined transformation matrix. Besides, the GPU is very fast at computations! Why is this a bad idea? (Select all that apply.)





Q-150: You want to modify the example WebGL program to add a 3rd linkage to the robot that has one degree of rotation from the end of the 2nd linkage. How many new transformation matrices do you need to create?





Next Section - 6.10 - Chaining Transformations (Summary)