View Single Post
  #4   Spotlight this post!  
Unread 12-11-2012, 17:51
slijin's Avatar
slijin slijin is offline
Pockets
AKA: Samuel Lijin
FRC #0694 (StuyPulse)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York City
Posts: 537
slijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to beholdslijin is a splendid one to behold
Re: Limit Switches???

Quote:
Originally Posted by Ether View Post
You'll probably get useful answers faster if you post your code.
Describing your setup as well would probably help.

In pseudocode, it would be something like:

Code:
direction = forward
toggle_prev = false


loop:
   if report_state(limit_switch_1):
      stop(motor)
      direction = backward

   if report_state(limit_switch_2):
      stop(motor)
      direction = forward

   if report_state(toggle) != toggle_prev:
      if report_state(limit_switch_1) or report_state(limit_switch_2):
         set(motor, direction)
         ## Keep in mind this will only work if set() is a state function
         ## (that is, if set() doesn't have to be looped to keep the motor running())
      elif report_state(motor) == running:
         stop(motor)
      toggle_prev = report_state(toggle)
   
   delay 100
The last delay statement is crucial. Here's why: You start from the center, hit the toggle to move forward, hit a limit switch, stopping the motor Then you hit the toggle again to run it backwards, but if the loop runs fast enough, the limit switch will still be triggered, stopping the motor again and reversing the direction. As a result, you'll be left oscillating at that limit switch. The delay lets the motor run long enough so that the limit switch doesn't stay triggered when the loop repeats.
__________________

2010-12 CT Chairman's
2011 Galileo 5th seed
2010 NY Regional Winners
Reply With Quote