View Single Post
  #2   Spotlight this post!  
Unread 12-26-2008, 02:39 PM
kyungjin kyungjin is offline
Software Specialist
AKA: Daniel
VRC #0646
Team Role: Programmer
 
Join Date: Aug 2008
Rookie Year: 2009
Location: Honolulu, Hawaii
Posts: 65
kyungjin is an unknown quantity at this point
Send a message via AIM to kyungjin Send a message via MSN to kyungjin
Re: Getting Familiar with Programming in WindRiver

Here's the sample source code...

Code:
#include "WPILib.h"

/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */
class RobotDemo : public SimpleRobot
{
	RobotDrive *myRobot; // robot drive system
	Joystick *stick; // only joystick
	DriverStation *ds; // driver station

public:
	RobotDemo(void)
	{
		ds = DriverStation::GetInstance();
		myRobot = new RobotDrive(1, 2); // create robot drive base
		stick = new Joystick(1); // create the joysticks
		GetWatchdog().SetExpiration(100);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		GetWatchdog().SetEnabled(false);
		myRobot->Drive(0.5, 0.0); 	// drive forwards half speed
		Wait(2000); 				//    for 2 seconds
		myRobot->Drive(0.0, 0.0); 	// stop robot
	}

	/**
	 * Runs the motors with arcade steering. 
	 */
	void OperatorControl(void)
	{
		GetWatchdog().SetEnabled(true);
		while (IsOperatorControl())
		{
			GetWatchdog().Feed();
			myRobot->ArcadeDrive(stick); // drive with arcade style (use right stick)
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote