E5 Lab 11 - Robotic Laser Pointer

 

Remember, documentation is at: https://www.mathworks.com/help/supportpkg/arduinoio/index.html?s_cid=doc_ftr

If you make a mistake with the servo variable during this lab, you can run the following two lines to clear the variable from memory and disconnect it.

>> clear s1   % s1 is the MATLAB variable associated with the motor on pin 9
>> configureDigitalPin(a,9,'Unset')    % specify pin 9 in this line

If your arduino stops communicating with MATLAB, you can try disconnecting and then reconnecting the USB. If that doesn't work, try:

>> snew = instrfind;   % find all serial port objects;
>> fclose(snew);       % close them
>> delete(snew);       % delete them

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 same I/O board you built a few weeks ago.Connect a servo to JServo1 as shown below.. Note the position of the black wire near the power connector - it must be connected as shown. You must also connect an external power source because USB cannot supply sufficient power.

To communicate with the board, and control the servos, connect to the arduino and the create a variable to represent the motors.

>> a=arduino('com31','Uno')
a = 
  arduino with properties:
                    Port: 'COM31'
                   Board: 'Uno'
     AvailableAnalogPins: [0, 1, 2, 3, 4, 5]
    AvailableDigitalPins: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
               Libraries: {'I2C', 'SPI', 'Servo'}

>>s1=servo(a,9) % Create servo variable
s1 = 
 Servo with properties:
                 Pins: 9
     MinPulseDuration: 5.44e-04 (s)
     MaxPulseDuration: 2.40e-03 (s)

You can now make the motor turn by specifying an angle between 0 and 1 (roughly 180 degrees).

>> writePosition(s1,0.5);
>> writePosition(s1,1);
>> writePosition(s1,0);

This is illustrated below, note that the motor is at a different angle in each photograph

writePosition(s1,0); writePosition(s1,0.5); writePosition(s1,1);

Check the schematic below. Note that pin 9 not only controls the servo but one of the RGB led's, so the intensity of that LED will vary as you change the width of the pulse (a pulse is generated about once every 20 milliSeconds - too fast for your eye to see - but you can see the change in intensity in the images above).

Make sure you can also control a motor on JServo2. Note: you will have to change the pin number - check the schematic for the correct pin number.

You may want to split up your group into sub-groups to perform calibration of motors and construction of apparatus, though there is no requirement to do so.

Servo Calibration:

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

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 - there are several new things that we haven't seen before (and these will be more obvious to those that are more comfortable with MatLab).

Make sure you understand how the code works.  In particular add comments as necessary to explain the operation of the code.

Set the normalized angle to 0.5.  We will call this zero degrees.  Use a protractor provided to fill in the table below with the angles for several normalized angles.  You may take more data at more angles if you wish.

Angle (normalize) 0.50 0.00 1.00 0.25 0.75
Angle (degrees) 0        

Now plot the normalized angle versus measured angle, and find the values of slope and intercept the best fit the data as you did last week.

Repeat for a second servo motor (you will need both motors for the lab, so keep them separate).

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.

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.

Collect evidence that your invKin function works.  To do this you should figure out at least four x, y, and z values and their associated values for theta and phi for a given arm lengths, and demonstrate that your function returns the proper angle.  S

The text below describes a two-week project. You should demonstrate to me when you are done, the written report is due on moodle (check moodle for due date).  See the note above about getting extra help.


The mini project

Resources/Ideas:

Requirement

Build a laser pointer that conforms to the geometry described in class using the parts supplied as well as the laser holder you designed in SolidWorks earlier in the semester.. You may specify the a and b parameters as well as the zero locations for x, y and z. Your task for the mini project is to write a script that conrols a laser pointer and meets the following requirement.

Report

The report will be a single file on moodle that

Moodle will also accept a video file if you want to include one, but it is not required.