Lab Report #1: Spice Games



Hsiang Wei Lee (hl336)

Weisheng Winson Lin (wl228)

Thursday, 1:25

Final Project

Automated Swing Robot

May. 4, 2006

Introduction

Everyone has played the playground swing since young at a point of time. So our final project will be to design a robot to simulate the swinging motion that brings us lots of joy during our childhood. The robot will extend and retract the leg while sitting on the swing. By using simple physics, the robot will swing on its own from rest to an angle of 90°. There is also an interface such that the robot can be switched to manual mode whereby a volunteer can attempt to swing it himself.

High Level Design

Rationale

This project was suggested during lecture by our Professor as he mentioned that a “swing robot” would be a cool final project. We liked the idea suggested by him and we modified it to suit the purposes of this project.

The Physics

So what is the physics behind the swing? Since not everyone is a physicist, we will attempt to explain the motion using some simple physics. The swing works just like a pendulum, the period is only affected by the length of the rod holding the swing and gravity that we cannot really change. Therefore, we need to find some ways to change the amplitude of the swing arc.

One method to increase the amplitude is to create an addition forward momentum at the top of a swing arc. This can be done by swinging the legs forward when coming down from the top of the arc and retracting the legs backward when backing down from the other end of the arc. Assuming the loss of momentum to drag and friction is less than the momentum added in by the peak of the swing arc, the amplitude will increase with every swing.

The basic concept to increasing the amplitude is resonance. As the swing will be oscillating up and down at a certain frequency, the objective is to impart the external force into the system at the natural frequency. By doing so, the amplitude will increase with every swing.

Logical Structure

Using the physics as discussed above, we will attempt to create a robot capable of swinging from rest. The basic structure can be summarized with the block diagram as shown below. A detailed schematic of the project can be found in the appendix.

Figure 1. Block diagram

The Mega32 chip will be the ‘brain’ of the robot. It will be in-charged of moving the leg, which is the motor, so as to increase the amplitude of the swing. The ‘eyes’ of the robot will be the accelerometer that will be used to detect the peak of the swing arc. The movement of the legs will be coordinated so as to simulate a human being swinging as described above. The push buttons will allow human interaction with the system.

Hardware/Program Design

The design can be broken down into two parts: the hardware section and the program section. The hardware design will include the pushbuttons/switch, accelerometer and servo motor. The program design will explain how the Atmel32 chip coordinates the input and output of the hardware so as to start the swing from rest and maintain the amplitude. A picture of the custom board with all attached devices is shown below in Figure 2:

[pic]

Figure 2. Custom Board with all attached devices

Push Buttons/Switch

There are two objectives to this project. One is to create an autonomous robot that can swing itself from rest. The other is to allow a volunteer to play with the robot. Therefore, a switchbox is set up with three push buttons and one switch. The switch will turn on the robot system and the buttons will allow interaction with the robot. It can be seen below in Figure 3.

[pic]

Figure 3. Switchbox

The three buttons serve the following functions.

• Button 1: Get into auto swing mode. The robot will start swinging from rest and maintain the swing amplitude.

• Button 2: Get into manual mode. The robot will stop swinging so as to allow human operation of the leg motor.

• Button 3: Control for the leg motor. This button is only in effect when in manual mode. Pressing the button will result in the leg being extended. Releasing the button will result in the leg being tucked in.

The default state is manual mode.

The buttons are debounced using the similar code structure that was used in the labs done over the semester. Debouncing the buttons is important as the buttons not only controls the mode of the swing, but it also controls the servo motor directly. If the buttons are not debounced, the servo will not be able to transit between the two positions smoothly, resulting in a significant amount of mechanical noise in the setup which affects the proper functioning of the accelerometer.

Accelerometer

The accelerometer is used to detect the peak of the swing arc so that the robot can decide when to kick the leg. A donated z-axis accelerometer MMA1260D from Freescale is used to detect the acceleration in the z-axis. The three ports of the accelerometer are ground, power supply and output. The output is connected to a 100µF capacitor to reduce the noise.

