# Robotic Arm: Team Stealth Squad

**Team Stealth Squad:**

## Overview

Our team created a dual-jointed robotic arm that would hold a pencil and draw a circle within a square within another circle. To do this we used a variety of Lynxmotion parts from the Engineering Lab classroom. The arm is attached to a surface using a c-clamp and is moved using two servo motors. The motors are controlled through a circuit board run with Matlab code. After calibrating the motors we went about creating an arm using aluminum tubes, servo brackets, and hubs. We initially used long (4"-6")tubes for the "upper arm" segment of our robotic arm, however this caused poor distibution of mass and led to an unbalanced and shaky product. Our final construct used 2" tubes for both segments of our robotic arm. After constructing the arm our team began to work on making a SolidWorks Model and creating Matlab commands that would control the arm and run the functions which we wanted with appropriate scale, speed, and accuracy.

## Solid Works

- Our SolidWorks model shows the basic design and assembly of our robotic arm.
- Fastners, pencil, and c-clamp are not included.
- The SolidWorks file was created after completion of the physical arm.
- It is thus more of a model/simulation than a design aid.

## Matlab

### Simulation

%Define the arm la=4.5; lb=4.3025; %Draw and animate the arm; numPts = 20; %the number of points in the animation phi = linspace(0,2*pi,numPts); %angle goes from 0 to 2*pi. clf % clear the figure. x0=0; %Define center (x0,y0) of circle and radius (r) y0=7; r=1; % loop through all the values of phi for i=1:length(phi), x2=x0+r*cos(phi(i)); %x2 and y2 trace out a circle. y2=y0+r*sin(phi(i)); %First do inverse kinematics to find angles... [theta_a, theta_b]= InverseKinematics(la, lb, x2, y2); %Then do forward kinematics to find arm locations. [xa ya xb yb] = forwardKinematics(la, lb, theta_a, theta_b); subplot(1,2,1); %generate 1x2 plots, choose plot 1 plot([0 xa xb],[0 ya yb],'b','LineWidth',2); axis([-10 10 0 10]); subplot(1,2,2); %choose second plot plot(xb,yb,'ro') %plot red circle axis([-10 10 0 10]); hold on; %don't erase this plot. pause(0.1); %delay 1/10 second end

This code simulates our robotic arm drawing a circle in MatLab. The code is essentially the same as the simulation from MatLab Lab 1, only with the arm lengths changed to correspond with the arm lengths of our robot.

### Control Script

To draw a circle within a square within a circle, we first create a function to draw a line from two endpoints and a function to draw a circle from a center point and a radius. These functions were generated by taking the code for the simulations, replacing the values of the line and circle with variables defined by the inputs, and replacing the part that plotted the figure with a loop that sent strings to the servo controller for each point on the line or circle. Then, we created a script that first drew a circle with radius 1, the the lines that defined a tangential square, and then another circle of radius sqrt(2) that circumscribed the square.

ArmDrawLine.m:

function [xi,yi,xf,yf] = ArmDrawLine(xi,yi,xf,yf) %Define the arm la=4.5; lb=4.3025; %Define the line; numPts = 25; %the number of points in the line x2=linspace(xi,xf,numPts); %generate an array of x2 ... y2=linspace(yi,yf,numPts); %... and y2 values to define a line. % loop through all the values of x2 and y2 for i=1:length(x2), %First do inverse kinematics to find angles... [theta_a, theta_b]= InverseKinematics(la, lb, x2(i), y2(i)); %Then do forward kinematics to find arm locations. [xa ya xb yb] = forwardKinematics(la, lb, theta_a, theta_b); %Move arm to next point on the line. MoveArm(xb, yb); pause(0.1); %delay 1/10 second end

ArmDrawCircle.m:

function [x0,y0,r] = ArmDrawCircle(x0,y0,r) %Define the arm la=4.5; lb=4.3025; %Define the circle; numPts = 50; %the number of points in the circle phi = linspace(0,2*pi,numPts); %angle goes from 0 to 2*pi. % loop through all the values of phi for i=1:length(phi), x2=x0+r*cos(phi(i)); %x2 and y2 trace out a circle. y2=y0+r*sin(phi(i)); %First do inverse kinematics to find angles... [theta_a, theta_b]= InverseKinematics(la, lb, x2, y2); %Then do forward kinematics to find arm locations. [xa ya xb yb] = forwardKinematics(la, lb, theta_a, theta_b); MoveArm(xb,yb); pause(0.1); %delay 1/10 second end

CwiaSwiaC.m (Circle within a Square within a Circle):

%Draw first circle ArmDrawCircle(0,7,1) %Starting from the end of the circle, draw a tangential square ArmDrawLine(1,7,1,8) ArmDrawLine(1,8,-1,8) ArmDrawLine(-1,8,-1,6) ArmDrawLine(-1,6,1,6) ArmDrawLine(1,6,1,7) %Circumscribe the square ArmDrawCircle(0,7,1.41)