strategy
Our final strategy was a very simple method that leveraged the capabilities of our mechanical design. The adjustable barrel direction allowed Gwen to drive straight away from the Safe Space to a single shooting location. Without the need for further positioning from the drive system, attempts could be made on two different social media site towers as the barrel moved through its full range. For each tower, slightly adjusting the barrel between shots allowed Gwen to "spray" her shots to compensate for any slight variations in the shooting location.
In summary: Two full shot attempts are made on the first two social media sites, then Gwen drives over the Fact Checker.
In summary: Two full shot attempts are made on the first two social media sites, then Gwen drives over the Fact Checker.
State machine diagram
Software implementation
To streamline the code development process, we divided our code into four modules. The main Gwen code handles the state machine behavior and calls on helper functions available in the other three modules to control the drive, shooter, and ball stepper (hopper) systems. A general description is provided below.
1.) Gwen Main
Main operation code that contains the core logic of Gwen
2.) Drive Functions
Controls all low-level functions of the drive system and handles pin states and inputs to the motor driver
3.) Ball Shooter Functions
Controls all low-level functions of the shooter system to aim barrel and run flywheel
4.) Ball Stepper Functions
Controls all low-level functions of the stepper hopper system to load balls into the shooter
1.) Gwen Main
Main operation code that contains the core logic of Gwen
- Tracks state and performs associated actions
- Handles timers
- Contains all #define definitions
- General helper functions
- readPing: Obtain Ping sensor readings
- startMotorPause: Sets pause between driving states to minimize momentum effects and to protect motors
- driveAdjustStraight: Calculate drive adjustment to ensure straight driving
2.) Drive Functions
Controls all low-level functions of the drive system and handles pin states and inputs to the motor driver
- initializeMotors: Assigns Arduino pins leading to the L298N motor driver and sets initial motor speeds
- setSpeeds: Set speeds of each motor but does not start motors
- setDirections: Set directions of each motor
- driveForward: Sets each motor to drive forward at its individual set speed
- driveReverse: Sets each motor to drive reverse at its individual set speed
- driveStop: Sets each motor to stop using fast-braking
- driveRotateCW: Sets each motor to drive at its individual set speed so Gwen rotates clockwise
- driveRotateCCW: Sets each motor to drive at its individual set speed so Gwen rotates counterclockwise
- drivePivotCW: Sets each motor to drive at its individual set speed so Gwen pivots CW about her right wheel
- drivePivotCCW: Sets each motor to drive at its individual set speed so Gwen pivots CCW about her left wheel
3.) Ball Shooter Functions
Controls all low-level functions of the shooter system to aim barrel and run flywheel
- initializeShooter: Assigns Arduino pins leading to the flywheel motor driver and the aiming servo
- stopShooter: Turns flywheel off
- aimTower1: Aims at Tower 1 and turns flywheel on
- aimTower1_spray: Aims at Tower 1 with a slight offset and turns flywheel on
- aimTower2: Aims at Tower 2 and turns flywheel on
- aimTower2_spray: Aims at Tower 2 with a slight offset and turns flywheel on
4.) Ball Stepper Functions
Controls all low-level functions of the stepper hopper system to load balls into the shooter
- oneShot: Rotates stepper approximately 1/12 revolution so that one ball may fall into the shooter
Source code
The full source for Gwen can be found in .zip file below
gwenTheRobot.zip | |
File Size: | 11 kb |
File Type: | zip |
Major Code developments
- Initial working strategy: Drive over the Fact Checker while driving to the shooting position (near the small divider wall that separates social media sites). Took an L-shaped path from the Safe Space to quickly and efficiently meet the minimum requirements.
- Return to Safe Space: The addition of code to return to the Safe Space allowed Gwen additional chances to fire and meet the minimum requirements.
- Using delays instead of the Pulse library to control the stepper: Using the Pulse library to control the stepper motor led to problems with returning to driving since both Pulse and our drive motors used Timer 2. Since the drive motors required a PWM-enabled pin, we chose to use delays to brute force a PWM signal to the stepper motor. This was a reasonable choice because Gwen only needed to stay in place and shoot during the stepper motor operation. PWM values and pin states are maintained during delay so our flywheel would continue running.
- Final strategy: Realized that the corner areas of the Echo Chamber were too difficult to reliably handle with Gwen. Reconstruct strategy so shooting position is near the middle of the board. Sacrifice time by separately driving to the Fact Checker and running it over.
- Rotation on Fact Checker: During check-off, the teaching assistants were skeptical that Gwen's ball caster bearings were successfully triggering the Fact Checker. Returning to the Safe Space after hitting the Fact Checker was replaced by a continuous rotation on the Fact Checker to ensure that it was triggered. Gwen will continue to rotate until the end of the trial.