<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=RyanDeeter</id>
	<title>Mech - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=RyanDeeter"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/RyanDeeter"/>
	<updated>2026-05-19T17:44:32Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18151</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18151"/>
		<updated>2010-03-19T08:23:23Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Next Steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofArmSetUp.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.  These equations were found on [http://www.societyofrobots.com/robot_arm_tutorial.shtml#forward_kinematics this helpful website].  The following block of MATLAB code shows how these equations were adapted for this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ x, y ] = arm_thetas_to_xy( theta1, theta2 )&lt;br /&gt;
%ARM_THETAS_TO_XY Uses forward kinematics to give position from angle&lt;br /&gt;
%   Pass in theta1 and theta2 (in degrees)&lt;br /&gt;
%   Returns x and y&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
alpha = deg2rad(theta1);&lt;br /&gt;
psi = deg2rad(theta2 - theta1);&lt;br /&gt;
&lt;br /&gt;
j1_x = L1*cos(alpha);&lt;br /&gt;
j1_y = L1*sin(alpha);&lt;br /&gt;
&lt;br /&gt;
j2_x = L2*cos(alpha+psi) + j1_x;&lt;br /&gt;
j2_y = L2*sin(alpha+psi) + j1_y;&lt;br /&gt;
&lt;br /&gt;
x = j2_x;&lt;br /&gt;
y = j2_y;&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ theta1, theta2 ] = arm_xy_to_thetas( x, y )&lt;br /&gt;
%ARM_XY_TO_THETAS Uses inversion kinematics to give angles for position&lt;br /&gt;
%   Pass in x and y&lt;br /&gt;
%   Returns theta1 and theta2 (in degrees)&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
% calculate the theta path      &lt;br /&gt;
c2 = (x.^2 + y.^2 - L1.^2 - L2.^2) / (2 * L1 * L2);&lt;br /&gt;
s2 = sqrt(1 - c2.^2);&lt;br /&gt;
psi = acos((x.^2 + y.^2 - L1^2 - L2^2) / (2 * L1 * L2));&lt;br /&gt;
alpha = asin((y .* (L1 + L2 .* c2) - x .* L2 .* s2) ./ (x.^2 + y.^2));&lt;br /&gt;
&lt;br /&gt;
% convert to degrees&lt;br /&gt;
theta1 = rad2deg(alpha);&lt;br /&gt;
theta2 = rad2deg(alpha+psi);&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in the dark color is the path that the PIC tried to execute, and the light color plot shows the actual path of the arm, for comparison. Currently, the plotting commands are buggy.  Data only plot if &amp;quot;Continuous Update&amp;quot; is on, and the &amp;quot;Get Data&amp;quot; button does not seem to function.  The problem here is communicating between the GUI and the other MATLAB functions, and this could easily be corrected.&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
This project came a long way, but could go much further.  &lt;br /&gt;
&lt;br /&gt;
One large area of improvement is in the logging of data.  Logging speeds could be improved through more efficient coding, but even more through the use of USB communication.  Since data are currently sent through RS-232, top transmission speeds are limited.  Using USB would allow for the GUI graphs to update in much closer to real time.  &lt;br /&gt;
&lt;br /&gt;
The motor control parameters could be tweaked to provide for greater control.  Part of that is just trail and error for different constants, but better derivative and integral terms could be used in the control.&lt;br /&gt;
&lt;br /&gt;
Mechanical improvements would also aid in control.  The arms currently move about and bounce (as seen in the video) due to motor backlash.  Fixing this problem would allow for even more precise, quicker motions.&lt;br /&gt;
&lt;br /&gt;
The GUI could also be greatly improved to allow for more user options.  The options were limited in this version to reduce the likelihood that a user would program a path fatal to the arm.  With improved software and hardware limit switching, more user control would be available.&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18148</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18148"/>
		<updated>2010-03-19T08:17:02Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofArmSetUp.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.  These equations were found on [http://www.societyofrobots.com/robot_arm_tutorial.shtml#forward_kinematics this helpful website].  The following block of MATLAB code shows how these equations were adapted for this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ x, y ] = arm_thetas_to_xy( theta1, theta2 )&lt;br /&gt;
%ARM_THETAS_TO_XY Uses forward kinematics to give position from angle&lt;br /&gt;
%   Pass in theta1 and theta2 (in degrees)&lt;br /&gt;
%   Returns x and y&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
alpha = deg2rad(theta1);&lt;br /&gt;
psi = deg2rad(theta2 - theta1);&lt;br /&gt;
&lt;br /&gt;
j1_x = L1*cos(alpha);&lt;br /&gt;
j1_y = L1*sin(alpha);&lt;br /&gt;
&lt;br /&gt;
j2_x = L2*cos(alpha+psi) + j1_x;&lt;br /&gt;
j2_y = L2*sin(alpha+psi) + j1_y;&lt;br /&gt;
&lt;br /&gt;
x = j2_x;&lt;br /&gt;
y = j2_y;&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ theta1, theta2 ] = arm_xy_to_thetas( x, y )&lt;br /&gt;
%ARM_XY_TO_THETAS Uses inversion kinematics to give angles for position&lt;br /&gt;
%   Pass in x and y&lt;br /&gt;
%   Returns theta1 and theta2 (in degrees)&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
% calculate the theta path      &lt;br /&gt;
c2 = (x.^2 + y.^2 - L1.^2 - L2.^2) / (2 * L1 * L2);&lt;br /&gt;
s2 = sqrt(1 - c2.^2);&lt;br /&gt;
psi = acos((x.^2 + y.^2 - L1^2 - L2^2) / (2 * L1 * L2));&lt;br /&gt;
alpha = asin((y .* (L1 + L2 .* c2) - x .* L2 .* s2) ./ (x.^2 + y.^2));&lt;br /&gt;
&lt;br /&gt;
% convert to degrees&lt;br /&gt;
theta1 = rad2deg(alpha);&lt;br /&gt;
theta2 = rad2deg(alpha+psi);&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in the dark color is the path that the PIC tried to execute, and the light color plot shows the actual path of the arm, for comparison. Currently, the plotting commands are buggy.  Data only plot if &amp;quot;Continuous Update&amp;quot; is on, and the &amp;quot;Get Data&amp;quot; button does not seem to function.  The problem here is communicating between the GUI and the other MATLAB functions, and this could easily be corrected.&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18146</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18146"/>
		<updated>2010-03-19T08:16:10Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofArmSetUp.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.  These equations were found on [http://www.societyofrobots.com/robot_arm_tutorial.shtml#forward_kinematics this helpful website].  The following block of MATLAB code shows how these equations were adapted for this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ x, y ] = arm_thetas_to_xy( theta1, theta2 )&lt;br /&gt;
%ARM_THETAS_TO_XY Uses forward kinematics to give position from angle&lt;br /&gt;
%   Pass in theta1 and theta2 (in degrees)&lt;br /&gt;
%   Returns x and y&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
alpha = deg2rad(theta1);&lt;br /&gt;
psi = deg2rad(theta2 - theta1);&lt;br /&gt;
&lt;br /&gt;
j1_x = L1*cos(alpha);&lt;br /&gt;
j1_y = L1*sin(alpha);&lt;br /&gt;
&lt;br /&gt;
j2_x = L2*cos(alpha+psi) + j1_x;&lt;br /&gt;
j2_y = L2*sin(alpha+psi) + j1_y;&lt;br /&gt;
&lt;br /&gt;
x = j2_x;&lt;br /&gt;
y = j2_y;&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ theta1, theta2 ] = arm_xy_to_thetas( x, y )&lt;br /&gt;
%ARM_XY_TO_THETAS Uses inversion kinematics to give angles for position&lt;br /&gt;
%   Pass in x and y&lt;br /&gt;
%   Returns theta1 and theta2 (in degrees)&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
% calculate the theta path      &lt;br /&gt;
c2 = (x.^2 + y.^2 - L1.^2 - L2.^2) / (2 * L1 * L2);&lt;br /&gt;
s2 = sqrt(1 - c2.^2);&lt;br /&gt;
psi = acos((x.^2 + y.^2 - L1^2 - L2^2) / (2 * L1 * L2));&lt;br /&gt;
alpha = asin((y .* (L1 + L2 .* c2) - x .* L2 .* s2) ./ (x.^2 + y.^2));&lt;br /&gt;
&lt;br /&gt;
% convert to degrees&lt;br /&gt;
theta1 = rad2deg(alpha);&lt;br /&gt;
theta2 = rad2deg(alpha+psi);&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison. Currently, the plotting commands are buggy.  Data only plot if &amp;quot;Continuous Update&amp;quot; is on, and the &amp;quot;Get Data&amp;quot; button does not seem to function.  The problem here is communicating between the GUI and the other MATLAB functions, and this could easily be corrected.&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18119</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18119"/>
		<updated>2010-03-19T07:42:07Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofArmSetUp.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.  These equations were found on [http://www.societyofrobots.com/robot_arm_tutorial.shtml#forward_kinematics this helpful website].  The following block of MATLAB code shows how these equations were adapted for this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ x, y ] = arm_thetas_to_xy( theta1, theta2 )&lt;br /&gt;
%ARM_THETAS_TO_XY Uses forward kinematics to give position from angle&lt;br /&gt;
%   Pass in theta1 and theta2 (in degrees)&lt;br /&gt;
%   Returns x and y&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
alpha = deg2rad(theta1);&lt;br /&gt;
psi = deg2rad(theta2 - theta1);&lt;br /&gt;
&lt;br /&gt;
j1_x = L1*cos(alpha);&lt;br /&gt;
j1_y = L1*sin(alpha);&lt;br /&gt;
&lt;br /&gt;
j2_x = L2*cos(alpha+psi) + j1_x;&lt;br /&gt;
j2_y = L2*sin(alpha+psi) + j1_y;&lt;br /&gt;
&lt;br /&gt;
x = j2_x;&lt;br /&gt;
y = j2_y;&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ theta1, theta2 ] = arm_xy_to_thetas( x, y )&lt;br /&gt;
%ARM_XY_TO_THETAS Uses inversion kinematics to give angles for position&lt;br /&gt;
%   Pass in x and y&lt;br /&gt;
%   Returns theta1 and theta2 (in degrees)&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
% calculate the theta path      &lt;br /&gt;
c2 = (x.^2 + y.^2 - L1.^2 - L2.^2) / (2 * L1 * L2);&lt;br /&gt;
s2 = sqrt(1 - c2.^2);&lt;br /&gt;
psi = acos((x.^2 + y.^2 - L1^2 - L2^2) / (2 * L1 * L2));&lt;br /&gt;
alpha = asin((y .* (L1 + L2 .* c2) - x .* L2 .* s2) ./ (x.^2 + y.^2));&lt;br /&gt;
&lt;br /&gt;
% convert to degrees&lt;br /&gt;
theta1 = rad2deg(alpha);&lt;br /&gt;
theta2 = rad2deg(alpha+psi);&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18118</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18118"/>
		<updated>2010-03-19T07:41:45Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Equations of Motion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofArmSetUp.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.  These equations were found on [http://www.societyofrobots.com/robot_arm_tutorial.shtml#forward_kinematics this helpful website].  The following block of MATLAB code shows how these equations were adapted for this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ x, y ] = arm_thetas_to_xy( theta1, theta2 )&lt;br /&gt;
%ARM_THETAS_TO_XY Uses forward kinematics to give position from angle&lt;br /&gt;
%   Pass in theta1 and theta2 (in degrees)&lt;br /&gt;
%   Returns x and y&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
alpha = deg2rad(theta1);&lt;br /&gt;
psi = deg2rad(theta2 - theta1);&lt;br /&gt;
&lt;br /&gt;
j1_x = L1*cos(alpha);&lt;br /&gt;
j1_y = L1*sin(alpha);&lt;br /&gt;
&lt;br /&gt;
j2_x = L2*cos(alpha+psi) + j1_x;&lt;br /&gt;
j2_y = L2*sin(alpha+psi) + j1_y;&lt;br /&gt;
&lt;br /&gt;
x = j2_x;&lt;br /&gt;
y = j2_y;&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function [ theta1, theta2 ] = arm_xy_to_thetas( x, y )&lt;br /&gt;
%ARM_XY_TO_THETAS Uses inversion kinematics to give angles for position&lt;br /&gt;
%   Pass in x and y&lt;br /&gt;
%   Returns theta1 and theta2 (in degrees)&lt;br /&gt;
%   ---&lt;br /&gt;
%   Sam Bobb,  Daniel Cornew,  Ryan Deeter&lt;br /&gt;
%	Two degree of freedom arm&lt;br /&gt;
%	High speed motor control for 2 motors&lt;br /&gt;
%	Code version 3&lt;br /&gt;
%	March 18, 2010&lt;br /&gt;
%   ---&lt;br /&gt;
&lt;br /&gt;
% pull in constants&lt;br /&gt;
arm_constants&lt;br /&gt;
&lt;br /&gt;
% calculate the theta path      &lt;br /&gt;
c2 = (x.^2 + y.^2 - L1.^2 - L2.^2) / (2 * L1 * L2);&lt;br /&gt;
s2 = sqrt(1 - c2.^2);&lt;br /&gt;
psi = acos((x.^2 + y.^2 - L1^2 - L2^2) / (2 * L1 * L2));&lt;br /&gt;
alpha = asin((y .* (L1 + L2 .* c2) - x .* L2 .* s2) ./ (x.^2 + y.^2));&lt;br /&gt;
&lt;br /&gt;
% convert to degrees&lt;br /&gt;
theta1 = rad2deg(alpha);&lt;br /&gt;
theta2 = rad2deg(alpha+psi);&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18107</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18107"/>
		<updated>2010-03-19T07:35:50Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Equations of Motion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofArmSetUp.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.  These equations were found on [http://www.societyofrobots.com/robot_arm_tutorial.shtml#forward_kinematics this helpful website].&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18099</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18099"/>
		<updated>2010-03-19T07:21:28Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofArmSetUp.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18095</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18095"/>
		<updated>2010-03-19T07:20:13Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18092</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18092"/>
		<updated>2010-03-19T07:18:59Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;imagemap&amp;gt;&lt;br /&gt;
Image:2dofYoutubeLink.jpg|right&lt;br /&gt;
default [[Results]]&lt;br /&gt;
&amp;lt;/imagemap&amp;gt;&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18084</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18084"/>
		<updated>2010-03-19T07:08:11Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg||right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18082</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18082"/>
		<updated>2010-03-19T07:07:49Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18081</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18081"/>
		<updated>2010-03-19T07:07:09Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link=Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18045</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18045"/>
		<updated>2010-03-19T06:10:24Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|center|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18042</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18042"/>
		<updated>2010-03-19T06:09:37Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|500px|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:GuiScreenShot.jpg&amp;diff=18041</id>
		<title>File:GuiScreenShot.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:GuiScreenShot.jpg&amp;diff=18041"/>
		<updated>2010-03-19T06:09:04Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: Screenshot of the GUI&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of the GUI&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18037</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18037"/>
		<updated>2010-03-19T06:06:30Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[[Image: guiScreenShot.jpg|Screenshot of the GUI]]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18029</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18029"/>
		<updated>2010-03-19T06:01:28Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:CircleGUI.jpg&amp;diff=18020</id>
		<title>File:CircleGUI.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:CircleGUI.jpg&amp;diff=18020"/>
		<updated>2010-03-19T05:56:09Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: A screenshot of the GUI using the circle function.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A screenshot of the GUI using the circle function.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:TraceXY.jpg&amp;diff=18017</id>
		<title>File:TraceXY.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:TraceXY.jpg&amp;diff=18017"/>
		<updated>2010-03-19T05:55:20Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: A screenshot of the GUI using the Trace path and plotting in xy space.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A screenshot of the GUI using the Trace path and plotting in xy space.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18016</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18016"/>
		<updated>2010-03-19T05:54:43Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta.jpg|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY.jpg|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI.jpg|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:TraceTheta.jpg&amp;diff=18015</id>
		<title>File:TraceTheta.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:TraceTheta.jpg&amp;diff=18015"/>
		<updated>2010-03-19T05:53:42Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: Screenshot of GUI Trace when plotting theta v time.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of GUI Trace when plotting theta v time.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18012</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18012"/>
		<updated>2010-03-19T05:48:52Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[[Image: TraceTheta|thumb|150px|right]]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[[Image: TraceXY|thumb|150px|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image: CircleGUI|thumb|150px|right]]&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18010</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=18010"/>
		<updated>2010-03-19T05:48:18Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
[Image: TraceTheta|thumb|150px|right]&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
[Image: TraceXY|thumb|150px|right]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[Image: CircleGUI|thumb|150px|right}&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17984</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17984"/>
		<updated>2010-03-19T05:25:46Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png|thumb|300px|Electrical block diagram.|right]]&lt;br /&gt;
