Ping Pong Bong_final Paper_080318

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Ping Pong Bong_final Paper_080318 as PDF for free.

More details

  • Words: 3,293
  • Pages: 22
Ping Pong Bong Marcus Gibson Christopher Thomas MECH208 Final Project Paper March 10, 2008

Table of Contents 1 Synopsis............................................................................................................................4 2 Design Description............................................................................................................4 2.1 Tube............................................................................................................................6 2.2 Sensor.........................................................................................................................7 2.2.1 Photo...................................................................................................................7 2.2.2 Specification Sheet..............................................................................................8 2.2.3 Calibration...........................................................................................................9 2.2.4 Dynamics............................................................................................................9 2.3 Actuator....................................................................................................................11 2.3.1 Photo.................................................................................................................11 2.3.2 Specification Sheet............................................................................................11 2.3.3 Calibration.........................................................................................................11 2.3.4 Dynamics..........................................................................................................11 2.4 Microcontroller........................................................................................................12 2.5 Motor Driver............................................................................................................12 2.5.1 Photo.................................................................................................................12 2.5.2 Specification Sheet............................................................................................13 2.6 Software Design.......................................................................................................13 2.6.1 Software Flowchart...........................................................................................13 2.7 Overall Schematic....................................................................................................14 2.8 Overall Configuration Sketch or Labeled Photo......................................................14 3 Control System Design...................................................................................................17 3.1 Simulation................................................................................................................17 A. Software Code..............................................................................................................17

Table of Figures and Tables Figure 1 Project Configuration Sketch................................................................................4 Figure 2 Project Configuration Picture................................................................................5 Figure 3 Project Configuration Tube Close-up Picture........................................................5 Figure 4 IR Sensor Front Photo...........................................................................................7 Figure 5 IR Sensor Back Photo............................................................................................7 Figure 6 Tube and User IR Sensors.....................................................................................8 Figure 7 IR Sensor Specification Response.........................................................................8 Figure 8 IR Sensor Responses.............................................................................................9 Figure 9 Tube Sensor Differencing....................................................................................10 Figure 10 User Sensor Differencing..................................................................................10 Figure 11 Fan Photo...........................................................................................................11 Figure 12 Motor Performance............................................................................................11 Figure 13 Motor Driver Photo...........................................................................................13 Figure 14 Software Flow Diagram....................................................................................14 Figure 15 Configuration Sketch.........................................................................................15 Figure 16 Electronics Picture.............................................................................................15 Figure 17 Ping Pong Bong Simulation..............................................................................17 Table 1 Project Equipment List ..........................................................................................6 Table 2 Microcontroller Data.............................................................................................12

1 Synopsis This paper describes the details of the Ping Pong Bong project sufficient to build your own. In addition it provides the actual response of the system for both the sensors and actuators. Performance of the system is as follows: • Ping Pong Ball control within one inch maximum deviation within two seconds • Capable of control on an uneven plane/platform

2 Design Description The goal of the Ping Pong Bong project is to be able to control the position of a ping pong ball in a tube relative to the position determined by a user. An original rendition of the setup can be seen in Figure 1 . Initially one IR sensor was chosen for both inside and outside the tube; rejected due to its non-linear output. A sonar sensor was the next feasible choice because of its very linear range; unfortunately sensor was incoherent. The signal provided by the sensor to by reflected and then sensed was incoherent. The signal diverged to much causing reflections off the tube resulting in a noisy signal. Additionally, the sonar sensor was relatively large in size potentially impacting the flow of air from the fans.

Figure 1 Project Configuration Sketch The final decision was to use an IR sensor on both ends of the tube, by differencing the signal we were able to obtain an output that was linear enough to provide adequate control of the ping pong position within the tube. To simplify our situation we used another pair of the same IR sensors outside of the tube to determine the desired location of the ball. A sketch of the final setup can be seen in Figure 1. and are pictures of the project configuration. The list of components used to create the Ping Pong Bong can be found in Table 1.

Figure 2 Project Configuration Picture

Figure 3 Project Configuration Tube Close-up Picture

Table 1 Project Equipment List Item

Quantity

Tube

1

Sensor

4

Actuator

2

Microcontroller Motor Driver 12V Regulator

1 1 1

LCD Display

1

Ping Pong Ball

1