Connecting the accelerometer to an oscilloscope, the output of the accelerometer is a sine wave whereby the peak of the swing arc will coincide with the peak of the sine curve. Using this as the motivation of the detection of the peak, a simple algorithm is written to determine the peak of each swing arc.

The output is connected to the ADC0 and is sampled every 40ms. The previous ADC value is stored and compared to the current ADC value. If the current value is greater than the previous one, a counter is incremented until a max number which determines the sensitivity of the peak detection. If the current value is lower than the previous one, the counter is decremented. The peak of the arc is detected when the counter is maxed and the current ADC value is less than the previous ADC value.

The accelerometer can be seen below in Figure 4.

[pic]

Figure 4. Accelerometer

Servo Motor

The servo motor is used in this robot to impart energy into the system. This part was purchased from Acroname at the cost of $10.90. The servo is a pre-modified potentiometer to adjust the center position and the specification is as shown below:

Specifications:

Size: 1.55 x 1.40 x 0.79in.

Weight: 1.48oz.

4.8-6v Speed: 0.23-.18 sec/60°

4.8-6v Torque: 47-56 oz- in.

The servo motor has 3 leads – GND, POWER and SIGNAL. The GND lead connects to the MCU ground, and a 5V potential difference is applied across the POWER and GND leads. The SIGNAL lead is connected to PORTD7 which is OCR2 which generates a PWM signal using timer2 of the Mega32.

To ensure that the servo motor can impart enough energy to the system, a weight of significant mass has to be attached to the servo motor which acts as the robots leg. The weight for this robot is a stack of 60 quarters, worth a total of $15.00. A figure of the servo motor attached with the weight is shown below.

[pic]

Figure 5. Servo Motor with the weight

Power Supply

For this project, power supplies of 5V (for the servo motor) and 12V (for the custom board) are needed. The servo motor cannot be powered off the VCC on the custom board as the servo motor draws too much current then the voltage regulator mounted on the custom board as provide. Hence, the project uses the power supply which has outputs of both 5V and 12V. An image of the power supply is shown below on Figure 6.

[pic]

Figure 6. Power Supply

Program Design

Using the input of the accelerometer, the servo motor has to be controlled such that the robot is able to swing itself from rest to the maximum amplitude and then maintain the amplitude. The program design can be broken down into two parts: swinging from rest and maintaining the swing.

Swinging from rest is difficult for the robot because it cannot push off the ground like what we usually do at the playground swing. Therefore, we have to make use of the principles of resonance to swing from rest. Furthermore, the accelerometer is not sensitive enough to detect a change if the change in amplitude is small. Therefore, by swinging the robot from rest at the natural frequency, the amplitude will add up with every swing until it is high enough for the accelerometer to detect the motion. So, we have to first determine the natural frequency of the swing.

We do this manually by swinging legs at a certain speed such that the amplitude adds up. By determining the period of each swing such that the amplitude will add up, we can determine the natural frequency. However, the natural frequency changes with amplitude. Therefore, we timed a few repetitions of the kicking and tucking motion of the servo motor whereby the amplitude of the arc increases. These timings were then used by the robot to start the initial swing.

Maintaining the swing is a matter of detecting the peak, kicking and tucking in at the respective peaks. Since the initial swing will bring the arc to an amplitude high enough for the accelerometers to detect the peaks, maintaining the swing is just simply changing the pulse signal of the servo motor at the peaks.

The final product is a robot that can swing itself from rest and maintain the swing arc. The swing and the robot can be seen below in Figure 7.

[pic]

Figure 7. The Swing

What did not work

There are some difficulties faced during the course of making the robot work. One of the difficulties is to provide sufficient power to the servo motor and yet ensure that it is not drawing from the same 5V source as the Atmel32 chip. We tried using 9V batteries but the motor drew too much current. In the end, we used a single power supply that provided both 12V and 5V across its terminals.

Another problem is the noise from the accelerometer output. The effect is especially pronounced for the xy-axis accelerometer. In the end, we have to use a big capacitor to reduce the noise. The drawback of using a big capacitor is a slight delay to the response time because it takes time to remove the charges from the capacitor. However, the short delay is not significant.

