153B final project
Proposal
Ball-Shooting Game Project Proposal
ECE 153b
Changsheng Su, Huake He
TA: Tarik
Feb 10th, 2020
Overview
Our project is to build a real ball-shooting game. One player plays as a goalkeeper and chooses one of the two sides (left, right) to defend the goal. Another player places a ping pong ball on to the shooter machine and uses the joystick to control the direction of the shot. The logic flow of the ball shooting game is the following. First, the goalkeeper chooses a side to defend, and this signal is stored. Then, the shooter will adjust the direction of the shot, and press shot, which are delayed for 0.5 second, while the left/right defense board will turn in that direction as soon as the shot button is pressed. The ultrasonic sensor will be constantly detecting the distance between two goal posts. If a different distance is measured at one instance (which means the ball passes by the goal line), this means the attacker scores one goal. A message will be printed to the screen to say which side scored via UART/Bluetooth.
Peripherals
Joystick
Ultrasonic sensor
Stepper Motor (PWM)
Bluetooth
Motor (5600RPM)
Serial Interface Protocols
UART/Bluetooth (for score display)
I2C (for joystick)
Responsibilities
Our group has two people, both of us are responsible for the software and hardware implementation. For software, Huake He will be mainly focusing on implementing the Bluetooth module, and Changsheng Su will be focusing on the joystick control. For hardware, Huake will handle the defense part, which is two step motors controlling the two sides to defense; Changsheng will handle the shooting part, which is one step motor for direction adjustments and two motors for ball shooting.
Software structure
The game logic is implemented in a while loop. The defender will first trigger a signal for a selected defense side. The side signal is stored, and wait until the attacker to determine the direction and shoot to trigger the interrupt to switch the defense board. Then the sensor determines if scored or not, and sends the signal to be printed on the console.
Block Diagram
WEEKLY UPDATES
Week 1
We worked on implementing the servo motor. Firstly, we studied the PWM module to correctly adjust the turning angle of the servo. Then, We wrote the function that can adjust the turning angle by inputting a number. Also, we were finalizing the choice of other peripherals, e.g. motors, physical components of the setup.
Week 2
We designed the overall workflow of our shooting game, and wrote the helper functions to control the game, including defend(), attack(), ifScore(), gameOver(). The basic flow is that the defender chooses a side by pressing a button, and the signal is received and processed by defend() function, and by controlling the duty cycle, we programmed the servo to turn to the right direction. Then, the attack() function allows the user to control the direction of the shooting platform. The ifScore() function uses the signal returned by the ultrasonic sensor to determine if scored or not, and add to the defender or the attacker's score. The record() function record the scores and print to the screen using UART. The gameOver function determines if the game is over by checking if one of the player scores up to 5.
Week 3
We implemented the I2C protocol to use the wii nunchuck to adjust the PWM duty cycle to control servo of the shooting platform. We also implemented the PWM control function for the other two servos used to control the shooting of the ball and the defender's action. Also, the ultrasonic sensor function is written for goal detection -- if the distance measured has changed due to the passing though of the ball, a goal signal is detected and scores are updated. The UART blue tooth module is implemented to transmit the score information to an Android phone, and an Android App is written to display the scoring information.
Week 4
We bought materials and made the physical frame of the penalty game. Two motors are equipped on the platform made from foam and hard paper cover to shoot out the ball. A servo controlled by the Z button on the nunchuck is equipped on the platform to feed the ball to the shooting wheels. The servo controlled by the nunchuck is connected to the platform to adjust shooting angle. The last servo controlled by the button is equipped on the goal to simulate the defender. The ultrasonic sensor is placed in a box under the goal to sense if the ball goes in or not.
We also finished up the Android app connected to the UART bluetooth to transmit the score information to smart phone.
After testing, our project work as expected :).
Pin design
PA0 Ultrasonic Trigger TIM5_CH1
PA1 Right button
PA2 USART2_TX connected to bluetooth RX
PA3 USART2_RX connected to bluetooth TX
PA5 Left button
PB3 Ultrasonic Echo TIM2_CH2
PB6 I2C SCL
PB7 I2C SDA
PE8 nunchuck servo TIM1_CH1N PWM1
PE10 button servo TIM1_CH2N PWM2
PE12 z servo TIM1_CH3N PWM3
By device:
Ultrasonic Sensor
PA0 Ultrasonic Trigger TIM5_CH
PB3 Ultrasonic Echo TIM2_CH2
I2C
PB6 I2C SCL
PB7 I2C SDA
Servos
PE8 nunchuck servo TIM1_CH1N PWM1
PE10 button servo TIM1_CH2N PWM2
PE12 z servo TIM1_CH3N PWM3
Buttons
PA1 right button
PA5 left button
Bluetooth
PA2 USART2_TX connected to bluetooth RX
PA3 USART2_RX connected to bluetooth TX