Professional Documents
Culture Documents
Ping Pong Bong - Final Paper - 080318
Ping Pong Bong - Final Paper - 080318
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
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.
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
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.
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
3.00
Sensor 1 Output
2.50 [inside tube]
Output (Volts)
Sensor 2 Output
2.00
[inside tube]
Sensor 3 Output
1.50
[outside tube]
1.00 Sensor 4 Output
[outside tube]
0.50
0.00
0 5 10 15 20 25 30
Distance (Inches)
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
2.00
Output (Volts)
-2.00
4.00
3.00
2.00
Output (Volts)
-2.00
-3.00
y = -0.2487x + 3.5701
-4.00
Distance (Inches)
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).
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
2.5.1 Photo
Figure 13 is a photo of the top profile of the motor driver.
Figure 13 Motor Driver Photo
Read Sensors
Test
Stuck Kick Out of Left
Left
Test Stuck
Kick Out of Right
Right
3.1 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
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