[[Image:2dof-hbridge.png|thumb|300px|H-bridge circuit and opto-isolators.|right]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
[http://www.youtube.com/watch?v=Ffun2e6hnVE This video] demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17979</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17979"/>
		<updated>2010-03-19T05:24:35Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png]]&lt;br /&gt;
[[Image:2dof-hbridge.png]]&lt;br /&gt;
&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
This video demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
[[File: 2dofArmDemo.mp4|frame|none|alt=alt text| Demonstration of the arm.]]&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17963</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17963"/>
		<updated>2010-03-19T04:51:11Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png]]&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
This video demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that the optointerrupters are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17962</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17962"/>
		<updated>2010-03-19T04:49:44Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
[[Image:2dof-interconnects.png]]&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  1&lt;br /&gt;
|  [[Introduction to the PIC32|Introduction to the PIC32]]&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.st.com/stonline/books/pdf/docs/1773.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Optoisolators   4N27&lt;br /&gt;
|  6&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Lite-On%20PDFs/4N27_28_.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Quadrature Up/Down decoders  LS7083&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://www.datasheetcatalog.com/datasheets_pdf/L/S/7/0/LS7083.shtml data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  QVB11134 Optointerrupters&lt;br /&gt;
|  2&lt;br /&gt;
|  [http://media.digikey.com/pdf/Data%20Sheets/Fairchild%20PDFs/QVB%20Series.pdf data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  35V 9A Schottkey Diodes   90SQ035-ND&lt;br /&gt;
|  8&lt;br /&gt;
|  [http://www.vishay.com/doc?93417 data sheet]&lt;br /&gt;
|-&lt;br /&gt;
|  Pittman GM8224 motor with 19.5:1 gearhead and 500 line encoder&lt;br /&gt;
|  2&lt;br /&gt;
|  [[Media:pittmangearmotor.pdf|data sheet]]&lt;br /&gt;
|-&lt;br /&gt;
|  24VDC 6A power supply&lt;br /&gt;
|  1&lt;br /&gt;
|  N/A&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
This video demonstration shows the capabilities of the arm.&lt;br /&gt;
&lt;br /&gt;
Before paths are executed, the arm is lifted manually so that optical sensors are tripped and the arm is &amp;quot;homed,&amp;quot; meaning that the PIC recognizes the arm&#039;s location with respect to motor encoder counts.&lt;br /&gt;
&lt;br /&gt;
The first path executed is a simple &amp;quot;Go To.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
After the &amp;quot;Go To,&amp;quot; a looped &amp;quot;Trace&amp;quot; path is executed. The GUI screenshot at the right was used to generate this path.  The top screenshot shows theta plotted against time and the bottom shows position plotted in xy space.&lt;br /&gt;
&lt;br /&gt;
The last two paths are both circles.  The first is a slow, wide circle rotating counter clockwise.  The second is a quicker, tighter circle rotating clockwise.  The GUI for the wide circle is at the right.&lt;br /&gt;
&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17943</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17943"/>
		<updated>2010-03-19T04:15:19Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right|link = Results]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  row 1, cell 2 &lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:2dofYoutubeLink.jpg&amp;diff=17942</id>
		<title>File:2dofYoutubeLink.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:2dofYoutubeLink.jpg&amp;diff=17942"/>
		<updated>2010-03-19T04:13:11Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: Image of youtube video (hopefully) linking to description at the bottom of the page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Image of youtube video (hopefully) linking to description at the bottom of the page.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17940</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=17940"/>
		<updated>2010-03-19T04:12:11Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:2dofYoutubeLink.jpg|right]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The Motors are mounted into right-angle pieces of aluminum via screws in the face-plate of the motors.  Each right angle has a slot milled into its base, and there is a flat aluminum base that also has a slot milled into it.  The right angles are secured to this base with bolts, nuts, and lock washers.  This slotted construction allows the position of the motors to be adjusted in order to ensure free movement of the arms.  &lt;br /&gt;
