E5 Lab 8

 Motors 'n MatLab
&
Mini-Project I: the robotic artist (or artistic robot)


The Teams

The teams for the next three lab periods (the next 2 weeks) are shown below.

Section A 

Team A?
Emery
Early
Holcomb
Karol
Lee

Team A??
Brown
Dulin
Landis
Noomah
Robinson

Team A???
McGuire
Perketi
Sacks
Thielstrom
Wilson

Section B

Team B?
Bledsoe
Chen
Garibay
Pitts
Thum

Team B??
Alto
Gluck
Ortiz
Redelmeier

Team B???
Gelles
Liebert
Quevedo
Rigell

Section C

Team C?
Alhessi
Barron
Guarini
Lin
Swartz

Team C??
Drubin
Friske
Norling-Ruggle
Ranshous
Sun

Team C???
Lu
Heppe
Hirsch
Thompson


Getting extra help:

If you find that you would like extra help, the following resources are available (in no particular order):


Getting Started

Choose a name for your team, and add it to the wiki (follow example for "Team Generic" at the top of the page for the Robot Artist project).  In addition to the wiki page there is a lab writeup (one per group) due next week.

Get a plastic box, and put your team name on it.  You can store these in Hicks 212.  Don't put the E5Shields in your box.  There are not enough for each group to have their own.

Read over the lab quickly - with such large groups, it probably makes sense to split up the tasks. 


Serial ports and motor control

Servo background:

We will use servo motors to position the arms of the robot arm you will be building.  Recall from class that the width of pulses sent to the servo determines the angle of the output shaft.



To control the servo motors we will use the "E5Shield" board shown below.

Connect the board to the computer with a USB cable.  To determine the correct port for the E5Shield go to the start menu in the lower left corner of the screen and select Start→Control Panel→Device Manager.  You should get a window like the one shown below.

Expand the "Ports (COM & LPT)" selection and find the "Arduino UNO R3"  (or something similar).  Note the number of the COM port associated with it. In the example above it is COM24.   Important:  You will probably have to do this every time you come in to program the devices.  The port number varies from computer to computer and over time.

To create and open an E5Shield object use the following code.  If it is successful you will get the output shown.  If not, type ">>explainError" and you will (hopefully) get a useful message.  The most common problems are the wrong COM port number or the fact that the object already exists.

>> a=E5Shield('COM24');  % Use your own COM port number here
Attempting connection: 3,2,1,0
E5Shield Script detected!
E5Shield successfully connected!

Get two motors and label them "A" and "B."  Connect one of the motors to a connector labeled "J0" through "J7" (the letter after the "J" is the motor number).  Note the polarity of the wire.  At the top of the connector there are three letters "Y  R  B".  The yellow lines goes to the pins marked "Y", red to "R" and black to "B."  In what follows below I will assume you have connected the motor to J3.  You also need to connect an external power supply to the wires coming off of the E5Shield board.

To turn the motor to the neutral position enter

>> a.servoWrite(3,125)

To go to the extreme counterclockwise position

>> a.servoWrite(3,0)

and to go to the extreme clockwise position.

>> a.servoWrite(3,250)

 Servo Calibration:

Your first task for today is to calibrate your two servos.

Connect servo "A" to the E5Shield to J0.  Download and run the script "ServoCalibrate.m" which asks for user input for the pulse width (in microseconds) and then sends the specified pulse width to channel 1.  Ask me (or a wizard if you have questions about the code).  Try to ensure that everybody on your team understands this code.

MATLAB Cell 1: Start a new script for this lab.  Include the code from script "ServoCalibrate.m", but add comments to the code to explain it.

Set the pulse count to 125.  We will call this zero degrees.   Use the protractor provided to fill in the table below with the angles for several pulse widths.  You may take more data at more pulse widths if you wish.

Pulse count 125 0 65 190 250
Angle (degrees) 0        

Now plot the pulse count versus angle (you did something similar in last week's lab), and find the values of slope and intercept the best fit the data

MATLAB Cell 2:  Include MATLAB code to create two vectors (for "Pulse count" and "Angle") with the data you collected.  Generate a graph simlar to the one shown below (but with your own measured data from your motor "A.").  The cell should display the values of slope and intercept.

Repeat for servo B (you will need both motors for the lab, so keep them marked so you can differentiate between them).

MATLAB Cell 3: Repeat the previous cell for servo B.


gotoAngles

Use the supplied template, gotoAngles.m, and fill it in to create a function that takes as input:

The function should move the two motors to the desired angles, and it must use your "getPCs" function from last week (you'll have to edit the constants defined in that function in accordance with your motor calibrations).  Test the function to make sure it works.


Inverse Kinematics

Use the supplied template, invKin.m, and fill it in to create a function that takes as input:

and returns

You may want to review the class notes to review the geometry of the problem.  You will need to include the lengths of the two sections of your robot arm.

Provide evidence that your "invKin" function works.  To do this you should figure out at least four x, y,  values and their associated values for θa and θb for a given arm lengths and demonstrate the the function returns the proper angle.  Some examples locations that are easy to verify include (you might want to double check these for accuracy because I didn't; also I assumed that the upper arm had a length of 4, and the lower arm a length of 3):

MATLAB Cell 4: Include proof that your "invKin" function works.  Figure out (by hand) the angles required for several (x,y) pairs, and show that your program calculates them properly.

To turn in

(via moodle)

Only turn in one lab report per group.  For this lab you are to turn in 3 files by next week.  Turn in one MATLAB script with multiple cells; each cell is devoted to one of the assigned tasks (magenta arrows, ).  Turn in function files, "gotoAngles.m" and "invKin.m".  There is no need to turn in a "published" Word document.  Grading of each cell and function is on a ten point scale:


The mini project

Resources/Ideas:

Requirements

Your task for the mini project is to write a script that  meets the following requirements.

  1. You must use the "invKin" and "gotoAngles" functions that you wrote (or similar functions).
  2. Your program must draw a circle inscribed in a square
  3. The project will be demonstrated in two week (November 15).
  4. You will create a wiki page that describes your design (what you did, evidence that your design functioned properly, what worked well, what didn't...) and includes a link to a zip file that contains all of your code used in the project.  The wiki is due the following week (Monday, November 19).

Other than those requirements, you are free to do as you please.

Good luck!