Description Florescent Lamp Protector ~ 40mm diameter Sharp GP2 Y0A21YK IR Sensor Link Depot Motor FAN-5015-B Parallax BS2px Dual Serial Motor Controller Standard Matrix Orbital 4x20 Standard ~ 40mm diameter

2.1 Tube The tube is a plastic cylinder approximately 30 inches or 76 centimeters in length and 1.57 inches or 4 cm in diameter. With the sensors installed the range of the Ping Pong Ball within the tube is 29 inches.

2.2 Sensor The Sharp distance sensor is a popular choice for many projects that require accurate distance measurements. This IR sensor is more economical than sonar rangefinders, yet it provides much better performance than other IR alternatives. Interfacing to most microcontrollers is straightforward: the single analog output can be connected to an analog-to-digital converter for taking distance measurements, or the output can be connected to a comparator for threshold detection. The detection range is approximately 10 cm to 80 cm (4" to 32"); the distance-to-output voltage graph is shown below in Figure 7. The sensor uses a 3-pin JST connector; power, ground, and the output signal.

2.2.1 Photo The following photos provide the front and rear photos of the IR Sensor, Figure 4 and Figure 5 respectively. Figure 6 provides a vantage point of one tube sensor and one user sensor, refer back to Figure 1 for test setup sensor locations.

Figure 4 IR Sensor Front Photo

Figure 5 IR Sensor Back Photo

Figure 6 Tube and User IR Sensors

2.2.2 Specification Sheet Figure 7 is the IR sensor specification response provided by the manufacturer.

Figure 7 IR Sensor Specification Response

Feature summary: •

4.5 V to 5.5 V operating voltage



30 mA average current consumption



10 cm to 80 cm range (4" to 32")



1.9 V output voltage change over distance range

2.2.3 Calibration Calibration of the sensor within our setup is not required. The sensors are differenced electronically through software and are discussed further in 2.2.4. This assumes the sensors are identical; if not, there is minimal difference in the sensor that does not sufficiently impact the configuration.

2.2.4 Dynamics Figure 8 provides the actual response of the IR Sensors in the system. There is a noticeable difference between the tube sensors and the user sensors from four to ten inches and has been determined to be because of the tube. Comparison of the user sensors to the IR Sensor specification response shown in Figure 7 confirms the “free space” response of the user sensors matches. 3.50

Output (Volts)

3.00 Sensor 1 Output [inside tube] Sensor 2 Output [inside tube] Sensor 3 Output [outside tube] Sensor 4 Output [outside tube]

2.50 2.00 1.50 1.00 0.50 0.00 0

5

10

15

20

25

30

Distance (Inches)

Figure 8 IR Sensor Responses A linear range of sensing was obtained by differencing the pair of IR Sensors. The linear range of the tube sensors and user sensors can be seen in Figure 9 and Figure 10 respectively. The tube sensors provide a linear range of 21 inches with a maximum

deviation of 0.76 inches. The user sensors provide a linear range of 20 inches with a maximum deviation of 0.88 inches. The difference in the linear region output can once again be attributed to the tube. To improve the user sensors two concepts were used. The first was inset the user sensors by 1 inch. The second was to use an object to be sensed by the user that was equivalent in size or larger than the ping pong ball, hence the Pillsbury Dough Boy seen in . 4.00 3.00

Output (Volts)

2.00 1.00 0.00 -1.00

0

5

10

15

20

25

30

Sensor 1 Voltage Sensor 2 Voltage Difference Linear (Difference)

-2.00 -3.00

y = -0.2323x + 3.5335

-4.00 Distance (Inches)

Figure 9 Tube Sensor Differencing 4.00 3.00

Output (Volts)

2.00 1.00 0.00 -1.00

0

5

10

15

20

25

-2.00 -3.00

y = -0.2487x + 3.5701

-4.00 Distance (Inches)

Figure 10 User Sensor Differencing

30

Sensor 1 Output Sensor 2 Output Difference Linear (Difference)

2.3 Actuator The Ping Pong Bong setup uses two fans of the same make and model for actuators at each end of the tube.

2.3.1 Photo Figure 11 is a photo of the fan used to actuate the ping pong ball within the tube. There are three wires; ground (black), power (red), and tachometer (yellow).

Figure 11 Fan Photo

2.3.2 Specification Sheet •

Link Depot Motor FAN-5015-B o Size:50x50x15mm o Current: 0.16A o Air Flow: 15CFM o Speed: 5200RPM o Power: 1.92W o Bearing: One Ball Bearing o Voltage: 12VDC

