<?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=KrystianZimowski</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=KrystianZimowski"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/KrystianZimowski"/>
	<updated>2026-04-20T01:29:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17839</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17839"/>
		<updated>2010-03-18T22:34:03Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Reflections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:motor circuit.jpg|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation.  It resets when the length of the data array (num_data) is reached by the counter, iteration&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
//  All of these functions are documented in the LAB 4 information section&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked the first time we combined the mechanical and electrical parts together. The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|thumb|300 px|A working furuta pendulum captured in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
Overall, we had a successful execution of this project, because of the timeline we laid for ourselves. We broke down our project into many mechanical and electrical milestones so that we could test if parts of the pendulum were properly working before we put it all together and risk failure.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Successes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*Mechanical&lt;br /&gt;
**Milestone 1--The base of the pendulum was built and tested for stability, turning the motor on and off with various speeds. The base was mechanically robust.&lt;br /&gt;
**Milestone 2--The horizontal arm was attached to the motor shaft and the motor was run at different voltages and currents to test if it had enough torque to spin the arm around. The motor ultimately provided enough torque to spin the arm quickly and the base prevented the setup from tipping.&lt;br /&gt;
**Milestone 3--The vertical arm was set screwed to the horizontal shaft that was attached to the encoder and allowed to rotate freely via bearings. The whole setup was assembled together and tested for any shifting of mechanical parts that could affect the feedback control. Another mechanical block with a bearing was attached on the other side of the encoder to improve stability.&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
*Electrical&lt;br /&gt;
**Milestone 1--The circuit was constructed using an H-bridge in order to run the motor forward and reverse.&lt;br /&gt;
**Milestone 2--Position control was introduced so that the motor would run but maintain the same position, even with external forces acting upon it, such as a hand trying to turn it&lt;br /&gt;
**Milestone 3--The encoder was attached to the mechanical portion of the pendulum, so that it could read the position of the vertical arm&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Deterrents&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. &lt;br /&gt;
*We did not reach a point where we even truly considered trying to code a swing-up operation, which adds a lot of razzle dazzle but really complicates the code and there simply wasn&amp;#039;t enough time.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17838</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17838"/>
		<updated>2010-03-18T22:33:49Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Reflections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:motor circuit.jpg|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation.  It resets when the length of the data array (num_data) is reached by the counter, iteration&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
//  All of these functions are documented in the LAB 4 information section&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked the first time we combined the mechanical and electrical parts together. The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|thumb|300 px|A working furuta pendulum captured in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
Overall, we had a successful execution of this project, because of the timeline we laid for ourselves. We broke down our project into many mechanical and electrical milestones so that we could test if parts of the pendulum were properly working before we put it all together and risk failure.&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Successes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*Mechanical&lt;br /&gt;
**Milestone 1--The base of the pendulum was built and tested for stability, turning the motor on and off with various speeds. The base was mechanically robust.&lt;br /&gt;
**Milestone 2--The horizontal arm was attached to the motor shaft and the motor was run at different voltages and currents to test if it had enough torque to spin the arm around. The motor ultimately provided enough torque to spin the arm quickly and the base prevented the setup from tipping.&lt;br /&gt;
**Milestone 3--The vertical arm was set screwed to the horizontal shaft that was attached to the encoder and allowed to rotate freely via bearings. The whole setup was assembled together and tested for any shifting of mechanical parts that could affect the feedback control. Another mechanical block with a bearing was attached on the other side of the encoder to improve stability.&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
*Electrical&lt;br /&gt;
**Milestone 1--The circuit was constructed using an H-bridge in order to run the motor forward and reverse.&lt;br /&gt;
**Milestone 2--Position control was introduced so that the motor would run but maintain the same position, even with external forces acting upon it, such as a hand trying to turn it&lt;br /&gt;
**Milestone 3--The encoder was attached to the mechanical portion of the pendulum, so that it could read the position of the vertical arm&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Deterrents&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. &lt;br /&gt;
*We did not reach a point where we even truly considered trying to code a swing-up operation, which adds a lot of razzle dazzle but really complicates the code and there simply wasn&amp;#039;t enough time.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17791</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17791"/>
		<updated>2010-03-18T19:25:34Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Circuit */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:motor circuit.jpg|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation.  It resets when the length of the data array (num_data) is reached by the counter, iteration&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
//  All of these functions are documented in the LAB 4 information section&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked the first time we combined the mechanical and electrical parts together. The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|thumb|300 px|A working furuta pendulum captured in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Successes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
We broke down our project into many mechanical and electrical milestones so that we could test if parts of the pendulum were properly working before we put it all together and risk failure.&lt;br /&gt;
*Mechanical&lt;br /&gt;
**Milestone 1--The base of the pendulum was built and tested for stability, turning the motor on and off with various speeds. The base was mechanically robust.&lt;br /&gt;
**Milestone 2--The horizontal arm was attached to the motor shaft and the motor was run at different voltages and currents to test if it had enough torque to spin the arm around. The motor ultimately provided enough torque to spin the arm quickly and the base prevented the setup from tipping.&lt;br /&gt;
**Milestone 3--The vertical arm was set screwed to the horizontal shaft that was attached to the encoder and allowed to rotate freely via bearings. The whole setup was assembled together and tested for any shifting of mechanical parts that could affect the feedback control. Another mechanical block with a bearing was attached on the other side of the encoder to improve stability.&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
*Electrical&lt;br /&gt;
**Milestone 1--The circuit was constructed using an H-bridge in order to run the motor forward and reverse.&lt;br /&gt;
**Milestone 2--Position control was introduced so that the motor would run but maintain the same position, even with external forces acting upon it, such as a hand trying to turn it&lt;br /&gt;
**Milestone 3--The encoder was attached to the mechanical portion of the pendulum, so that it could read the position of the vertical arm&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Deterrents&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. &lt;br /&gt;
*We did not reach a point where we even truly considered trying to code a swing-up operation, which adds a lot of razzle dazzle but really complicates the code and there simply wasn&amp;#039;t enough time.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.jpg&amp;diff=17790</id>
		<title>File:Motor circuit.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.jpg&amp;diff=17790"/>
		<updated>2010-03-18T19:24:19Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: uploaded a new version of &amp;quot;Image:Motor circuit.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.jpg&amp;diff=17789</id>
		<title>File:Motor circuit.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.jpg&amp;diff=17789"/>
		<updated>2010-03-18T19:23:55Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.pdf&amp;diff=17772</id>
		<title>File:Motor circuit.pdf</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.pdf&amp;diff=17772"/>
		<updated>2010-03-18T17:02:13Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.png&amp;diff=17770</id>
		<title>File:Motor circuit.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Motor_circuit.png&amp;diff=17770"/>
		<updated>2010-03-18T17:01:55Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17768</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17768"/>
		<updated>2010-03-18T16:59:57Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Circuit */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:motor circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation.  It resets when the length of the data array (num_data) is reached by the counter, iteration&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
