View Single Post
  #1   Spotlight this post!  
Unread 12-19-2009, 12:21 AM
spartango spartango is offline
Registered User
FRC #0192 (GRT)
Team Role: Alumni
 
Join Date: Nov 2009
Rookie Year: 2008
Location: Palo Alto, CA
Posts: 43
spartango is an unknown quantity at this point
Event Driven Development for FRC-Java

The GRTFramework (http://code.google.com/p/grtframework , seee http://forums.usfirst.org/showthread.php?t=13459 for more) has been updated to Version 2.0, bringing a brand-new Event model to FRC Java!

That means you can develop code for your robot that doesn't need to poll for sensor data, instead being notified when a sensor has new data or when a sensor state changes. That means you can be notified when a component has executed a specific instruction, or a part has failed to do what it needs to do. All told, this allows for asynchronous robot control and really flexible, responsive code.

Give it a try and let us know what you think!

A little more info:

I'm attaching here a the file that defines a teleoperated tankdrive mode using events from the joystick.

http://forums.usfirst.org/attachment...1&d=1260931244

Very simply, lets walk through this code...
First, we are in a "DriveEventController"... which is an EventController and a JoystickListener.
In the constructor we register the RobotBase(Drivetrains and sensors involved in moving) with this controller by "addMechanism"-ing it.
We also subscribe this controller to events pushed by each joystick, as follows:
((GRTJoystick) ds.getSensor("leftJoystick")).addJoystickListener( this);

When the x-axis Joystick, changes position, that joystick sends an event and calls "xAxisMoved"...When this happens we do nothing--this is tank drive--as is the case with the z axis and throttle.

When the joystick yAxis is moved, yAxisMoved is called, and we do two things:
1st we figure out if it was the left or right joystick by asking for its ID.
2nd we tell the mechanism that it should be tankdriving at the new desired speed.

Thats it! no threads or loops. no polling. no weird or random calls, all abstracted to the physical object of a robot base. Oh, and it works.
See http://code.google.com/p/grtframework for more!
Reply With Quote