View Single Post
  #10   Spotlight this post!  
Unread 31-10-2012, 12:20
Brian Selle's Avatar
Brian Selle Brian Selle is offline
Mentor
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Texas
Posts: 167
Brian Selle has a spectacular aura aboutBrian Selle has a spectacular aura aboutBrian Selle has a spectacular aura about
Re: Interrupts vs. Polling

Quote:
Originally Posted by TeraViks View Post
I think we understand the difference between Polling and Interrupt, but HOW are these two methods manifested with the program??
You can get an interrupt like behavior if you use the new C++ or Java Command-based template in the WPILib.

This program structure handles all the complicated timing, scheduling and notifications. You simply set up input-to-command relationships. When a button, joystick, limit switch, or other input device changes state, a scheduler automatically calls your command. For example, we had a limit switch for the elevator that when a ball came in and depressed the switch our Elevator command was called. This command turned on the elevator motor until the recently ingested ball depressed another limit switch which signaled it to stop. Essentially the WPILib functions are handling the input state polling for you.

Each command is associated with various subsystems (elevator, shooter, drivetrain, etc) so the scheduler can determine if it needs to stop a currently executing command before starting another command that shares the same subsystem. You can set up sequential groups of commands to force things to happen in a predictable order or parallel groups of commands for things to happen simultaneously.

There are also teleop and autonomous methods called each robot iteration where you can place polling functions.

It's a little more work to setup up at first, but I found it to be quite elegant and easy to teach kids once we got going. It also distributes the code well so multiple people can work on the code base without stepping on each other's toes.

If you are interested, the best place to start is the WPILib Robot Programming Cookbook:

http://firstforge.wpi.edu/sf/docman/...tation/doc1297

Last edited by Brian Selle : 31-10-2012 at 16:23.