The initial design of our project involved the use of solenoids together with the servo motor. The concept of using solenoids was to alter the swings centre of gravity with respect to the axis of rotation, raising it at the bottom of the oscillation and lowering it at the peaks. However, we were unable to get this concept to function satisfactorily as the solenoids that we had provided insufficient displacement and strength. In an attempt to get this concept to work, we attached a 30V across the solenoids with weights attached to them. This, at best, prolonged the oscillation of the swing but the unwanted mechanical vibration that came along with it outweighed its benefits.

Result of Design

Reaching Target

We have been able to reach the target set for the final project by implementing a swing robot that can increase the swing amplitude and then maintaining it. Furthermore, the user interface is set up so that the servo motor can be operated by anyone. We went beyond the basic target by swinging the robot from rest.

Usability and safety

To enhance the usability of the robot by the users, a swtichbox is used to change the control settings of the robot – between user control and microcontroller control. In addition, to ensure the safety of the user, a switch to turn on and off the power to the robot at a moments notice is equally important. This feature of the project can be seen in Figure 3 above.

Accuracy

Accuracy of the robot is not a major issue in this project due to the different timescales between the swing and the microcontroller. Each tick of the microcontroller is set to run every microsecond, while a single oscillation of the swing robot takes about 1 second on average. This difference in timescale is of 3 orders of magnitude, hence it does not affect the functioning of the robot in any discernable way.

Conclusion

We achieved our target of swinging the robot from rest and maintaining the amplitude infinitely. A user interface was added to the robot so that other people can have their hands on the swing.

Areas of Improvement

Given more time, there are some improvements that can be made to the swing robot. One of them is to be able to continue the swinging motion when the user decides to stop swinging halfway and switch to auto swing mode. Currently, the swing robot is programmed to swing from rest.

Another improvement is to implement a wireless control system so that the amplitude of the swing would not be hindered by excess wires. With the existing setup, there are many wires connecting the switchbox to the board. This resulted in unnecessary dampening of the motion and hence the amplitude could not be further increased.

Ethical Considerations

We, the members of the IEEE, in recognition of the importance of our technologies in affecting the quality of life throughout the world, and in accepting a personal obligation to our profession, its members and the communities we serve, do hereby commit ourselves to the highest ethical and professional conduct and agree:

1. to accept responsibility in making decisions consistent with the safety, health and welfare of the public, and to disclose promptly factors that might endanger the public or the environment;

There are no safety issues with the swing robot since the only human interaction will be through the switchbox which is properly insulated against any electric shock.

2. to avoid real or perceived conflicts of interest whenever possible, and to disclose them to affected parties when they do exist;

There is no conflict of interest of any sort.

3. to be honest and realistic in stating claims or estimates based on available data;

Everything is real and no data has been made up.

4. to reject bribery in all its forms;

No bribery has been offered to our team members.

5. to improve the understanding of technology, its appropriate application, and potential consequences;

The report describes everything to our fullest possible capabilities.

6. to maintain and improve our technical competence and to undertake technological tasks for others only if qualified by training or experience, or after full disclosure of pertinent limitations;

We are able to apply what is learnt in the classroom into daily life application like a playground swing.

7. to seek, accept, and offer honest criticism of technical work, to acknowledge and correct errors, and to credit properly the contributions of others;

Acknowledgements are given in the appropriate section.

8. to treat fairly all persons regardless of such factors as race, religion, gender, disability, age, or national origin;

Everyone is treated fairly without any prejudice.

9. to avoid injuring others, their property, reputation, or employment by false or malicious action;

No one was hurt throughout the course of the project. A team member was burnt by overheated chip but was attended to immediately.

10. to assist colleagues and co-workers in their professional development and to support them in following this code of ethics.

Groups doing similar projects were able to build on some of our experience. Our concept of using the servo enabled the 3 groups doing the swing to move forward in the project together.

Acknowledgements

Freescale, – For donating their accelerometers

Dr Bruce Land and his team of TAs – For their help during lab hours

References

Mega32 datasheet

MMA1260D datasheet

Codevision C user manual

Further Physics of a Swing -

Physics of Everyday stuff -

[pic]

THE END

Appendix

Cost