//  All of these functions are documented in the LAB 4 information section&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked the first time we combined the mechanical and electrical parts together. The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|thumb|300 px|A working furuta pendulum captured in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Successes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
We broke down our project into many mechanical and electrical milestones so that we could test if parts of the pendulum were properly working before we put it all together and risk failure.&lt;br /&gt;
*Mechanical&lt;br /&gt;
**Milestone 1--The base of the pendulum was built and tested for stability, turning the motor on and off with various speeds. The base was mechanically robust.&lt;br /&gt;
**Milestone 2--The horizontal arm was attached to the motor shaft and the motor was run at different voltages and currents to test if it had enough torque to spin the arm around. The motor ultimately provided enough torque to spin the arm quickly and the base prevented the setup from tipping.&lt;br /&gt;
**Milestone 3--The vertical arm was set screwed to the horizontal shaft that was attached to the encoder and allowed to rotate freely via bearings. The whole setup was assembled together and tested for any shifting of mechanical parts that could affect the feedback control. Another mechanical block with a bearing was attached on the other side of the encoder to improve stability.&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
*Electrical&lt;br /&gt;
**Milestone 1--The circuit was constructed using an H-bridge in order to run the motor forward and reverse.&lt;br /&gt;
**Milestone 2--Position control was introduced so that the motor would run but maintain the same position, even with external forces acting upon it, such as a hand trying to turn it&lt;br /&gt;
**Milestone 3--The encoder was attached to the mechanical portion of the pendulum, so that it could read the position of the vertical arm&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Deterrents&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. &lt;br /&gt;
*We did not reach a point where we even truly considered trying to code a swing-up operation, which adds a lot of razzle dazzle but really complicates the code and there simply wasn&amp;#039;t enough time.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17370</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17370"/>
		<updated>2010-03-17T17:48:22Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Reflections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked the first time we combined the mechanical and electrical parts together. The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|thumb|300 px|A working furuta pendulum captured in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Successes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
