Application Center - Maplesoft

App Preview:

Robot Arm Drawing a Maple Leaf

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application




Robot Arm Drawing a Maple Leaf

Introduction

This application generates an animation of a 3 DOF robot arm drawing a Maple leaf.

To model the arm, the worksheet symbolically derives the transformation matrix (via a Denavit & Hartenberg method) for each of the three joints

The tip of the robot arm is requested to follow a parametric curve that traces out a Maple leaf. The joint angles to achieve this motion are calculated via the transformation matrices.

Reference:

Adapted from http://www.maplesoft.com/applications/view.aspx?SID=6850

Transformation Matrix for One Joint

restartwith(plots)with(plottools); with(ColorTools)

A1 := Matrix(4, 4, {(1, 1) = cos(theta), (1, 2) = -sin(theta), (1, 3) = 0, (1, 4) = 0, (2, 1) = sin(theta), (2, 2) = cos(theta), (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1}); A2 := Matrix(4, 4, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1, (3, 4) = d, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1}); B1 := A2.A1; A3 := Matrix(4, 4, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = cos(alpha), (2, 3) = -sin(alpha), (2, 4) = 0, (3, 1) = 0, (3, 2) = sin(alpha), (3, 3) = cos(alpha), (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1}); A4 := Matrix(4, 4, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = a, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 1}); B2 := A3.A4; H := B1.B2

Matrix(%id = 18446745673619737886)

(2.1)

Transformation Matrix of Tip wrt Base

Next, use parameters for a robot with a sequence of three arms and compute the transformation matrix for the tip of the robot with respect to its base.

H1 := eval(H, [theta = theta1, alpha = -(1/2)*Pi, a = 0, d = lengthArm1])
H2 := eval(H, [theta = theta2, alpha = 0, d = 0, a = lengthArm2])

H3 := eval(H, [theta = theta3, alpha = 0, a = lengthArm3+lengthTip, d = 0])

H14 := H1.H2.H3

Path for Robot Tip to Follow

This is the required path for the end effector, as a function of time.

r := (1+sin(t))*(1+.3*cos(8*t))*(1+.1*cos(24*t))

path := [x = 200*r*cos(t)+400, y = 200*r*sin(t)+200, z = 200]

Deriving Joint Angles

First Angle

v := `<,>`(0, 0, 0, 1)
w := H14.v

eq1 := w[1]/w[2] = x/y
Theta1 := solve(eq1, theta1)

arctan(y/x)

(5.1.1)

Second Angle

u := w[1]^2+w[2]^2+w[3]^2-A

v := w[3]-z

W := simplify(-2*v*lengthArm1+u)

Theta := solve(W, theta3)
Theta2 := eval(Theta, A = x^2+y^2+z^2)

arccos((1/2)*(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2-lengthArm2^2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)/(lengthArm2*(lengthArm3+lengthTip)))

(5.2.1)

Third Angle

W1 := w[3]-z
W2 := eval(W1, theta3 = Theta2)

sol := solve(W2 = 0, theta2)

Theta3 := simplify(sol[1]+(1/2)*Pi)

arctan((-lengthArm2*((x^2+y^2)*(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2+lengthArm2^2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)^2)^(1/2)*(lengthArm3+lengthTip)*(-(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2-lengthArm2^2+(2*lengthArm3+2*lengthTip)*lengthArm2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)*(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2-lengthArm2^2+(-2*lengthArm3-2*lengthTip)*lengthArm2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)/(lengthArm2^2*(lengthArm3+lengthTip)^2))^(1/2)-(z-lengthArm1)*(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2+lengthArm2^2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)^2)/((x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2)*lengthArm2*(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2+lengthArm2^2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)), (-lengthArm2*(lengthArm3+lengthTip)*(z-lengthArm1)*(-(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2-lengthArm2^2+(2*lengthArm3+2*lengthTip)*lengthArm2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)*(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2-lengthArm2^2+(-2*lengthArm3-2*lengthTip)*lengthArm2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)/(lengthArm2^2*(lengthArm3+lengthTip)^2))^(1/2)+((x^2+y^2)*(x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2+lengthArm2^2-lengthArm3^2-2*lengthArm3*lengthTip-lengthTip^2)^2)^(1/2))/((x^2+y^2+z^2-2*z*lengthArm1+lengthArm1^2)*lengthArm2))+(1/2)*Pi