The cost of the project was kept under the budget imposed budget of $50. The table below shows the breakdown of the costs involved with the project.

|Part |Cost |Description |

|Solder Board |$2.50 | - |

|Mega32 |$8.00 | - |

|Power Supply |$5.00 | - |

|Custom PC Board |$5.00 | - |

|Accelerometer Z-axis |$0.00 |Sampled from Freescale |

|Metal Rods |$0.00 |Found - With help from a MechE friend |

|Plastic Sheets |$0.00 |Found as scrap |

|Acylic Sheet |$0.00 |Found as scrap |

|Quarters |$15.00 |Used as Weights |

|2 Pieces of Wood |$0.00 |Obtained as Scrap from a contruction site |

|Total |$35.50 |  |

Figure 8. Breakdown of Costs

Tasks

|Task |Group Member |

|Accelerometer Interface |Winson |

|Servo Interface |Hsiang Wei |

|Swing Setup |Hsiang Wei |

|Switchbox / Wiring |Hsiang Wei |

|Soldering |Winson/ Hsiang Wei |

|Testing |Winson |

|Report |Winson/ Hsiang Wei |

|Website |Winson/ Hsiang Wei |

Figure 9. Breakdown of Tasks

Schematic

[pic]

Figure 10. Schematic of Project

Code

#include

#include

//timeout values for each task

#define t1 38

#define t3 38

//Positions for Servo

#define p1 10

#define p2 25

//States for debouncer

#define nopush 1

#define maybepush 2

#define push 3

#define maybenopush 4

//States for modes

#define m_user 0

#define m_mc 1

#define m_start 2

#define begin {

#define end }

//the four task subroutines

void task1(void); //ADC 1

void task2(void); //ADC 2

void task3(void); //Button Control

void start(void); //Initial starting sequence from rest

void initialize(void); //all the usual mcu stuff

unsigned int time1, time2,time3,tcount,i; //timeout counters

unsigned int timestart; //timeout counters

unsigned char led; //light states

unsigned int incount[2]; //increasing counter

unsigned int decount[2]; //decreasing counter

unsigned int peakcount; //peak counter

unsigned int nopeakcount; //no peak counter

unsigned char peak; //indicates at peak position

unsigned char auto; //auto kick

unsigned char north; //indicates nth/sth position

unsigned char bpress[3]; //keeps track of button presses

unsigned char mode,leg; //state for mode of project

//Time values for initial start sequence

flash int tvalues[26] ={51,63,77,89,103,116,133,145,160,172,189,202,218,231,

246,260,276,288,303,317,333,346,362,374,391,402};

//ADC variables

char Ain[2] ; //raw A to D number

char Aprev[2]; //previous Ain

//**********************************************************

//timer 0 compare ISR

interrupt [TIM0_COMP] void timer0_compare(void)

begin

//Decrement the three times if they are not already zero

if (time1>0 && mode==m_mc) --time1;

if (time2>0 && mode==m_mc) --time2;

if (time3>0) --time3;

if (timestart>0 && mode==m_start) --timestart;

end

//**********************************************************

//Entry point and task scheduler loop

void main(void)

begin

initialize();

//main task scheduler loop

while(1)

begin

if (time1==0 ) task1();

if (time2==0 ) task2();

if (time3==0) task3();

if (timestart==0) start();

//user control

if(mode==m_user)

begin

if (leg==0) OCR2=p2;

else OCR2=p1;

end

//microcontroller control

else if (mode==m_mc && peak==1)

begin

//if (north==1) OCR2=p2;

//else OCR2=p1;

if (OCR2==p1) OCR2=p2;

else OCR2=p1;

peak=0;

north=0;

end

end

end

//**********************************************************

//Task subroutines

//Task 1 - ADC channel 0

void task1(void)

begin

time1=t1; //reset the task timer

//get the sample

Aprev[0] = Ain[0];

Ain[0] = ADCH;

//start another conversion

//channel one/ left adj /EXTERNAL Aref

ADMUX = 0b01100001;

ADCSR.6=1;

#define countmax 3

if (Ain[0]>Aprev[0]) //increasing

begin

if (incount[0] ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download