View Single Post
  #9   Spotlight this post!  
Unread 04-09-2009, 15:15
Jared Russell's Avatar
Jared Russell Jared Russell is online now
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: very basic code help

Quote:
Originally Posted by byteit101 View Post
you should also put the Joystics and RobotDrive inside the class (and move the constructors for them, you SHOULD use the watchdog (unless debugging), and you have infinite loops (and auto is longer than 15 seconds, but i am assuming it is not for a real competition):
Code:
#include "WPILib.h"

class RobotDemo : public SimpleRobot 
{

RobotDrive myRobot;
Joystick leftStick;
Joystick rightStick;
public:
	RobotDemo():myRobot(1,2), leftStick(1), rightStick(2)//need to put them here
	{
		//GetWatchdog().SetEnabled(false); dont need to do this here
	}

	void Autonomous() 
	{
		GetWatchdog().SetEnabled(false);
		//while(1)
		//{
			for(int i = 0; i < 4; i++)
			{
				myRobot.TankDrive(0.5,-0.5);
				Wait(4);
				myRobot.TankDrive(0.5,0.5);
				Wait(2);
			}
			myRobot.TankDrive(0.0,0.0);
			Wait(4);
		//}
	}
	
	void OperatorControl() 
	{
		//while(1) and you should use while(true) in C++, while(1) is so C
		//{
			GetWatchdog().SetEnabled(true);
			while (IsOperatorControl()) 
			{
				GetWatchdog().Feed();
				myRobot.TankDrive(leftStick, rightStick);
				Wait(0.005);
			}
		//}
	}
};
START_ROBOT_CLASS(RobotDemo);
Just so nobody gets confused, while these suggestions are certainly reflective of good practice and may reflect the actual coder's intent, they aren't strictly necessary for your code to compile and work (work as in not crash as opposed to exactly what you want it to do).
Reply With Quote