2.3.3 Calibration The fans were calibrated by providing each with an equivalent PWM or current and observing the ping pong ball movement. Equivalent performance of the fans would be identified by no ball movement; a PWM bias of 8 was necessary to achieve equal output of the fans. Leads to the fans were switched to ensure that the calibration was needed because of the fans and not because of the motor driver, circuitry, or software.

2.3.4 Dynamics TBD Figure 12 Motor Performance

2.4 Microcontroller Table 2 provides details for the performance capabilities of the microcontroller used for the project. Table 2 Microcontroller Data Product Environment Microcontroller Processor Speed Program Execution Speed RAM Size Scratch PadRam EEPROM (Program) Size Number of I/O Pins Voltage Requirements Current Draw@ 5 volts Source/Sink Current per I/O Source/Sink Current per unit PBASIC Commands* PC Interface Windows Text Editor Version

BS2px 0º - 70º C (32º - 158º F) ** Ubicom SX48AC 32 MHz Turbo ~19,000 instructions/sec. 38 Bytes (12 I/O, 26 Variable) 128 Bytes 8 x 2K Bytes, ~4,000 inst. 16 + 2 Dedicated Serial 5 - 12 vdc 55 mA Run, 450 µA Sleep 30 mA / 30 mA 60 mA / 60 mA per 8 I/O pins 63 Serial (19200 baud) Stampw.exe (v2.2 and up)

* PBASIC Command count totals include PBASIC 2.5 commands on all BS2 models.

2.5 Motor Driver The Dual Serial Motor Controller or Motor Driver is a PWB that primarily consists of an H-Bridge and a PIC. As its name implies it utilizes serial communication to receive information from the main microcontroller and drive the motors.

2.5.1 Photo Figure 13 is a photo of the top profile of the motor driver.

Figure 13 Motor Driver Photo

2.5.2 Specification Sheet The following motor driver details are provided by the manufacturer. o Speeds: 127 forward, 127 backwards, and brake o Maximum current: 1A each for two motors

2.6 Software Design PID control was chosen to control the position of the ball. Refer to Appendix A Software Code for the Ping Pong Bong control software. Need Marcus to add P/I/D details

2.6.1 Software Flowchart The software flowchart is provided in Figure 14. A unique feature of the Ping Pong Bong project was the addition of the “kick out” routines. The tube sensors provide a linear range of ~21 inches in tube that is ~29 inches leaving a “dead zone” of ~2 inches on each side, considering the ping pong ball is ~2 inches in diameter. When the ball enters the “dead zone” it is pushed up against the sensor because the software interprets the difference in the sensor voltage to be the same as the ball being located at the far end of the tube at the edge of the opposite “dead zone”, reference Figure 9. In order to correct this misinterpretation the software uses if then statements to identify the special case when both sensors are reading low values. If this instance occurs then system will provide full force in the opposite direction for 220 ms and clear the PID integral term to prevent integral windup.

Initialize Read Sensors

Test Stuck Left

Kick Out of Left

Test Stuck Right

Kick Out of Right

Calculate Desired & Actual Positions Calculate Drive (PID) Set Motor Speeds

Figure 14 Software Flow Diagram

2.7 Overall Schematic

2.8 Overall Configuration Sketch or Labeled Photo

Figure 15 Configuration Sketch

Figure 16 Electronics Picture

3 Control System Design 3.1 Simulation

Figure 17 Ping Pong Bong Simulation

A. Software Code ' {$STAMP BS2px} ' {$PBASIC 2.5} ' IO ' desired sensor left DSL_CS PIN 7 ' 0831 chip select active low from BS2 DSL_CLK PIN 5 ' Clock pulse from BS2 to 0831 DSL_Dout PIN 6 ' Serial data output from 0831 to BS2 ' desired sensor right DSR_CS PIN 3 ' 0831 chip select active low from BS2 DSR_CLK PIN 1 ' Clock pulse from BS2 to 0831 DSR_Dout PIN 2 ' Serial data output from 0831 to BS2 ' actual sensor right ASR_CS PIN 11 ' 0831 chip select active low from BS2 ASR_CLK PIN 9 ' Clock pulse from BS2 to 0831 ASR_Dout PIN 10 ' Serial data output from 0831 to BS2 ' actual sensor left ASL_CS PIN 15 ' 0831 chip select active low from BS2 ASL_CLK PIN 13 ' Clock pulse from BS2 to 0831 ASL_Dout PIN 14 ' Serial data output from 0831 to BS2 MOTOR PIN 8 ' Motor controller serial input MOTOR_RESET PIN 4 ' Motor controller On/Off line ' CONSTANTS