(5.3.1)

Animation

N := 200

radiusBase := 150

radiusArm1 := 70

radiusJoint2 := radiusArm1+5

radiusArm2 := 60

radiusArm3 := 50

lengthArm1 := 500; lengthArm2 := 450; lengthArm3 := 350; lengthTip := 200

for p from 0 to N do s := 2.0*Pi*p/N; pathAtTime := eval(path, t = s); px[p], py[p], pz[p] := rhs(pathAtTime[1]), rhs(pathAtTime[2]), rhs(pathAtTime[3]); for i to 3 do theta[p, i] := eval(subs(path, Theta || i), t = s) end do end do

pathTrace := pointplot3d([seq([px[u], py[u], pz[u]], u = 0 .. N)], color = Color("RGB", [0*(1/255), 79/255, 121/255]), connect = true)

opts := color = Color("RGB", [108*(1/255), 122/255, 137/255]), grid = [10, 2]; baseCyl := cylinder([0, 0, 0], radiusBase, 80, opts)

arm1 := cylinder([0, 0, 0], radiusArm1, lengthArm1, opts)

joint2 := translate(rotate(cylinder([0, 0, 0], radiusJoint2, 2*radiusJoint2, opts), (1/2)*Pi, 0, 0), 0, -radiusJoint2, lengthArm1)

arm2 := cylinder([0, 0, 0], radiusArm2, lengthArm2, opts)

joint3 := rotate(cylinder([0, 0, 0], radiusArm2, 2*radiusArm2, opts), (1/2)*Pi, 0, 0)

arm3 := cylinder([0, 0, 0], radiusArm3, lengthArm3, opts)
tip := cone([0, 0, 0], radiusArm3, lengthTip, opts)
NULL

robotAnim := proc (p) local Joint2, Arm2, Joint3, Arm3, Tip, pt; Joint2 := rotate(joint2, 0, 0, -theta[p, 1]); Arm2 := rotate(translate(rotate(arm2, 0, -theta[p, 3], 0), 0, 0, lengthArm1), 0, 0, -theta[p, 1]); Joint3 := rotate(translate(joint3, lengthArm2*sin(theta[p, 3]), -radiusArm2, lengthArm1+lengthArm2*cos(theta[p, 3])), 0, 0, -theta[p, 1]); Arm3 := rotate(translate(rotate(arm3, 0, -theta[p, 3]-theta[p, 2], 0), lengthArm2*sin(theta[p, 3]), 0, lengthArm1+lengthArm2*cos(theta[p, 3])), 0, 0, -theta[p, 1]); Tip := rotate(translate(rotate(tip, 0, Pi-theta[p, 3]-theta[p, 2], 0), lengthArm2*sin(theta[p, 3])+(lengthArm3+lengthTip)*sin(theta[p, 3]+theta[p, 2]), 0, lengthArm1+lengthArm2*cos(theta[p, 3])+(lengthArm3+lengthTip)*cos(theta[p, 3]+theta[p, 2])), 0, 0, -theta[p, 1]); pt := pointplot3d([seq([px[u], py[u], pz[u]], u = 0 .. p)], color = Color("RGB", [0, 79/255, 121/255]), connect = true); display(pt, baseCyl, arm1, Joint2, Arm2, Joint3, Arm3, Tip, scaling = constrained, axes = none, style = patchnogrid, orientation = [-45, 45, 0]) end proc

animate(robotAnim, [t], t = [`$`(1 .. 200)])