&lt;br /&gt;
Attached to each motor is a carbon fiber arm.  These arms are 1/2 inch thick carbon-nomex-carbon layups.  (Nomex is a material that provides rigidity to carbon fiber.)  Each arm has an aluminum block with a hole and set screw for mounting epoxied to one end.  One of these carbon fiber arms has a bearing mounted in it 10 inches away from the motor shaft, and the other has a pin mounted at the same distance.&lt;br /&gt;
&lt;br /&gt;
There are two other component to the parallelogram assembly.  One is a 22 inch by 1/2 inch length of carbon-nomex-carbon.  This piece has one pin mounted 1 inch away from one end, and another pin mounted 10 inches away from that.  The other piece is a 12 inch long piece of aluminum that has been bent into a 1 inch by in inch U-shape.  This piece has two ball-bearing epoxied into it 10 inches apart.&lt;br /&gt;
&lt;br /&gt;
The longer piece of carbon has the pin closest to its end press fit into the ball bearing mounted into the motor arm.  The U-shaped piece of aluminum has on ball bearing slid onto the other motor arm, and secured with a snap ring.  The remaining ball bearing is then slid onto the reaming pin in the long piece of carbon and secured with a snap ring.&lt;br /&gt;
&lt;br /&gt;
The position of the motors relative to one another in then adjusted unit the arms move freely, and then fastened in place.&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
Encoders for position feedback.&lt;br /&gt;
&lt;br /&gt;
Optical break sensor on each arm to establish absolute position&lt;br /&gt;
&lt;br /&gt;
===Components===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Electrical Components Needed.&lt;br /&gt;
!  Quantity&lt;br /&gt;
!  Data Sheets&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  PIC 32 on NU32 board&lt;br /&gt;
|  row 1, cell 2 &lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|-&lt;br /&gt;
|  H-bridges  L298&lt;br /&gt;
|  row 2, cell 2&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
There are two main applications: the C code that runs on the PIC and the MATLAB code that runs on a PC. The two applications communicate by sending command packets over a serial connection. The packets consist of a string of 16-bit integers. The first integer identifies the command and the following integers carry the parameters. This table shows the available commands. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+Commands&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Identifying Integer !! Description !! Number of following ints !! Syntax for following ints&lt;br /&gt;
|-&lt;br /&gt;
! C_HOLD&lt;br /&gt;
| 0 || Hold arm in home position || 2 || [ x_position y_position ]&lt;br /&gt;
|-&lt;br /&gt;
! C_FLOAT&lt;br /&gt;
| 1 || Stop and float motors || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_RUN&lt;br /&gt;
| 2 || Run path || 1 || [ true = 1 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_CONTROL_CONFIG&lt;br /&gt;
| 3 || Send new control parameters || 14 || [ KPnum1 KPden1 KDnum1 KDden1 KInum1 KIden1 Kslope1 KPnum2 KPden2 KDnum2 KDden2 KInum2 KIden2 Kslope2 ]&lt;br /&gt;
|-&lt;br /&gt;
! C_LOG_CONFIG&lt;br /&gt;
| 4 || Send new logging parameters (unimplemented) || 0 ||  --&lt;br /&gt;
|-&lt;br /&gt;
! C_SET_PATH&lt;br /&gt;
| 5 || Send new path points || variable || [ n time&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; time&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;3&amp;lt;/sub&amp;gt; ... time&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta1&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt; theta2&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;  ]&lt;br /&gt;
|-&lt;br /&gt;
! C_SEND_LOG&lt;br /&gt;
| 6 || Asks the PIC to send logged data || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_LOOP&lt;br /&gt;
| 7 || Sets the looping option || 1 || 0 = run once, 1 = loop the path &lt;br /&gt;
|-&lt;br /&gt;
! C_STARTSTOP&lt;br /&gt;
| 8 || start and stop (unimplemented) || 0 || -- &lt;br /&gt;
|-&lt;br /&gt;
! C_GOTO&lt;br /&gt;
| 9 || Tells the arm to goto a certain X,Y || 2 || [ X Y ]&lt;br /&gt;
|-&lt;br /&gt;
! C_PAUSE&lt;br /&gt;
| 10 || Stop and hold at current location || 0 || --&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For example, the vector that MATLAB sends to move the arm to X = 15, Y = -10 would be: [9 15 -10].&lt;br /&gt;
&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
[[Media:2dof-arm-v3-PIC.zip]]&lt;br /&gt;
&lt;br /&gt;
This code runs on the PIC 32 and handles the motor control, control loop, logging, and serial interface. On start up, the PIC runs the initialization routines, and then waits for the user to move the arm through each of the optical break sensors. When a break is detected on one of the sensors, the position of the corresponding arm is set to zero. This allows an absolute position to be established for each arm. Once the procedure is complete, the PIC waits for commands from the PC.&lt;br /&gt;
====Initialization====&lt;br /&gt;
* mInitAllLEDs() -- sets up the on board LEDs&lt;br /&gt;
* initPWMandIO() -- sets up digital IO pins for motors and more LEDs, sets up two analog to digital converters for the optical break sensors, configures the PWM modules and assigns them to Timer 3, and configures Timer3 at 20kHz&lt;br /&gt;
* initEncoder() -- Sets up Timers 1, 2, 4, and 5 as external counters for the encoders.&lt;br /&gt;
* initUART2(pbClk) -- Sets up UART2 for serial communication.&lt;br /&gt;
====Timed loop (2 kHz)====&lt;br /&gt;
What happens&lt;br /&gt;
====Serial Interrupt====&lt;br /&gt;
What happens&lt;br /&gt;
&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
[[Media:2dof-arm-v3-matlab.zip]]&lt;br /&gt;
&lt;br /&gt;
The MATLAB library consists of functions for each of the commands that can be sent to the PIC and some helper functions. When one of the callback functions from the GUI runs, it pulls parameters from the interface, assembles them, and passes them to the proper command functions.&lt;br /&gt;
&lt;br /&gt;
Within the arm command functions, MATLAB uses the &#039;&#039;fwrite&#039;&#039; function to write data to the serial port. The &#039;&#039;int16&#039;&#039; option ensures that MATLAB breaks each number into a 16 bit integer and sends it as two bytes out the serial port. The PIC will then reassemble these two bytes as a 16 bit integer.&lt;br /&gt;
&lt;br /&gt;
====Example MATLAB procedure====&lt;br /&gt;
Suppose the user wants move the arm to X = 15, Y = -10. The following happens:&lt;br /&gt;
# The user opens the GUI by running me333gui from the MATLAB command line&lt;br /&gt;
# The user puts the proper COM port in the COM port text box and clicks Connect&lt;br /&gt;
# The function &#039;&#039;Connect_Callback&#039;&#039; runs. This function pulls the text from COMport text box and sends it to the &#039;&#039;arm_connect&#039;&#039; function. The serial port is now open. The handle for the serial port object is stored in the UserData field.&lt;br /&gt;
# The user puts the desired X and Y in the goto X and Y text boxes, selects the GoTo radio button, and clicks Start.&lt;br /&gt;
# The function &#039;&#039;startButton_Callback&#039;&#039;. This function checks which of the mode radio buttons are selected. If GoTo is selected, it reads from the X and Y boxes, and calls the &#039;&#039;arm_goto&#039;&#039; function with the COM port handle and the X and Y from the text box.&lt;br /&gt;
# The arm receives the command and executes the move.&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16733</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16733"/>
		<updated>2010-03-15T00:52:25Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16731</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16731"/>
		<updated>2010-03-15T00:50:14Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etc.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=16727</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=16727"/>
		<updated>2010-03-15T00:45:49Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* High Speed Motor Control */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &#039;&#039;&#039;[[ME 333 end of course schedule]]&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&#039;&#039;&#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2010 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Sample Project Title]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
You can copy and paste this wiki code to start your wiki page (but don&#039;t erase this code).  Then replace this text with your own.  A few sentences describing what your project does, with a link to a youtube video.  Look at other final project wiki pages for ideas, but see [[ME 333 end of course schedule]] for more information on what should be included on your wiki page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ferrofluid Art Display]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Place holder text for caption .|right]]&lt;br /&gt;
&lt;br /&gt;
A little blurb about our Ferrofluid Art Display will go here. Just a few sentences talking about blah blah lkasjdfal hfalsdjh.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Can Launching Fridge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:27_Fridge|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
fridge info&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[High Speed Motor Control]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:2dofArmSetUp.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32. To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&#039;s Right Hand|right]]&lt;br /&gt;
Mozart&#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
This is a fully customizable display implemented using the concept of Persistence of Vision. User-specified images (and even moving images) were displayed by rotating a column of LEDs at speeds faster than 300rpm. Each individual LED was modeled as a row of pixels. Conversely, the rotational position of the panel of LEDs represented the pixel columns of the display; the time interval and rotational speed determined the width of the pixel columns. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Rock Paper Scissors Machine]] ===&lt;br /&gt;
[[Image:rps whole thing.JPG|thumb|150px|Rock Paper Scissors Machine|right]]&lt;br /&gt;
A machine that will play a fully functioning, intuitive game of [http://en.wikipedia.org/wiki/Rock-paper-scissors Rock/Paper/Scissors] (abbreviated as RPS) with a user. The machine is represented by a human-like hand, capable of seperate and independant wrist, arm, finger and thumb motion. The players&#039; hand goes into a glove equipped with flex sensors, which wirelessly transmits data to the machine based on what the player chose. The machine then reads this data, randomly chooses a throw of its own, and displays what the machine threw, what the human threw, total win/loss/tie info, and winner/loser both on an [http://en.wikipedia.org/wiki/Lcd LCD] screen and in the form of a thumbs up/down/side motion. Video of the machine in action can be found [http://www.youtube.com/watch?v=xbLNBSTTrcE here.]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot; A video can be found [http://www.youtube.com/watch?v=Y466dzP-qiY here].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
[[Image:Robot_Drummer.jpg|thumb|400pix|right|Robot Drummer]]&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
[[Image: MarionettePicForIntro.JPG|right|thumb]] The Marionette Project focused on using RC Servos to make a puppet that would do a dance with the press of a button.  There were 5 different dances programmed for the marionette, showcasing different styles of movement.  The movement had 2 degrees of freedom thanks to using 5 bar linkages and 2 RC servos for each arm.  Two more RC Servos were used on the back of the marionette to create the appearance of leg movement.  The movements included a Hula dance, Jumping Jacks, and even some moves right out of Saturday Night Fever.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
[[Image:monkeybot_pic|thumb|right|200px|Monkeybot]]&lt;br /&gt;
The monkeybot is a swinging robot capable of moving side to side and climbing.  It consists of a two link, double pendulum system with an electro-magnet on each end.  At the pivot is a DC motor, which provides an input torque and allows the swinging system to gain energy and climb.  Check out the video of the monkeybot climbing [http://www.youtube.com/watch?v=TA2VcH_GDJ0 here] and a later brachiation video [http://www.youtube.com/watch?v=0hfwJEVQyeQ&amp;amp;feature=related here].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
&lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
Featured on [http://blog.makezine.com/archive/2009/03/well_documented_robotic_snake.html Makezine.com].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &#039;Steel Toe&#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:2dofArmSetUp.jpg&amp;diff=16725</id>
		<title>File:2dofArmSetUp.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:2dofArmSetUp.jpg&amp;diff=16725"/>
		<updated>2010-03-15T00:42:48Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: Full view of all components for the project: the 2-DOF parallelogram robotic arm, computer and 24V power supply.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Full view of all components for the project: the 2-DOF parallelogram robotic arm, computer and 24V power supply.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=16724</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=16724"/>
		<updated>2010-03-15T00:41:43Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* High Speed Motor Control */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &#039;&#039;&#039;[[ME 333 end of course schedule]]&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&#039;&#039;&#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2010 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Sample Project Title]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
You can copy and paste this wiki code to start your wiki page (but don&#039;t erase this code).  Then replace this text with your own.  A few sentences describing what your project does, with a link to a youtube video.  Look at other final project wiki pages for ideas, but see [[ME 333 end of course schedule]] for more information on what should be included on your wiki page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ferrofluid Art Display]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Place holder text for caption .|right]]&lt;br /&gt;
&lt;br /&gt;
A little blurb about our Ferrofluid Art Display will go here. Just a few sentences talking about blah blah lkasjdfal hfalsdjh.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Can Launching Fridge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:27_Fridge|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
fridge info&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[High Speed Motor Control]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:2dofArmSetUp.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
intro statement about project goes here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&#039;s Right Hand|right]]&lt;br /&gt;
Mozart&#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
This is a fully customizable display implemented using the concept of Persistence of Vision. User-specified images (and even moving images) were displayed by rotating a column of LEDs at speeds faster than 300rpm. Each individual LED was modeled as a row of pixels. Conversely, the rotational position of the panel of LEDs represented the pixel columns of the display; the time interval and rotational speed determined the width of the pixel columns. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Rock Paper Scissors Machine]] ===&lt;br /&gt;
[[Image:rps whole thing.JPG|thumb|150px|Rock Paper Scissors Machine|right]]&lt;br /&gt;
A machine that will play a fully functioning, intuitive game of [http://en.wikipedia.org/wiki/Rock-paper-scissors Rock/Paper/Scissors] (abbreviated as RPS) with a user. The machine is represented by a human-like hand, capable of seperate and independant wrist, arm, finger and thumb motion. The players&#039; hand goes into a glove equipped with flex sensors, which wirelessly transmits data to the machine based on what the player chose. The machine then reads this data, randomly chooses a throw of its own, and displays what the machine threw, what the human threw, total win/loss/tie info, and winner/loser both on an [http://en.wikipedia.org/wiki/Lcd LCD] screen and in the form of a thumbs up/down/side motion. Video of the machine in action can be found [http://www.youtube.com/watch?v=xbLNBSTTrcE here.]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot; A video can be found [http://www.youtube.com/watch?v=Y466dzP-qiY here].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
[[Image:Robot_Drummer.jpg|thumb|400pix|right|Robot Drummer]]&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
[[Image: MarionettePicForIntro.JPG|right|thumb]] The Marionette Project focused on using RC Servos to make a puppet that would do a dance with the press of a button.  There were 5 different dances programmed for the marionette, showcasing different styles of movement.  The movement had 2 degrees of freedom thanks to using 5 bar linkages and 2 RC servos for each arm.  Two more RC Servos were used on the back of the marionette to create the appearance of leg movement.  The movements included a Hula dance, Jumping Jacks, and even some moves right out of Saturday Night Fever.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
[[Image:monkeybot_pic|thumb|right|200px|Monkeybot]]&lt;br /&gt;
The monkeybot is a swinging robot capable of moving side to side and climbing.  It consists of a two link, double pendulum system with an electro-magnet on each end.  At the pivot is a DC motor, which provides an input torque and allows the swinging system to gain energy and climb.  Check out the video of the monkeybot climbing [http://www.youtube.com/watch?v=TA2VcH_GDJ0 here] and a later brachiation video [http://www.youtube.com/watch?v=0hfwJEVQyeQ&amp;amp;feature=related here].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
&lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
Featured on [http://blog.makezine.com/archive/2009/03/well_documented_robotic_snake.html Makezine.com].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &#039;Steel Toe&#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=16723</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=16723"/>
		<updated>2010-03-15T00:40:36Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* ME 333 Final Projects 2010 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &#039;&#039;&#039;[[ME 333 end of course schedule]]&#039;&#039;&#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&#039;&#039;&#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2010 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Sample Project Title]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
You can copy and paste this wiki code to start your wiki page (but don&#039;t erase this code).  Then replace this text with your own.  A few sentences describing what your project does, with a link to a youtube video.  Look at other final project wiki pages for ideas, but see [[ME 333 end of course schedule]] for more information on what should be included on your wiki page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ferrofluid Art Display]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Place holder text for caption .|right]]&lt;br /&gt;
&lt;br /&gt;
A little blurb about our Ferrofluid Art Display will go here. Just a few sentences talking about blah blah lkasjdfal hfalsdjh.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Can Launching Fridge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:27_Fridge|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
fridge info&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[High Speed Motor Control]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
intro statement about project goes here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&#039;s Right Hand|right]]&lt;br /&gt;
Mozart&#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
This is a fully customizable display implemented using the concept of Persistence of Vision. User-specified images (and even moving images) were displayed by rotating a column of LEDs at speeds faster than 300rpm. Each individual LED was modeled as a row of pixels. Conversely, the rotational position of the panel of LEDs represented the pixel columns of the display; the time interval and rotational speed determined the width of the pixel columns. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Rock Paper Scissors Machine]] ===&lt;br /&gt;
[[Image:rps whole thing.JPG|thumb|150px|Rock Paper Scissors Machine|right]]&lt;br /&gt;
A machine that will play a fully functioning, intuitive game of [http://en.wikipedia.org/wiki/Rock-paper-scissors Rock/Paper/Scissors] (abbreviated as RPS) with a user. The machine is represented by a human-like hand, capable of seperate and independant wrist, arm, finger and thumb motion. The players&#039; hand goes into a glove equipped with flex sensors, which wirelessly transmits data to the machine based on what the player chose. The machine then reads this data, randomly chooses a throw of its own, and displays what the machine threw, what the human threw, total win/loss/tie info, and winner/loser both on an [http://en.wikipedia.org/wiki/Lcd LCD] screen and in the form of a thumbs up/down/side motion. Video of the machine in action can be found [http://www.youtube.com/watch?v=xbLNBSTTrcE here.]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot; A video can be found [http://www.youtube.com/watch?v=Y466dzP-qiY here].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
[[Image:Robot_Drummer.jpg|thumb|400pix|right|Robot Drummer]]&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
[[Image: MarionettePicForIntro.JPG|right|thumb]] The Marionette Project focused on using RC Servos to make a puppet that would do a dance with the press of a button.  There were 5 different dances programmed for the marionette, showcasing different styles of movement.  The movement had 2 degrees of freedom thanks to using 5 bar linkages and 2 RC servos for each arm.  Two more RC Servos were used on the back of the marionette to create the appearance of leg movement.  The movements included a Hula dance, Jumping Jacks, and even some moves right out of Saturday Night Fever.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
[[Image:monkeybot_pic|thumb|right|200px|Monkeybot]]&lt;br /&gt;
The monkeybot is a swinging robot capable of moving side to side and climbing.  It consists of a two link, double pendulum system with an electro-magnet on each end.  At the pivot is a DC motor, which provides an input torque and allows the swinging system to gain energy and climb.  Check out the video of the monkeybot climbing [http://www.youtube.com/watch?v=TA2VcH_GDJ0 here] and a later brachiation video [http://www.youtube.com/watch?v=0hfwJEVQyeQ&amp;amp;feature=related here].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
&lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
Featured on [http://blog.makezine.com/archive/2009/03/well_documented_robotic_snake.html Makezine.com].&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &#039;Steel Toe&#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16720</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16720"/>
		<updated>2010-03-15T00:35:08Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command to the user specified value in the GUI if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16718</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16718"/>
		<updated>2010-03-15T00:32:33Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Acknowledgements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;br /&gt;
We would like to acknowledge Professor Lynch, Nick Marchuk and Andy Long for their instruction and guidance throughout this project.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16716</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16716"/>
		<updated>2010-03-15T00:27:22Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16715</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16715"/>
		<updated>2010-03-15T00:26:40Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2-DOF) parallelogram robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16714</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16714"/>
		<updated>2010-03-15T00:03:53Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* GUI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16713</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16713"/>
		<updated>2010-03-14T23:15:06Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Team Members */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16712</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16712"/>
		<updated>2010-03-14T23:14:08Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Team Members */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg|thumb|300px|Sam, Ryan and Daniel with their robot.|right]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:DanSamRyanTeamPic.jpg&amp;diff=16711</id>
		<title>File:DanSamRyanTeamPic.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:DanSamRyanTeamPic.jpg&amp;diff=16711"/>
		<updated>2010-03-14T23:11:36Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: Team photo of Sam Bobb, Ryan Deeter and Daniel Cornew with their robot.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Team photo of Sam Bobb, Ryan Deeter and Daniel Cornew with their robot.&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16710</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16710"/>
		<updated>2010-03-14T23:10:34Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Team Members */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
[[Image:DanSamRyanTeamPic.jpg]]&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16709</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16709"/>
		<updated>2010-03-14T23:05:52Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16706</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16706"/>
		<updated>2010-03-14T22:38:58Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The GUI is made up of four main sections that allow a user to control the path and motor control parameters of the arm and plot the results.&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement with utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16705</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16705"/>
		<updated>2010-03-14T22:34:19Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the GUI (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement with utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16704</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16704"/>
		<updated>2010-03-14T22:29:08Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the guis (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This block of code is for the x-coordinate of the &amp;quot;Go To&amp;quot; path option.  The if statement with utilizes handles so that the &amp;quot;Go To&amp;quot; button&#039;s function can be accessed from the x-coordinate function.  This block sets the x-coordinate of the &amp;quot;Go To&amp;quot; command if the &amp;quot;Go To&amp;quot; button is selected.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16703</id>
		<title>High Speed Motor Control</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=High_Speed_Motor_Control&amp;diff=16703"/>
		<updated>2010-03-14T22:27:03Z</updated>

		<summary type="html">&lt;p&gt;RyanDeeter: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
The project suggested was to design a system for high speed motor control using the PIC 32.  To demonstrate the motor control, a two degree of freedom (2DOF) robot arm was designed to follow paths specified in a MATLAB gui.&lt;br /&gt;
&lt;br /&gt;
===Team Members===&lt;br /&gt;
*Sam Bobb (Electrical Engineering senior, left)&lt;br /&gt;
*Daniel Cornew (Mechanical Engineering junior, right)&lt;br /&gt;
*Ryan Deeter (Mechanical Engineering junior, middle)&lt;br /&gt;
&lt;br /&gt;
==Mechanical Design==&lt;br /&gt;
===Theory of Parallelogram Design===&lt;br /&gt;
====Equations of Motion====&lt;br /&gt;
Commanding the arm is much easier for a user to do in x- and y- coordinates than in motor angles or encoder counts.  Therefore, equations were required that would translate x- and y- coordinates into angles from horizontal and then into encoder counts.  Equations to express the reverse (encoder counts to angles to x- and y- coordinates) were also needed to evaluate the accuracy of the execution with respect to the command path.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x = L \cos (\theta_1)\ + \cos (\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; y = L \sin(\theta_1)\ + \sin(\theta_1+\alpha)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \alpha = cos^{-1} \left(\frac{x^2+y^2-L^2-(2L)^2}{2L^2} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_1 = \frac{-(2 L \sin(\alpha)) x + (L + 2 L \cos(\alpha)) y} {(2 L \sin(\alpha)) y + (L + 2 L \cos(\alpha)) x}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \theta_2 = \theta_1 + \alpha \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: &amp;lt;math&amp;gt;\alpha\,&amp;lt;/math&amp;gt; is used to calculate &amp;lt;math&amp;gt;\theta_{1,2}\,&amp;lt;/math&amp;gt; in the MATLAB code and is not ever sent to the PIC.&lt;br /&gt;
&lt;br /&gt;
===Materials and Construction===&lt;br /&gt;
The arm is constructed from aluminum and carbon fiber.  These materials were chosen due to their light weight and their availability. The extended link of the arm is made of carbon fiber, as are two of the other supporting links.  The final link is made from bent aluminum sheet because that link houses two bearings and removing&lt;br /&gt;
&lt;br /&gt;
==Electrical Design==&lt;br /&gt;
===Overview===&lt;br /&gt;
===Components===&lt;br /&gt;
===Circuit Diagram===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==GUI==&lt;br /&gt;
&lt;br /&gt;
The GUI used to control the arm was programmed in MATLAB using the &amp;quot;guide&amp;quot; function.  The GUI code calls the other MATLAB functions and is rather small as far as the amount of new code in contains.&lt;br /&gt;
&lt;br /&gt;
[insert screenshot of gui on the right]&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
The first section is the &amp;quot;Path&amp;quot; section, which allows users to specify the type of path the arm will follow.  There are currently three path choices: &amp;quot;go to,&amp;quot; &amp;quot;circle,&amp;quot; and &amp;quot;trace.&amp;quot;  The &amp;quot;go to&amp;quot; path allows the user to specify a point that the arm will go to from its current position in five seconds.  The &amp;quot;circle&amp;quot; path is determined through five values.  The first two are the (x, y) of the center of the circle.  The next two are coefficients on sin and cosine terms that are effectively the radii [CHECK THIS WITH SAM}.  The last value is the time in seconds for the arm to complete the circle.  In the final path, &amp;quot;trace,&amp;quot; users input four (x, y) positions and the arm moves from the first to the fourth and back to the first with two seconds in between points.  The GUI could easily be changed so that the user specifies (x, y, t) and controls the time between points, but this would require velocity-based failure checking in the code to ensure that the user did not give a command that was dangerous to the arm.&lt;br /&gt;
&lt;br /&gt;
The section just to the right of the &amp;quot;Path&amp;quot; section allows for further manipulation of the path and motor control.  A checkbox controls whether or not the specified path loops (note: &amp;quot;go to&amp;quot; cannot loop).   Beneath the checkbox is a section labeled &amp;quot;PID Control&amp;quot; and it lets users adjust the coefficients kp (proportional), ki (integral) and kd (derivative) on the fly by pressing the &amp;quot;Update&amp;quot; button.  &lt;br /&gt;
&lt;br /&gt;
The section on the far right is used to communicate between MATLAB and the PIC.  A COM port is specified for communication.  The &amp;quot;Connect&amp;quot; button opens the COM port, and the &amp;quot;Disconnect&amp;quot; button closes it.  The &amp;quot;Start&amp;quot; button runs whichever path is specified in the &amp;quot;Path&amp;quot; section, and &amp;quot;Pause&amp;quot; pauses the path (note: to unpause, click the &amp;quot;Start&amp;quot; button again while paused).&lt;br /&gt;
&lt;br /&gt;
The final section of the GUI is the &amp;quot;Graphs&amp;quot; section.  This section plots the path of the arm in either &amp;quot;theta vs t&amp;quot; or &amp;quot;x vs y,&amp;quot; as selected by the radio buttons.  Plotted in COLOR is the path that the PIC tried to execute, and the COLOR plot shows the actual path of the arm, for comparison.  INCLUDE SOMETHING ABOUT THE GET DATA AND CONTINUOUS LOG BUTTONS!&lt;br /&gt;
&lt;br /&gt;
===Code===&lt;br /&gt;
Using MATLAB&#039;s &amp;quot;guide&amp;quot; function when creating GUIs makes for rather straightforward coding.  When a component is added to the guis (be it a button, text field, etx.), MATLAB adds a block of code to an automatically generated m-file.  These blocks are functions, which means that programming them requires the use of handles.  Here is an example:&lt;br /&gt;
&lt;br /&gt;
    function xCoor_Callback(hObject, eventdata, handles)&lt;br /&gt;
    % hObject    handle to xCoor (see GCBO)&lt;br /&gt;
    % eventdata  reserved - to be defined in a future version of MATLAB&lt;br /&gt;
    % handles    structure with handles and user data (see GUIDATA)&lt;br /&gt;
    if get(handles.goToButton, &#039;Value&#039;) == 1&lt;br /&gt;
        xCoor = get(hObject, &#039;String&#039;);&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
===Overview===&lt;br /&gt;
===PIC C Code===&lt;br /&gt;
===MATLAB Code===&lt;br /&gt;
&lt;br /&gt;
==Results==&lt;br /&gt;
It was awesome.&lt;br /&gt;
==Next Steps==&lt;br /&gt;
&lt;br /&gt;
==Acknowledgements==&lt;/div&gt;</summary>
		<author><name>RyanDeeter</name></author>
	</entry>
</feed>