MOTOR_BAUD CON 396 'Set Baud to 9600 (SPECIFIC TO BS2px) ' gains Kp CON 60 ' in hundredths (100=gain of 1) Ki CON 1 ' in hundredths (100=gain of 1) Kd CON 250 ' in tenths (10=gain of 1) ' biases MBias CON -8 ' motor bias (since they don't exactly match) DSBias CON -4 ' input sensor bias ASBias CON 4 ' actual sensor bias Ti CON 5 ' Integral Reset time (how often do we add Err to the Ei term) ' average filtering AAveCount CON 3 'size of average for position filtering (smoothing) for actual sensors DAveCount CON 3 'size of average for position filtering (smoothing) for desired sensors ' VARIABLES DSLData VAR Byte ' left desired sensor data DSRData VAR Byte ' right desired sensor data ASLData VAR Byte ' left actual sensor data ASRData VAR Byte ' right actual sensor data P VAR Word ' proportional control effort term I VAR Word ' integral control effort term D VAR Word ' differential control effort term Drive VAR Word ' total control effort Err VAR Word ' difference between desired and actual positions LastErr VAR Word ' store the previous Err term to calculate differential Ei VAR Word ' Err over time IntCount VAR Byte ' Variable for counting cycles for integral drive (see Ti constant) Sign VAR Word ' variable for calculating sign ActPos VAR Word ' calculated/filtered actual position DesPos VAR Word ' calculated/filtered desired position ' INIT LastErr = 0 ' clear last err ActPos = 0 ' initial actual position = 0 DesPos = 0 ' initial desired position = 0 Ei = 0 ' clear accumulated err HIGH MOTOR ' set motor serial control line high (for low pulses) HIGH MOTOR_RESET ' motor controller reset (controller on) ' PROGRAM Main: GOSUB ReadDSL GOSUB ReadDSR

GOSUB ReadASL GOSUB ReadASR GOSUB TestForStuck GOSUB CalcPosition GOSUB CalcDrive GOSUB RunMotors GOTO main ' subroutines ReadDSL: ' Acquire conversion from 0831 LOW DSL_CS ' Select the chip LOW DSL_CLK ' Ready the clock line. PULSOUT DSL_CLK,10 ' Send a 10 uS clock pulse to the 0831 SHIFTIN DSL_Dout, DSL_CLK, MSBPOST,[DSLData\8] ' Shift in data HIGH DSL_CS ' Stop conversion RETURN ReadDSR: ' Acquire conversion from 0831 LOW DSR_CS ' Select the chip LOW DSR_CLK ' Ready the clock line. PULSOUT DSR_CLK,10 ' Send a 10 uS clock pulse to the 0831 SHIFTIN DSR_Dout, DSR_CLK, MSBPOST,[DSRData\8] ' Shift in data HIGH DSR_CS ' Stop conversion RETURN ReadASL: ' Acquire conversion from 0831 LOW ASL_CS ' Select the chip LOW ASL_CLK ' Ready the clock line. PULSOUT ASL_CLK,10 ' Send a 10 uS clock pulse to the 0831 SHIFTIN ASL_Dout, ASL_CLK, MSBPOST,[ASLData\8] ' Shift in data HIGH ASL_CS ' Stop conversion RETURN ReadASR: ' Acquire conversion from 0831 LOW ASR_CS ' Select the chip LOW ASR_CLK ' Ready the clock line. PULSOUT ASR_CLK,10 ' Send a 10 uS clock pulse to the 0831 SHIFTIN ASR_Dout, ASR_CLK, MSBPOST,[ASRData\8] ' Shift in data HIGH ASR_CS ' Stop conversion RETURN CalcPosition: ' calculate the actual and desired positions using sensor biasing, and filtering ' the actual position is the right actual sensor differenced with the left actual sensor ActPos = ActPos * (AAveCount - 1) + (ASRData - ASLData + ASBias) Sign = ActPos