We broke down our project into many mechanical and electrical milestones so that we could test if parts of the pendulum were properly working before we put it all together and risk failure.&lt;br /&gt;
*Mechanical&lt;br /&gt;
**Milestone 1--The base of the pendulum was built and tested for stability, turning the motor on and off with various speeds. The base was mechanically robust.&lt;br /&gt;
**Milestone 2--The horizontal arm was attached to the motor shaft and the motor was run at different voltages and currents to test if it had enough torque to spin the arm around. The motor ultimately provided enough torque to spin the arm quickly and the base prevented the setup from tipping.&lt;br /&gt;
**Milestone 3--The vertical arm was set screwed to the horizontal shaft that was attached to the encoder and allowed to rotate freely via bearings. The whole setup was assembled together and tested for any shifting of mechanical parts that could affect the feedback control. Another mechanical block with a bearing was attached on the other side of the encoder to improve stability.&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
*Electrical&lt;br /&gt;
**Milestone 1--The circuit was constructed using an H-bridge in order to run the motor forward and reverse.&lt;br /&gt;
**Milestone 2--Position control was introduced so that the motor would run but maintain the same position, even with external forces acting upon it, such as a hand trying to turn it&lt;br /&gt;
**Milestone 3--The encoder was attached to the mechanical portion of the pendulum, so that it could read the position of the vertical arm&lt;br /&gt;
**Milestone 4--Working Pendulum!&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Deterrents&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. &lt;br /&gt;
*We did not reach a point where we even truly considered trying to code a swing-up operation, which adds a lot of razzle dazzle but really complicates the code and there simply wasn&amp;#039;t enough time.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17362</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17362"/>
		<updated>2010-03-17T17:16:38Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked the first time we combined the mechanical and electrical parts together. The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|thumb|300 px|A working furuta pendulum captured in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17360</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17360"/>
		<updated>2010-03-17T17:14:53Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|thumb|300 px|A working furuta pendulum captured in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Working_furuta.png&amp;diff=17358</id>
		<title>File:Working furuta.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Working_furuta.png&amp;diff=17358"/>
		<updated>2010-03-17T17:14:14Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17357</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17357"/>
		<updated>2010-03-17T17:13:58Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video] [[Image:working furuta.png|humb|300 px|A working furuta pendulum captures in motion|center]]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17355</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17355"/>
		<updated>2010-03-17T17:12:25Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Results */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple of alterations to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up. See the [http://www.youtube.com/watch?v=7DtFLKgNUk4 full demonstration video]&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17354</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17354"/>
		<updated>2010-03-17T17:08:43Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop. You can download the working version of the code [[Media:ME333_Lab2.c|here]]&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Furuta_code.c&amp;diff=17352</id>
		<title>File:Furuta code.c</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Furuta_code.c&amp;diff=17352"/>
		<updated>2010-03-17T17:02:36Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17351</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17351"/>
		<updated>2010-03-17T17:01:22Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
[[Image:wiring.png|thumb|200 px|Wiring for the pendulum enclosed inside the box.|right]]&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Working_pendulum.png&amp;diff=17350</id>
		<title>File:Working pendulum.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Working_pendulum.png&amp;diff=17350"/>
		<updated>2010-03-17T17:00:09Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Wiring.png&amp;diff=17349</id>
		<title>File:Wiring.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Wiring.png&amp;diff=17349"/>
		<updated>2010-03-17T16:59:47Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17348</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17348"/>
		<updated>2010-03-17T16:55:34Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17347</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17347"/>
		<updated>2010-03-17T16:52:45Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: /* Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17346</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17346"/>
		<updated>2010-03-17T16:46:18Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
The complete copy of the copy can be found below:&lt;br /&gt;
&lt;br /&gt;
/* &lt;br /&gt;
Team 12 Final Project&lt;br /&gt;
Furuta Pendulum&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/** INCLUDES ***************************************************/&lt;br /&gt;
#include &amp;quot;HardwareProfile.h&amp;quot;&lt;br /&gt;
//#include &amp;quot;HardwareProfileNU_32.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Constants **************************************************/&lt;br /&gt;
#define TRUE 					1&lt;br /&gt;
#define FALSE					0&lt;br /&gt;
&lt;br /&gt;
// PWM&lt;br /&gt;
#define ENABLE_PIN				LATAbits.LATA2&lt;br /&gt;
#define DIRECTION_PIN			LATAbits.LATA3&lt;br /&gt;
#define START_BUTTON			PORTFbits.RF2 // start program button&lt;br /&gt;
#define LOOP_TIME_PIN			LATAbits.LATA14&lt;br /&gt;
#define MAX_RESOLUTION			0x0F9F		// Proportional to period of PWM&lt;br /&gt;
&lt;br /&gt;
// Directions&lt;br /&gt;
#define FORWARD					0&lt;br /&gt;
#define REVERSE					1&lt;br /&gt;
&lt;br /&gt;
// RS232&lt;br /&gt;
#define DESIRED_BAUDRATE    	(19200)      // The desired BaudRate &lt;br /&gt;
#define NUM_DATA_POINTS 		640&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Function Declarations **************************************/&lt;br /&gt;
void initMotorPWM();&lt;br /&gt;
void initInterruptController();&lt;br /&gt;
void initEncoder(void);&lt;br /&gt;
int getEncoderPosition(void);&lt;br /&gt;
int getReference(int index);&lt;br /&gt;
unsigned int setPWMandDirection(signed int error);&lt;br /&gt;
unsigned int getPWMmagn(signed int error);&lt;br /&gt;
void initUART2(int pbClk);&lt;br /&gt;
void sendDataRS232(void);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Global Variables *******************************************/&lt;br /&gt;
// Encoder&lt;br /&gt;
signed int bigcount = 0; 	// set encoder value initially to zero, it can go + or -&lt;br /&gt;
						 	// 32 bit number&lt;br /&gt;
short last0 = 0, last1 = 0; // 16 bit number, prev tmr4 and tmr5&lt;br /&gt;
&lt;br /&gt;
// Controller&lt;br /&gt;
int globalIndex = 0;  // data point index&lt;br /&gt;
int refPeriod = 10000; // period in ms&lt;br /&gt;
int refAmplitude = 200; // in encoder counts&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int offset = 100; // feedback offset (dead zone)&lt;br /&gt;
int sum = 0;  //initialize value&lt;br /&gt;
int Kp = 240; //proportional gain was operating at 200&lt;br /&gt;
int Ki = 20;  //integral gain&lt;br /&gt;
int Kd = 30;  //derivative gain&lt;br /&gt;
&lt;br /&gt;
int num_data = 2;&lt;br /&gt;
int data_arr[2]; // 0 to num_data-1&lt;br /&gt;
int iteration = 10; // a 1.8deg change on a 500 quad encoder&lt;br /&gt;
int j;&lt;br /&gt;
	//encoder count goal - where the controller will attempt to hold the controller at&lt;br /&gt;
int goal = 0;&lt;br /&gt;
int current=0;&lt;br /&gt;
int movement=0;&lt;br /&gt;
int difference=0;&lt;br /&gt;
int anti_windup = 10;&lt;br /&gt;
&lt;br /&gt;
int error=0;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int encoderCounts[NUM_DATA_POINTS]; // initialize array to hold encoder data&lt;br /&gt;
int referenceData[NUM_DATA_POINTS]; // initialize array to hold reference data&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Main Function **********************************************/&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int	pbClk;&lt;br /&gt;
	//leave H Bridge off&lt;br /&gt;
	ENABLE_PIN = 0;&lt;br /&gt;
	//Set pin F2 to digital input&lt;br /&gt;
	TRISFbits.TRISF2 = 1;&lt;br /&gt;
	// Initialize board LEDs&lt;br /&gt;
	mInitAllLEDs();&lt;br /&gt;
&lt;br /&gt;
	// Initialize PWM&lt;br /&gt;
	initMotorPWM();&lt;br /&gt;
&lt;br /&gt;
	// Initialize encoder&lt;br /&gt;
	initEncoder();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	goal = 0;&lt;br /&gt;
	//initialize the velocity array to 0.&lt;br /&gt;
	data_arr[0]=0;&lt;br /&gt;
	data_arr[1]=0;&lt;br /&gt;
	while(1) // run forever&lt;br /&gt;
	{&lt;br /&gt;
		//resets loop index for derivative portion of control equation&lt;br /&gt;
		if (iteration &amp;gt; num_data)&lt;br /&gt;
			{iteration = 0;}&lt;br /&gt;
&lt;br /&gt;
		//get the current position from the encoder&lt;br /&gt;
		current = getEncoderPosition();		&lt;br /&gt;
		//Resets encoder position and turns on H bridge when star button is pressed&lt;br /&gt;
		if (START_BUTTON == 1)&lt;br /&gt;
		{&lt;br /&gt;
			ENABLE_PIN = 1;&lt;br /&gt;
			bigcount = 0;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		//turns off H bridge and thus motor if the pendulum wobbles too far.  Prevents a burn out from occurring&lt;br /&gt;
		if ((current &amp;gt; (49+goal)) &amp;amp;&amp;amp; (current &amp;lt; (goal-49)))&lt;br /&gt;
			{ENABLE_PIN = 0;}&lt;br /&gt;
&lt;br /&gt;
		//The guts of the program&lt;br /&gt;
		else if (ENABLE_PIN == 1)&lt;br /&gt;
		{&lt;br /&gt;
			//two values needed for the control equation&lt;br /&gt;
			error = goal - current;&lt;br /&gt;
			sum = sum + current;&lt;br /&gt;
			//stores last and current iteration of encoder position for derivative control&lt;br /&gt;
			data_arr[iteration] = current;&lt;br /&gt;
			&lt;br /&gt;
			//Anti wind-up parameters needed whenever using integral control&lt;br /&gt;
			if (sum&amp;gt;anti_windup)&lt;br /&gt;
				sum=anti_windup;&lt;br /&gt;
			if (sum&amp;lt;-anti_windup)&lt;br /&gt;
				sum = -anti_windup;&lt;br /&gt;
	&lt;br /&gt;
			//Actual control equation&lt;br /&gt;
			movement = Kp*error+Ki*sum+Kd*(abs(data_arr[0] - data_arr [1])); &lt;br /&gt;
			//makes sure hte movement is in bounds&lt;br /&gt;
			if (abs(movement) &amp;gt; MAX_RESOLUTION)&lt;br /&gt;
				movement = MAX_RESOLUTION;&lt;br /&gt;
			&lt;br /&gt;
			//to rotate the motor backwards, a different PWM is needed&lt;br /&gt;
			if (error &amp;lt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = REVERSE;&lt;br /&gt;
	 			SetDCOC1PWM(MAX_RESOLUTION-abs(movement));&lt;br /&gt;
			}&lt;br /&gt;
			//rotate the motor forwards&lt;br /&gt;
			if (error &amp;gt; 0 )&lt;br /&gt;
			{&lt;br /&gt;
				DIRECTION_PIN = FORWARD;&lt;br /&gt;
	 			SetDCOC1PWM(movement);&lt;br /&gt;
			}&lt;br /&gt;
			&lt;br /&gt;
			//move the counter for derivatrive control forward.&lt;br /&gt;
			iteration = iteration + 1;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	CloseOC1();&lt;br /&gt;
} //end main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/** Other Functions:  From Lab 4 ********************************************/&lt;br /&gt;
void initMotorPWM(void)&lt;br /&gt;
{&lt;br /&gt;
	//Set Enable, Direction and Loop Time Pins (A2, A3, A14) as digital outputs&lt;br /&gt;
	// Initialize as low&lt;br /&gt;
	LATA &amp;amp;= 0xBFF3; TRISA &amp;amp;= 0xBFF3;&lt;br /&gt;
	&lt;br /&gt;
	// init OC1 module, on pin D0&lt;br /&gt;
	OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);&lt;br /&gt;
	&lt;br /&gt;
	// init Timer2 mode and period (PR2) // set for 20kHz&lt;br /&gt;
	OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0x0F9F); //0F9F = 3999, prescale = 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void initEncoder(void)&lt;br /&gt;
{&lt;br /&gt;
	// init Timer4 and Timer5 mode and periods (PR4, PR5)&lt;br /&gt;
	OpenTimer4( T4_ON | T4_PS_1_1 | T4_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
	OpenTimer5( T5_ON | T5_PS_1_1 | T5_SOURCE_EXT, 0xFFFF); &lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
int getEncoderPosition()&lt;br /&gt;
{&lt;br /&gt;
	short count0 = ReadTimer4();  // in your routine this must be done at least every 32000 encoder counts to avoid rollover ambiguity&lt;br /&gt;
	short count1 = ReadTimer5(); 	&lt;br /&gt;
&lt;br /&gt;
	bigcount += count0 - last0; // add on the recent up-counts, since the last time&lt;br /&gt;
&lt;br /&gt;
	// check for rollover&lt;br /&gt;
	if (count0 &amp;lt; last0)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount += 65536; // count0 only increments, so if it got lower it must have rolled over&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last0 = count0;&lt;br /&gt;
&lt;br /&gt;
	bigcount -= count1 - last1; // we&amp;#039;re not worrying about rollover of the 32 bit bigcount total&lt;br /&gt;
&lt;br /&gt;
	if (count1 &amp;lt; last1)&lt;br /&gt;
	{&lt;br /&gt;
		bigcount -= 65536;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	last1 = count1; &lt;br /&gt;
&lt;br /&gt;
	return bigcount;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int getReference(int index)&lt;br /&gt;
{&lt;br /&gt;
	// get what reference signal should be given the globalindex&lt;br /&gt;
	if(index &amp;gt; refPeriod/2)&lt;br /&gt;
	{&lt;br /&gt;
		return refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return -refAmplitude;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int setPWMandDirection(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn;&lt;br /&gt;
	&lt;br /&gt;
	pwmMagn = getPWMmagn(error);&lt;br /&gt;
	&lt;br /&gt;
	if (error &amp;gt; 0) 					// Go Forward r &amp;gt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = FORWARD;&lt;br /&gt;
		mLED_2_On();&lt;br /&gt;
        SetDCOC1PWM(pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	else						// Go Reverse r &amp;lt; y&lt;br /&gt;
	{&lt;br /&gt;
		DIRECTION_PIN = REVERSE;&lt;br /&gt;
        mLED_2_Off();&lt;br /&gt;
		SetDCOC1PWM(MAX_RESOLUTION - pwmMagn);&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	return pwmMagn;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned int getPWMmagn(signed int error)&lt;br /&gt;
{&lt;br /&gt;
	unsigned int pwmMagn = abs(error) * Kp + offset; // Proportional Controller&lt;br /&gt;
&lt;br /&gt;
	// condition ? value if true : value if false&lt;br /&gt;
	return pwmMagn &amp;gt; MAX_RESOLUTION ? MAX_RESOLUTION : pwmMagn;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17345</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17345"/>
		<updated>2010-03-17T16:42:11Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum ultimately worked!  The vertical pendulum arm was kept upright by the horizontal adjustments of the arm attached to the motor shaft. It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
==Future Steps==&lt;br /&gt;
These would include optimization as mentioned above, and a “swing up” method.  A swing up method would benefit greatly from equations of motion for the system, but could probably be done by reversing swing direction when velocity is 0.  For this, I would recommend storing more than two data points, as we did.  For this project, 360 degrees of freedom is recommended for the apparatus.&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We managed to burn out one PIC chip when using a higher quality H-Bridge.  This was because of a wiring mistake that ran 12V through the 3.3V output, and into the connected laptop which caused a crash.  Fortunately, no permanent damage seems to be done to the laptop. We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17308</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17308"/>
		<updated>2010-03-17T08:23:54Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V. [[Image:furuta circuit.png|center]] The motor-encoder circuit can also be downloaded [http://hades.mech.northwestern.edu/images/f/fd/Motor_Encoder_circuit.pdf here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Furuta_circuit.png&amp;diff=17307</id>
		<title>File:Furuta circuit.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Furuta_circuit.png&amp;diff=17307"/>
		<updated>2010-03-17T08:20:48Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17306</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17306"/>
		<updated>2010-03-17T08:20:22Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
A PID controller for this project was chosen for multiple reasons.  Firstly, a PI controller (proportional and integral) was chosen.  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  The derivative term was added because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error it was found that 240*error+20*sum+30*velocity worked sufficiently for the purposes of the project.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All that was added was an input to the PIC triggered by a push button attached to 3.3V.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17304</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17304"/>
		<updated>2010-03-17T08:09:57Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - [http://www.cui.com/GetSpecForDigiKey.aspx?MFGNum=AME-1000V-600K AME 1000V 600k]&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
The main function needed to be achieved through the electrical design process was to control the motor speed and direction by reading the angular position of an encoder attached to the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
We decided upon a PID controller for multiple reasons.  Firstly, we decided upon a PI controller (proportional and integral).  The proportional term is a vital part to any controller, and the integral control is perfect for our desire of a steady state.  The integral term allows our motor to hold the pendulum vertical, and eventually balance it – whether or not the balancing uses the motor once a steady state is found depends on how well constructed the apparatus is.  If the pendulum has high friction and is evenly weighted, the controller will easily find a steady state.  We added the derivative term because we knew that how fast the pendulum is swinging should be factored into the controller in a predictive measure – rather than the purely responsive manner that a proportional response allows.&lt;br /&gt;
&lt;br /&gt;
===Control Law===&lt;br /&gt;
The control law we found is far from perfect.  Through trial and error we found that 240*error+20*sum+30*velocity worked sufficiently for our purposes.  In order to optimize this, many different methods could be employed.  For the best control law, a set of differential equations governing the movement of the pendulum (vertical arm) dependent upon the movement of the horizontal arm would be needed.  Less sophisticated methods would require the program randomly generating gains by itself, running the controller, and comparing the results in terms of watts used over time (or storing that data then sending it back to the PC).  This would allow a measure of refinement, but at essence is still trial and error.&lt;br /&gt;
&lt;br /&gt;
===Circuit===&lt;br /&gt;
Our circuit was nearly identical to the circuit diagram from the Mechatronics Lab 4.  All we added was an input to the PIC triggered by a push button attached to 3.3V.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
Most of our code is taken from lab 4.  We pared it down by removing all the RS232 communications functions, and decided to not use interrupts to run our control process, so all of those were removed.  We mainly added constants, and modified the code inside the while loop.  Our program runs completely inside the while loop, whereas lab 4 ran completely outside of the while loop.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17297</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17297"/>
		<updated>2010-03-17T07:55:55Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position. [http://www.youtube.com/watch?v=7DtFLKgNUk4 Click here for the final demonstration video.]&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - whatever model # it is&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The biggest issue to overcome was translating the rotation of the pendulum arm into a motion that the encoder could read and detect. Encoders are usually mounted on a motor shaft in order to measure its angular rotation and position, therefore a similar setup was needed. This was accomplished by attaching a horizontal shaft to the vertical pendulum arm and mounting it between two aluminum blocks that contained bearings, allowing for free rotation of the shaft. The encoder was mounted in between both blocks and was attached to the shaft. This way the encoder could detect the position of the vertical pendulum arm.&lt;br /&gt;
&lt;br /&gt;
The encoder shaft was set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
There were wires and stuff.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
It told the motor what to do.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17292</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17292"/>
		<updated>2010-03-17T07:42:28Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position.&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy. &lt;br /&gt;
 &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base sub-assembly to keep the motor upright and stabilize the pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
[[Image:horizontal arm.png|thumb|200 px|Horizontal arm attached to the motor shaft and lazy susan|right]]&lt;br /&gt;
[[Image:encoder.png|thumb|200 px|Encoder mounted in between two aluminum blocks with bearings|right]]&lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - whatever model # it is&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The same was done for the vertical arm, in this case for the encoder shaft.  The encoder shaft gets set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
[[Image:box.png|thumb|300 px|Box assembly to enclose the pendulum and provide mechanical stoppers on either side|right]]&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
There were wires and stuff.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
It told the motor what to do.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Horizontal_arm.png&amp;diff=17291</id>
		<title>File:Horizontal arm.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Horizontal_arm.png&amp;diff=17291"/>
		<updated>2010-03-17T07:34:59Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Box.png&amp;diff=17290</id>
		<title>File:Box.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Box.png&amp;diff=17290"/>
		<updated>2010-03-17T07:34:23Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Encoder.png&amp;diff=17289</id>
		<title>File:Encoder.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Encoder.png&amp;diff=17289"/>
		<updated>2010-03-17T07:33:14Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17287</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17287"/>
		<updated>2010-03-17T07:31:29Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position.&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy.  &lt;br /&gt;
[[Image:base.png|thumb|150 px|Base Sub-assembly|right]]&lt;br /&gt;
=== Base Assembly === &lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
=== Horizontal and Vertical Arm Assemblies ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - whatever model # it is&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of aluminum stock was press-fit into one end, and a hole was drilled through the arm for the motor shaft to slip in and another perpendicular to it for a set screw.  The same was done for the vertical arm, in this case for the encoder shaft.  The encoder shaft gets set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
There were wires and stuff.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
It told the motor what to do.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17286</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17286"/>
		<updated>2010-03-17T07:25:44Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position.&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy.  &lt;br /&gt;
&lt;br /&gt;
=== Base Assembly ===&lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman &lt;br /&gt;
&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
=== Arm Assembly ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings - [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - whatever model # it is&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of tubing was press-fit into one end, and a hole was drilled through it for the motor shaft and another for a set screw.  The same was done for the vertical arm, in this case for the encoder shaft.  The encoder shaft gets set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
There were wires and stuff.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
It told the motor what to do.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17285</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17285"/>
		<updated>2010-03-17T07:25:26Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm upright through horizontal rotation of the arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm. The PIC receives this information and controls the motor so as to move the horizontal arm in order to ultimately keep the pendulum in the vertical position.&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthew Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, light, and mechanically robust.  We wanted as light a design as possible because the motor we used was had no gearhead, so the torque was naturally going to be lower. We decided to use the motor with no gearhead to avoid any backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy.  &lt;br /&gt;
&lt;br /&gt;
=== Base Assembly ===&lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman &lt;br /&gt;
&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
=== Arm Assembly ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings [http://www.mcmaster.com/#5905k121/=69422o McMaster-Carr 1/4&amp;quot; ID 7/16&amp;quot; OD Needle Roller Bearings] &lt;br /&gt;
*Encoder - whatever model # it is&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of tubing was press-fit into one end, and a hole was drilled through it for the motor shaft and another for a set screw.  The same was done for the vertical arm, in this case for the encoder shaft.  The encoder shaft gets set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a band saw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, super-glued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
There were wires and stuff.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
It told the motor what to do.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Base.png&amp;diff=17284</id>
		<title>File:Base.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Base.png&amp;diff=17284"/>
		<updated>2010-03-17T07:25:07Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17280</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17280"/>
		<updated>2010-03-17T07:08:44Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm up through horizontal rotation of the horizontal arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm, and the PIC receiving that information and controlling the motor to keep the arm in the vertical position.&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|Inverted pendulum maintaining balance using feedback control|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthel Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, and very light.  We wanted as light a design as possible because the motor we used was ungeared (we wanted to avoid backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up) so the torque was naturally going to be lower.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy.  &lt;br /&gt;
&lt;br /&gt;
=== Base Assembly ===&lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman something or other&lt;br /&gt;
&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
=== Arm Assembly ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings&lt;br /&gt;
*Encoder - whatever model # it is&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of tubing was press-fit into one end, and a hole was drilled through it for the motor shaft and another for a set screw.  The same was done for the vertical arm, in this case for the encoder shaft.  The encoder shaft gets set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a bandsaw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, superglued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
There were wires and stuff.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
It told the motor what to do.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=17278</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=17278"/>
		<updated>2010-03-17T07:05:02Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#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;
&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&amp;#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;
=== [[Furuta Pendulum]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Picture 1.png|thumb|150px|Furuta Pendulum|right]]&lt;br /&gt;
&lt;br /&gt;
The Furuta pendulum, so named because it was first developed by Katsuhisa Furuta, is a rotational inverted pendulum.  In other words, the horizontal arm, which rotates in the horizontal plane, drives the movement of the vertical arm, which is free to rotate in the vertical plane.  Out objective was to build a Furuta pendulum that would hold the vertical arm up, as you can see from the [http://www.youtube.com/watch?v=7DtFLKgNUk4 demonstration video].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Music from the Heart -- Music Suit]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
This project attempted to create a natural form of musical expression by connecting sensors to the body.  Six tilt switches were attached to the wrist, ankles, and shoulders, each controlling a single pitch from the pentatonic scale.  The heart beat was obtained using photoplethysmography on the user&amp;#039;s finger, and this signal was used to strike a drum in sync with the heart beat.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Conservation of Angular Momentum Locomotion Robot (Fluffbot)]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Cute fluffy robot that uses conservation of angular momentum to move forward and backward. The robot&amp;#039;s momentum wheel accelerates in the floor-plane. The robot&amp;#039;s net angular momentum must remain zero-- a steering wheel guides the Fluffbot to accelerate in the opposite direction. This moves the robot forward in a curved path. The momentum wheel and steering wheel then change direction of acceleration. This repeated process moves the Fluffbot forward in a sinusoidal path.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Differential Drive Mobile Robot]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to create a small differential drive mobile robot that would act as a low cost replacement for the popular E-Puck Robot.  The robot uses hybrid stepper motors to allow it to track its position through odometry, has a laser cut acrylic chassis for easy replication and replacement, and a 1500 mAh, 13.2V battery pack for long run time.  The robot also uses the NU32 board for its control logic and a XBee chip for communication.&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.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of the can launching fridge was to create a fridge that would, when initiated by either a remote control or a wired push button, automatically load, aim, and fire a can to multiple predetermined locations. The fridge uses a combination of stepper motors, a DC motor, and solenoids to create the ultimate mix of convenience, fun, and refreshment. &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;
=== [[Variable Frequency Electrosense]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:TR_JP_PP-sensor.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Our objective was to build upon existing research being done at Northwestern utilizing Electrosense technology by testing if information can be derived from varying the emitter frequency. We sought to send sinusoidal waves at discrete frequencies between 100 Hz and 10 kHz and to read in the sensed wave using a PIC 32’s ADC. We then sent the gathered information to a PC for plotting and analysis. By mounting the sensor on a one dimensional linear actuator we are able to gather additional data about objects and perform object detection and identification algorithms. While our initial results have revealed exciting trends, farther research is necessary before any significant conclusions can be made. A [http://www.youtube.com/watch?v=PJY097L2m1M video] of the project is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Remote Controlled Wiitar]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
This project uses an array of solenoids to depress stings on the neck of a guitar.  A motor over the strings of the guitar turns an arm which strums the instrument, playing the chord depressed by the solenoids.  The system is controlled by a Wii Remote.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[6-DOF PPOD]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&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).&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&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&amp;#039;s Right Hand|right]]&lt;br /&gt;
Mozart&amp;#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&amp;#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&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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&amp;#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;
=== [[Butterfly Rolling Manipulation]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
The Butterfly emulates contact juggling by the stabilization of dynamic rolling.  The apparatus rolls a cylinder by rotating the &amp;quot;hand&amp;quot; using a specific trajectory and is able to move the cylinder from one side to the other without losing contact. A video of the Butterfly captured in high speed can be found [http://www.youtube.com/watch?v=hFafcjA_p7E here].&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;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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 &amp;#039;Steel Toe&amp;#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>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17276</id>
		<title>Furuta Pendulum</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Furuta_Pendulum&amp;diff=17276"/>
		<updated>2010-03-17T07:03:48Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
We were tasked with constructing and programming a [http://en.wikipedia.org/wiki/Furuta_pendulum Furuta pendulum], the goal of which is to hold the vertical arm up through horizontal rotation of the horizontal arm connected to the motor shaft.  Essentially, there were two separate projects: constructing the physical pendulum assembly, and programming the PIC to control the motor so the pendulum would function.  The basic mechanism consists of an encoder measuring the angle of rotation of the vertical arm, and the PIC receiving that information and controlling the motor to keep the arm in the vertical position.&lt;br /&gt;
[[Image:Furuta.png|thumb|300 px|center]]&lt;br /&gt;
=== Team Members ===&lt;br /&gt;
* Matthel Luther (Electrical Engineering, Class of 2010)&lt;br /&gt;
* Krystian Zimowski (Mechanical Engineering, Class of 2010)&lt;br /&gt;
* Gabriel Haack (Mechanical Engineering, Class of 2011)&lt;br /&gt;
&lt;br /&gt;
== Mechanical Design ==&lt;br /&gt;
There are three sections of the pendulum that can each be addressed separately: the base assembly with motor housing (including the motor itself); the arm assembly, which includes the horizontal arm, the vertical arm, and the encoder apparatus; and the box into which the whole pendulum was placed, including mechanical stops, the PIC and electrical circuitry, and a button to start the program.  Each section begins with a parts list; generic terms like &amp;quot;block&amp;quot; or &amp;quot;slab&amp;quot; indicate that these parts were made from aluminum scraps and can be just as effective with a different size or shape, or that they can be easily machined to fit any design.&lt;br /&gt;
&lt;br /&gt;
Aluminum was used for most parts because it was readily available, easy to machine, and very light.  We wanted as light a design as possible because the motor we used was ungeared (we wanted to avoid backlash since the pendulum requires rapid adjustments in motor position and direction to keep the vertical arm up) so the torque was naturally going to be lower.  However, we also wanted to minimize shaking from the pendulum operation, so the base had to be fairly heavy and sturdy.  &lt;br /&gt;
&lt;br /&gt;
=== Base Assembly ===&lt;br /&gt;
*Base - large aluminum block&lt;br /&gt;
*Support columns - 3/4&amp;quot; solid aluminum tubing&lt;br /&gt;
*Top platform - 1/4&amp;quot; acrylic&lt;br /&gt;
*Lazy susan - [http://www.mcmaster.com/#6031k2/=68z0to McMaster-Carr 4&amp;quot; Aluminum Turntable]&lt;br /&gt;
*Motor - Pittman something or other&lt;br /&gt;
&lt;br /&gt;
The aluminum block used was cylindrical: a hole was end-milled into the center to fit the encoder on the motor.  As you can see, the motor fits right in, preventing any rotation of the motor itself.  Two holes were drilled into the block on either side of the motor hole for the support columns, which were cut to be even with the top of the motor casing (not the motor shaft) once they were press-fit into the holes.  The tops of the columns were drilled and tapped.  Acrylic was cut to the size of the turntable and clearance holes were drilled to screw it to the motor, the support columns, and the turntable and a hole was cut in the center for the motor shaft.  Once the support columns were in place, the motor was placed in the base, the platform was screwed onto the motor and columns, and the turntable was screwed onto the platform.  &lt;br /&gt;
&lt;br /&gt;
=== Arm Assembly ===&lt;br /&gt;
*Horizontal arm - 3/4&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Vertical arm - 1/2&amp;quot; hollow aluminum tubing&lt;br /&gt;
*Press-fits for set screws - solid aluminum tubing with diameters equal to the inner diameter of the arms&lt;br /&gt;
*Weight - small aluminum block&lt;br /&gt;
*Bearing supports - flat aluminum slab&lt;br /&gt;
*Encoder shaft - machined solid aluminum tube&lt;br /&gt;
*Bearings&lt;br /&gt;
*Encoder - whatever model # it is&lt;br /&gt;
&lt;br /&gt;
The horizontal arm was cut to be long enough to stick out well past the edge of the turntable.  A short piece of tubing was press-fit into one end, and a hole was drilled through it for the motor shaft and another for a set screw.  The same was done for the vertical arm, in this case for the encoder shaft.  The encoder shaft gets set screwed onto and rotates with the vertical arm, providing a mechanism to send the angle of rotation back to the PIC.  As you can see, the horizontal arm was cut in half with a bandsaw for a length of the shaft sufficient to fit the encoder and both bearing supports.  To place the supports on the arm, the same tube used for the press-fit was machined to fit in the channel remaining after the top was sawed off.  One piece was placed where each of the bearing supports would be, superglued on, and end-milled to be perfectly flat on top.  Clearance holes were drilled in each piece and the bottom of the supports were drilled and tapped so they could be screwed onto the arm.  The bearings which support and stabilize the encoder shaft were press-fit into holes in the supports, and the encoder casing was screwed onto one of the supports.  The picture shows where each part is in relation to the others.  Meanwhile, the weight was drilled through so it would slide onto the vertical shaft, and a hole for a set screw was drilled and tapped.&lt;br /&gt;
&lt;br /&gt;
=== Box Assembly ===&lt;br /&gt;
*Box and top - plywood&lt;br /&gt;
*Dowel pins&lt;br /&gt;
*Rubber bumpers&lt;br /&gt;
*Paint&lt;br /&gt;
*Base stand - wooden blocks&lt;br /&gt;
&lt;br /&gt;
The box was not a critical part of the design in that it didn&amp;#039;t affect the pendulum itself, but it was very important for aesthetics, for providing mechanical stops, and keeping the project together in one compact design.  The box needed to be large enough to accommodate the electrical components, and the base stand elevated the pendulum so it wouldn&amp;#039;t interfere with the circuit.  Plywood was nailed together for the bottom and sides, and the top was machined so the pendulum was free to swing.  Dowel pins were placed on top of the sides to match with holes drilled in the top so once everything was ready, the top could be put on to protect the components inside.  The mechanical stops were glued onto the sides of the box with two set of bumpers: one for the pendulum to hit once it was on and in the vertical position and another to stop the horizontal arm if it was swinging out of control.  The wooden blocks used for base stand were screwed together and glued to the bottom of the box, and at the end the pendulum was epoxied to the top of the stand.  The entire box was painted before the pendulum was attached.&lt;br /&gt;
&lt;br /&gt;
== Electrical Design ==&lt;br /&gt;
There were wires and stuff.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
It told the motor what to do.&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The pendulum worked!  It took a couple adjustments to the code and electrical setup to get the motor to react the right way, and for some reason it only worked with a power supply, not when power was supplied from the PIC, but as the video shows, the motor does keep the vertical arm up.  Woohoo!&lt;br /&gt;
&lt;br /&gt;
== Reflections ==&lt;br /&gt;
We did not reach a point where we even truly considered trying to code a swing-up operation, which would have been really cool, but also really complicated and there simply wan&amp;#039;t enough time.  However, the physical pendulum is still intact, so if anyone would like to work with it I&amp;#039;m sure professor Lynch would be willing to let you try it out.&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Furuta.png&amp;diff=17271</id>
		<title>File:Furuta.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Furuta.png&amp;diff=17271"/>
		<updated>2010-03-17T07:00:07Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: uploaded a new version of &amp;quot;Image:Furuta.png&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Furuta.png&amp;diff=17269</id>
		<title>File:Furuta.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Furuta.png&amp;diff=17269"/>
		<updated>2010-03-17T06:59:11Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Furuta.JPG&amp;diff=17268</id>
		<title>File:Furuta.JPG</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Furuta.JPG&amp;diff=17268"/>
		<updated>2010-03-17T06:58:28Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=17265</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=17265"/>
		<updated>2010-03-17T06:56:07Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#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;
&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&amp;#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;
=== [[Furuta Pendulum]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Picture 1.png|thumb|150px|Furuta Pendulum.|right]]&lt;br /&gt;
&lt;br /&gt;
The Furuta pendulum, so named because it was first developed by Katsuhisa Furuta, is a rotational inverted pendulum.  In other words, the horizontal arm, which rotates in the horizontal plane, drives the movement of the vertical arm, which is free to rotate in the vertical plane.  Out objective was to build a Furuta pendulum that would hold the vertical arm up, as you can see from the [http://www.youtube.com/watch?v=7DtFLKgNUk4 demonstration video].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Music from the Heart -- Music Suit]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
This project attempted to create a natural form of musical expression by connecting sensors to the body.  Six tilt switches were attached to the wrist, ankles, and shoulders, each controlling a single pitch from the pentatonic scale.  The heart beat was obtained using photoplethysmography on the user&amp;#039;s finger, and this signal was used to strike a drum in sync with the heart beat.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Conservation of Angular Momentum Locomotion Robot (Fluffbot)]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Cute fluffy robot that uses conservation of angular momentum to move forward and backward. The robot&amp;#039;s momentum wheel accelerates in the floor-plane. The robot&amp;#039;s net angular momentum must remain zero-- a steering wheel guides the Fluffbot to accelerate in the opposite direction. This moves the robot forward in a curved path. The momentum wheel and steering wheel then change direction of acceleration. This repeated process moves the Fluffbot forward in a sinusoidal path.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Differential Drive Mobile Robot]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to create a small differential drive mobile robot that would act as a low cost replacement for the popular E-Puck Robot.  The robot uses hybrid stepper motors to allow it to track its position through odometry, has a laser cut acrylic chassis for easy replication and replacement, and a 1500 mAh, 13.2V battery pack for long run time.  The robot also uses the NU32 board for its control logic and a XBee chip for communication.&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.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of the can launching fridge was to create a fridge that would, when initiated by either a remote control or a wired push button, automatically load, aim, and fire a can to multiple predetermined locations. The fridge uses a combination of stepper motors, a DC motor, and solenoids to create the ultimate mix of convenience, fun, and refreshment. &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;
=== [[Variable Frequency Electrosense]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:TR_JP_PP-sensor.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Our objective was to build upon existing research being done at Northwestern utilizing Electrosense technology by testing if information can be derived from varying the emitter frequency. We sought to send sinusoidal waves at discrete frequencies between 100 Hz and 10 kHz and to read in the sensed wave using a PIC 32’s ADC. We then sent the gathered information to a PC for plotting and analysis. By mounting the sensor on a one dimensional linear actuator we are able to gather additional data about objects and perform object detection and identification algorithms. While our initial results have revealed exciting trends, farther research is necessary before any significant conclusions can be made. A [http://www.youtube.com/watch?v=PJY097L2m1M video] of the project is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Remote Controlled Wiitar]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
This project uses an array of solenoids to depress stings on the neck of a guitar.  A motor over the strings of the guitar turns an arm which strums the instrument, playing the chord depressed by the solenoids.  The system is controlled by a Wii Remote.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[6-DOF PPOD]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&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).&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&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&amp;#039;s Right Hand|right]]&lt;br /&gt;
Mozart&amp;#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&amp;#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&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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&amp;#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;
=== [[Butterfly Rolling Manipulation]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
The Butterfly emulates contact juggling by the stabilization of dynamic rolling.  The apparatus rolls a cylinder by rotating the &amp;quot;hand&amp;quot; using a specific trajectory and is able to move the cylinder from one side to the other without losing contact. A video of the Butterfly captured in high speed can be found [http://www.youtube.com/watch?v=hFafcjA_p7E here].&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;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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 &amp;#039;Steel Toe&amp;#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>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=17264</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=17264"/>
		<updated>2010-03-17T06:55:31Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#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;
&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&amp;#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;
=== [[Furuta Pendulum]] ===&lt;br /&gt;
&lt;br /&gt;
[[[[Image:Picture 1.png]]|thumb|150px|Furuta Pendulum.|right]]&lt;br /&gt;
&lt;br /&gt;
The Furuta pendulum, so named because it was first developed by Katsuhisa Furuta, is a rotational inverted pendulum.  In other words, the horizontal arm, which rotates in the horizontal plane, drives the movement of the vertical arm, which is free to rotate in the vertical plane.  Out objective was to build a Furuta pendulum that would hold the vertical arm up, as you can see from the [http://www.youtube.com/watch?v=7DtFLKgNUk4 demonstration video].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Music from the Heart -- Music Suit]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
This project attempted to create a natural form of musical expression by connecting sensors to the body.  Six tilt switches were attached to the wrist, ankles, and shoulders, each controlling a single pitch from the pentatonic scale.  The heart beat was obtained using photoplethysmography on the user&amp;#039;s finger, and this signal was used to strike a drum in sync with the heart beat.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Conservation of Angular Momentum Locomotion Robot (Fluffbot)]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Cute fluffy robot that uses conservation of angular momentum to move forward and backward. The robot&amp;#039;s momentum wheel accelerates in the floor-plane. The robot&amp;#039;s net angular momentum must remain zero-- a steering wheel guides the Fluffbot to accelerate in the opposite direction. This moves the robot forward in a curved path. The momentum wheel and steering wheel then change direction of acceleration. This repeated process moves the Fluffbot forward in a sinusoidal path.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Differential Drive Mobile Robot]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to create a small differential drive mobile robot that would act as a low cost replacement for the popular E-Puck Robot.  The robot uses hybrid stepper motors to allow it to track its position through odometry, has a laser cut acrylic chassis for easy replication and replacement, and a 1500 mAh, 13.2V battery pack for long run time.  The robot also uses the NU32 board for its control logic and a XBee chip for communication.&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.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of the can launching fridge was to create a fridge that would, when initiated by either a remote control or a wired push button, automatically load, aim, and fire a can to multiple predetermined locations. The fridge uses a combination of stepper motors, a DC motor, and solenoids to create the ultimate mix of convenience, fun, and refreshment. &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;
=== [[Variable Frequency Electrosense]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:TR_JP_PP-sensor.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Our objective was to build upon existing research being done at Northwestern utilizing Electrosense technology by testing if information can be derived from varying the emitter frequency. We sought to send sinusoidal waves at discrete frequencies between 100 Hz and 10 kHz and to read in the sensed wave using a PIC 32’s ADC. We then sent the gathered information to a PC for plotting and analysis. By mounting the sensor on a one dimensional linear actuator we are able to gather additional data about objects and perform object detection and identification algorithms. While our initial results have revealed exciting trends, farther research is necessary before any significant conclusions can be made. A [http://www.youtube.com/watch?v=PJY097L2m1M video] of the project is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Remote Controlled Wiitar]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
This project uses an array of solenoids to depress stings on the neck of a guitar.  A motor over the strings of the guitar turns an arm which strums the instrument, playing the chord depressed by the solenoids.  The system is controlled by a Wii Remote.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[6-DOF PPOD]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&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).&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&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&amp;#039;s Right Hand|right]]&lt;br /&gt;
Mozart&amp;#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&amp;#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&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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&amp;#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;
=== [[Butterfly Rolling Manipulation]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
The Butterfly emulates contact juggling by the stabilization of dynamic rolling.  The apparatus rolls a cylinder by rotating the &amp;quot;hand&amp;quot; using a specific trajectory and is able to move the cylinder from one side to the other without losing contact. A video of the Butterfly captured in high speed can be found [http://www.youtube.com/watch?v=hFafcjA_p7E here].&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;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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 &amp;#039;Steel Toe&amp;#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>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Picture_1.png&amp;diff=17263</id>
		<title>File:Picture 1.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Picture_1.png&amp;diff=17263"/>
		<updated>2010-03-17T06:54:44Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Entire_setup.jpg&amp;diff=17259</id>
		<title>File:Entire setup.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Entire_setup.jpg&amp;diff=17259"/>
		<updated>2010-03-17T06:46:52Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: uploaded a new version of &amp;quot;Image:Entire setup.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Entire_setup.jpg&amp;diff=17258</id>
		<title>File:Entire setup.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Entire_setup.jpg&amp;diff=17258"/>
		<updated>2010-03-17T06:45:43Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: uploaded a new version of &amp;quot;Image:Entire setup.jpg&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Entire_setup.jpg&amp;diff=17257</id>
		<title>File:Entire setup.jpg</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Entire_setup.jpg&amp;diff=17257"/>
		<updated>2010-03-17T06:43:40Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=17254</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=17254"/>
		<updated>2010-03-17T06:37:20Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#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;
&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&amp;#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;
=== [[Furuta Pendulum]] ===&lt;br /&gt;
&lt;br /&gt;
[[[[Image:Example.jpg]]|thumb|150px|Furuta Pendulum.|right]]&lt;br /&gt;
&lt;br /&gt;
The Furuta pendulum, so named because it was first developed by Katsuhisa Furuta, is a rotational inverted pendulum.  In other words, the horizontal arm, which rotates in the horizontal plane, drives the movement of the vertical arm, which is free to rotate in the vertical plane.  Out objective was to build a Furuta pendulum that would hold the vertical arm up, as you can see from the [http://www.youtube.com/watch?v=7DtFLKgNUk4 demonstration video].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Music from the Heart -- Music Suit]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
This project attempted to create a natural form of musical expression by connecting sensors to the body.  Six tilt switches were attached to the wrist, ankles, and shoulders, each controlling a single pitch from the pentatonic scale.  The heart beat was obtained using photoplethysmography on the user&amp;#039;s finger, and this signal was used to strike a drum in sync with the heart beat.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Conservation of Angular Momentum Locomotion Robot (Fluffbot)]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Cute fluffy robot that uses conservation of angular momentum to move forward and backward. The robot&amp;#039;s momentum wheel accelerates in the floor-plane. The robot&amp;#039;s net angular momentum must remain zero-- a steering wheel guides the Fluffbot to accelerate in the opposite direction. This moves the robot forward in a curved path. The momentum wheel and steering wheel then change direction of acceleration. This repeated process moves the Fluffbot forward in a sinusoidal path.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Differential Drive Mobile Robot]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to create a small differential drive mobile robot that would act as a low cost replacement for the popular E-Puck Robot.  The robot uses hybrid stepper motors to allow it to track its position through odometry, has a laser cut acrylic chassis for easy replication and replacement, and a 1500 mAh, 13.2V battery pack for long run time.  The robot also uses the NU32 board for its control logic and a XBee chip for communication.&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.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of the can launching fridge was to create a fridge that would, when initiated by either a remote control or a wired push button, automatically load, aim, and fire a can to multiple predetermined locations. The fridge uses a combination of stepper motors, a DC motor, and solenoids to create the ultimate mix of convenience, fun, and refreshment. &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;
=== [[Variable Frequency Electrosense]] ===&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&amp;#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;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Remote Controlled Wiitar]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
This project uses an array of solenoids to depress stings on the neck of a guitar.  A motor over the strings of the guitar turns an arm which strums the instrument, playing the chord depressed by the solenoids.  The system is controlled by a Wii Remote.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[6-DOF PPOD]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&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).&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&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&amp;#039;s Right Hand|right]]&lt;br /&gt;
Mozart&amp;#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&amp;#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&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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&amp;#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;
=== [[Butterfly Rolling Manipulation]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
The Butterfly emulates contact juggling by the stabilization of dynamic rolling.  The apparatus rolls a cylinder by rotating the &amp;quot;hand&amp;quot; using a specific trajectory and is able to move the cylinder from one side to the other without losing contact. A video of the Butterfly captured in high speed can be found [http://www.youtube.com/watch?v=hFafcjA_p7E here].&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;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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 &amp;#039;Steel Toe&amp;#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>KrystianZimowski</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=17253</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=17253"/>
		<updated>2010-03-17T06:35:31Z</updated>

		<summary type="html">&lt;p&gt;KrystianZimowski: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#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;
&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&amp;#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;
=== [[Furuta Pendulum]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The Furuta pendulum, so named because it was first developed by Katsuhisa Furuta, is a rotational inverted pendulum.  In other words, the horizontal arm, which rotates in the horizontal plane, drives the movement of the vertical arm, which is free to rotate in the vertical plane.  Out objective was to build a Furuta pendulum that would hold the vertical arm up, as you can see from the [http://www.youtube.com/watch?v=7DtFLKgNUk4 demonstration video].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Music from the Heart -- Music Suit]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
This project attempted to create a natural form of musical expression by connecting sensors to the body.  Six tilt switches were attached to the wrist, ankles, and shoulders, each controlling a single pitch from the pentatonic scale.  The heart beat was obtained using photoplethysmography on the user&amp;#039;s finger, and this signal was used to strike a drum in sync with the heart beat.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Conservation of Angular Momentum Locomotion Robot (Fluffbot)]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
Cute fluffy robot that uses conservation of angular momentum to move forward and backward. The robot&amp;#039;s momentum wheel accelerates in the floor-plane. The robot&amp;#039;s net angular momentum must remain zero-- a steering wheel guides the Fluffbot to accelerate in the opposite direction. This moves the robot forward in a curved path. The momentum wheel and steering wheel then change direction of acceleration. This repeated process moves the Fluffbot forward in a sinusoidal path.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Differential Drive Mobile Robot]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of this project was to create a small differential drive mobile robot that would act as a low cost replacement for the popular E-Puck Robot.  The robot uses hybrid stepper motors to allow it to track its position through odometry, has a laser cut acrylic chassis for easy replication and replacement, and a 1500 mAh, 13.2V battery pack for long run time.  The robot also uses the NU32 board for its control logic and a XBee chip for communication.&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.jpg|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
&lt;br /&gt;
The goal of the can launching fridge was to create a fridge that would, when initiated by either a remote control or a wired push button, automatically load, aim, and fire a can to multiple predetermined locations. The fridge uses a combination of stepper motors, a DC motor, and solenoids to create the ultimate mix of convenience, fun, and refreshment. &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;
=== [[Variable Frequency Electrosense]] ===&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&amp;#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;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Remote Controlled Wiitar]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&lt;br /&gt;
This project uses an array of solenoids to depress stings on the neck of a guitar.  A motor over the strings of the guitar turns an arm which strums the instrument, playing the chord depressed by the solenoids.  The system is controlled by a Wii Remote.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[6-DOF PPOD]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Persistence of Vison Display|thumb|150px|Project photo caption.|right]]&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).&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&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&amp;#039;s Right Hand|right]]&lt;br /&gt;
Mozart&amp;#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&amp;#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&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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&amp;#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;
=== [[Butterfly Rolling Manipulation]] ===&lt;br /&gt;
[[Image:Persistence of Vison Display|right|thumb|150px]]&lt;br /&gt;
The Butterfly emulates contact juggling by the stabilization of dynamic rolling.  The apparatus rolls a cylinder by rotating the &amp;quot;hand&amp;quot; using a specific trajectory and is able to move the cylinder from one side to the other without losing contact. A video of the Butterfly captured in high speed can be found [http://www.youtube.com/watch?v=hFafcjA_p7E here].&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;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#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 &amp;#039;Steel Toe&amp;#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>KrystianZimowski</name></author>
	</entry>
</feed>