ME 218B: Smart Product Design                                                                                                                                                                                 Winter 2014 Final Project
Joustball -
  • Home
    • The Game
    • Little Zorro
    • About Us
  • Circuits
    • Power & E128
    • Motors
    • Sensors
    • LEDs / Switches/ Emitter
  • Code
    • State-Chart Descriptions
    • Service Descriptions
    • Header / Code Listings
  • Mechanical Design
  • Bill of Materials
  • Gems of Wisdom

Service Modules


IRManager

IR Manager is a service that detects the knight and goal IR emitters. Three distinct phototransistors have input capture timer pins, and an ES_Timer loop checks the frequency of the incoming signals several times a second. 

PseudoCode (Technical Overview): Module Interrupt/Run Function Interface
  • Use Three Input Compare Interrupts That Increment Tick Counter
  • Use An ES_TIMER Library that 10 times a second checks the three counters, determines if the three pulse numbers are appropriate for the knight vs. goal (forward and rear facings sensors detect knight, side sensor detects goal), and resets the counters
  • If a sensor detects something, it posts an ES_GOALDETECTED or ES_KNIGHTDETECTED event to the mater state machine to handle if appropriate

TapeDebounce

TapeDebounce contains the event checkers for the tape sensors. It is its own service because it initially was using a debouncing system, however this was removed after further testing revealed there was no noise in the tape sensor signal

PseudoCode (Technical Overview): Event Checker Function For Tape Sensors
  • Read the Value of the tape sensor in the AD port
  • If the value is above the voltage threshold for black tape and it wasn't the last time checked:
  1. Post ES_CENTRALTAPEDETECTED or ES_LATERALTAPEDETECTED and post to the master state machine to handle if appropriate 

SPIProjectService

SPIProjectService is responsible for periodically querying the JSR and transmitting new stage/gave over messages to the master state machine. The SPI Project service performs the bitwise operations necessary to parse incoming signals and stores game scores, which could be queried by the state chart.

PseudoCode (Technical Overview): 

ModuleLevelVariables:
  •  CommandType: whether currently asking for game status or matchscore
  • CommandNumber: value 0-3 to depending on place in sequence
  • My Score: our knights score
  • Their Score: other knights score
  •   Reload Status: Boolean

InitServiceModule:
  • Initialize all of the SPI settings per previous command generator project. Start timer for 50ms

RunServiceModule:
o   If 50ms timer: Write CommandType To Register
o   If 2ms timer: Write appropriate value to register based on command type and number

SPI Interrupt:
  • Module Level Variable: LastGameStatus
  • Based on current commandType and CommandNumber:
  •  Read register and update module level variables appropriate
  • If game status changes or head knocked off post event to state chart / update score module level variables
  •  If CommandNumber is 3:
  1. Switch command types and reset commandnumber to 0
  2. Start 50ms timer
  •  Else: 
  1.  Set 2ms timer
  2. CommandNumber++

QueryReload/QueryMyScore/QueryTheirScore functions accessible to state charts

BallRequestService

BallRequestService is called upon by the Reload state machine when it is an appropriate time to request balls. The service uses an output compare timer to obtain the precise signal necessary to request a ball, and then the ES_Timer library to wait approximately 3 seconds between ball requests.

PseudoCode (Technical Overview): 

Run Function:
  • if request ball event: turn on indicator led and program next output compare
  • if timeout event: 
  1. if ball 5 over: send finished reload event
  2. if not ball 5 and three seconds up: turn on indicator led and program next output compare
  3. else: restart timer to wait a full three seconds

Interrupt:
  • Clear Flag
  • If the IR emittor is high: put it low, increment cycle number, and set output compare for 30 ms 
  • If the IR emiittor is low 
  1. If it has been 10 cycles: start timer for big break and turn off LED low
  2. Else: Set the emitter high, and set output compare for 10 ms

BallShootService

BallShootService responds to two event calls, one of which will turn on the shooting motor early to allow it to warm up, and the second of which controls a servo motor to release the balls into the shooter. 

PseudoCode (Technical Overview): 

  • if event is start the shorter: increase the duty cycle on the PWM pin to 45 from 0
  • if event is to shoot balls:
  1.  change pulse width of the servo holding balls back
  2.  start timer 
  • if event is a timeout:
  1. set PWM on motor back to zero
  2. change pulse width of servo to keep new balls back
  3. post event to move forward HSM to start moving

LanceMotorControl

LanceMotorControl is called to deploy the lance for the 3 second period. There are two servo motors which control the chop and sweep motions of the lance, and this service handles the timings and positions to obtain the deadliest motion.

PseudoCode (Technical Overview): 

  • if event is deploy the lance: set a timer to timeout
  • if event is a timeout:
  1. switch based on counter
  2. based on switch number reposition tilt servo or pan servo
  3. increment counter
  4. restart timer
  5. if count is greater than programmed motions: send ES_MOVE event to move forward state chart

MotorService

MotorService is a complex service that receives calls to move straight, backwards, and turn. Using encoders connected to input capture pins, the service can precisely measure distance traveled for turns and finite moves, sending motor response events when these moves are finished. For movements across the track, the service applies a PI control law to the PWM signal on the motors based on encoder readings. In order to keep the head from falling over, the service controls an acceleration and deceleration period. Finally, the service is able to recognize a wall hit when the requested duty cycle hits 100 for both wheels, and then automatically stops the motors and ends the stage. 

PseudoCode (Technical Overview): 

Left Encoder Interrupt:
  • Increment tick counter
  • If currently counting the number of ticks
  1. Increment special tick counter
  2. if special tick count is greater that requested ticks: turn both motors off and send motor response event to master state machine

Right Encoder Interrupt:
  • Increment tick counter
  • If currently counting the number of tick until reaching goal line
  1. Increment special tick counter
  2. if special tick count is greater that field distance ticks: turn on timer that will begin process of slowing down speed

Duty Cycle Interrupt:
  • if currently moving:
  1.  Determine Error Between Left Encoder and Desired Number of Ticks
  2. Determine Error Between Right Encoder and Desired Number of Ticks
  3. If Duty cycle is above 100 on both motors, post motor stop event and  post motor response event
  4. Apply PI Control Laws to both motors
  5. Apply Linear offset to right motor 
  6. Update Duty Cycles Accordingly

Run Function:
  • If Event is TimeOut: increase or decrease set point speed as appropriate to allow for slowing/speeding up
  • If Event is motor event, switch based on event parameter. Things to control:
  1. Direction: Forward, Backward, Turning Left, Turning Right: control relative current directions on wheels
  2. Speed: How high is DTY Cycle. Different speeds for long vs. short movements
  3. Moving For Set Distance? If so, program into module so that interrupt can turn off when appropriate
  4. Traveling across the track? If so, start the timers to speed up duty cycle gradually so headed doesn't fall off
Powered by Create your own unique website with customizable templates.