GOSUB SetSign ActPos = ABS ActPos / AAveCount ActPos = ActPos * Sign ' the desired position is the right desired sensor differenced with the left desired sensor DesPos = DesPos * (DAveCount - 1) + (DSRData - DSLData + DSBias) Sign = DesPos GOSUB SetSign DesPos = ABS DesPos DesPos = DesPos / DAveCount ' if we're within roughly the inside 16 inches, IF ( DesPos < 70 ) THEN DesPos = DesPos * 11 / 10 ' scale the desired position due to its slight lack of linearity ENDIF DesPos = DesPos * Sign RETURN TestForStuck: ' look for threshold crossings that would indicate the ball is stuck at one end of the tube ' if the right sensor reads 'very far away', and the left sensor doesn't read 'pretty close', IF ( ASRData < 18 AND ASLData < 80 ) THEN GOTO StuckLeft ' assume we're stuck against the left sensor/fan ' if the left sensor reads 'very far away', and the right sensor doesn't read 'pretty close', ELSEIF ( ASLData < 21 AND ASRData < 80 ) THEN GOTO StuckRight ' assume we're stuck against the right sensor/fan ENDIF RETURN StuckLeft: ' routine to kick the ball away from the left end of the tube SEROUT MOTOR, MOTOR_BAUD, [128, 0, 0, 0] ' turn off the right motor SEROUT MOTOR, MOTOR_BAUD, [128, 0, 2, 127] ' turn on the left motor full blast PAUSE 220 ' wait a little while to kick the ball out Ei = 0 ' clear the integral memory in case we've been stuck here for very long GOTO Main StuckRight: ' routine to kick the ball away from the right end of the tube SEROUT MOTOR, MOTOR_BAUD, [128, 0, 0, 127] ' turn on the right motor full blast SEROUT MOTOR, MOTOR_BAUD, [128, 0, 2, 0] ' turn off the left motor PAUSE 220 ' wait a little while to kick the ball out Ei = 0 ' clear the integral memory in case we've been stuck here for very long GOTO Main RunMotors: ' send control speed signal to motor drivers SEROUT MOTOR, MOTOR_BAUD, [128, 0, 0, (127 - Drive)/2] ' run right motor at 50% speed - drive value SEROUT MOTOR, MOTOR_BAUD, [128, 0, 2, (127 + Drive)/2] ' run left motor at 50% speed + drive value

RETURN CalcDrive: ' calculate the total control effort GOSUB ErrorCalc ' calculate error GOSUB PropCalc ' Perform proportional error calcs GOSUB IntCalc ' Perform intigral calcs GOSUB DerivCalc ' Perform derivitive calcs Drive = (MBias + P + I + D) ' calculate total drive Sign = Drive ' Sign adjust to max of 127 min -127 GOSUB SetSign Drive = ABS Drive MAX 127 ' Limit drive to motor capability Drive = Drive * Sign ' restore sign RETURN '********** Calculate Error - Sign adjusted ErrorCalc: LastErr = Err ' save last error for derivitive calc Err = (DesPos - ActPos) ' Calculate position error RETURN '*********** Proportional Drive - Sign adjusted PropCalc: Sign = Err GOSUB SetSign P = ABS Err * Kp / 100 ' Apply Kp gain in hundredths P = P * Sign RETURN '*********** INTIGRAL DRIVE - Sign adjusted IntCalc: IntCount = IntCount + 1 'Add to counter for reset time IF IntCount < Ti THEN IntDone ' Not at reset count? -- done Ei = Ei + Err ' Accumulate err Sign = Ei GOSUB SetSign Ei = ABS Ei MAX 6000 ' limit to prevent windup (the only potential for windup is if the ball gets stuck at an end and doesn't get kicked out) I = Ei * Ki / 100 ' Apply integral gain in hundredths Ei = Ei * Sign I = I * Sign IntCount = 0 ' reset counter IntDone: RETURN '*********** DERIVATIVE DRIVE - Sign adjusted DerivCalc:

' Calculate amount of derivative drive based on the difference of last error D = Err - LastErr Sign = D GOSUB SetSign D = ABS D * Kd / 10 ' apply the derivitive gain in tenths D = D * Sign RETURN '********** Set sign of value SetSign: IF Sign.BIT15 = 0 THEN SignPos ' If signbit is 1, then negative Sign = -1 RETURN SignPos: Sign = 1 SignDone: RETURN

Related Documents

Ping Pong
May 2020 9
Ping Pong Physics
December 2019 12
Alabanza Ping Pong
May 2020 3
Ping Pong Rules Poster
April 2020 8