View Single Post
  #8   Spotlight this post!  
Unread 30-01-2009, 17:49
BrandonD-1528's Avatar
BrandonD-1528 BrandonD-1528 is offline
Mentor
AKA: Brandon Dusseau
FRC #1528 (Monroe Trojan Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ann Arbor, MI
Posts: 118
BrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the rough
Re: Drive code not working; any suggestions?

We took all of your suggestions into consideration, and here's our revised code. It's still not building and maybe we were wrong about the syntax error.

Code:
#include <WPILib.h>
#include <Jaguar.h>
#include <Victor.h>



class RobotDemo : public SimpleRobot 
{ 
	RobotDemo(void)
	{ 	// put initialization code here
		Jaguar leftmotor(1);
		Victor rightmotor(2);
		Joystick leftjoy(1);
		Joystick rightjoy(2);
	}
	void Autonomous(void)
	{ 	// put autonomous code here
		
	}
	void OperatorControl(void)
	{ 	// put operator control code here
		update_drive();
	}
	
	
	void update_drive()
	{
	int k = 1;		//speed increase/decrease value
	
	if (leftjoy.GetY() >= (255 - k))		//if left joystick is near max
	{	//overshot security
		leftmotor.rawset(leftjoy.GetY());
	}
	
	if (leftjoy.GetY() <= k)				//if left joystick is near min
	{	//undershot security
		leftmotor.rawset(leftjoy.GetY());
	}
	
	if ((leftjoy.GetY() < (255 - k)) && (leftjoy.GetY() > k))		//otherwise...
	{	//standard control
		if (leftjoy.GetY() > leftmotor.rawget())
		{	//speed up
			int leftmotortemp1 = leftmotor.rawget();
			leftmotor.rawset(leftmotortemp1 + k);
			if (leftjoy.GetY() < leftmotor.rawget())
			{	//overshot security
				leftmotor.rawset(leftjoy.GetY());
			}
		}
		if (leftjoy.GetY() < leftmotor.rawget())
		{	//slow down
			int leftmotortemp1 = leftmotor.rawget();
			leftmotor.rawset(leftmotortemp1 - k);
			if (leftjoy.GetY() > leftmotor.rawget())
			{	//undershot security
				leftmotor.rawset(leftjoy.GetY());
			}
		}
	}
	
	
	
	
	if (rightjoy.GetY() >= (255 - k))		//if right joystick is near max
	{	//overshot security
		rightmotor.rawset(rightjoy.GetY());
	}
	
	if (rightjoy.GetY() <= k)				//if right joystick is near min
	{	//undershot security
		rightmotor.rawset(rightjoy.GetY());
	}
	
	if ((rightjoy.GetY() < (255 - k)) && (rightjoy.GetY() > k))		//otherwise...
	{	//standard control
		if (rightjoy.GetY() > rightmotor.rawget())
		{	//speed up
			int rightmotortemp1 = rightmotor.rawget();
			rightmotor.rawset(rightmotortemp1 + k);
			if (rightjoy.GetY() < rightmotor.rawget())
			{	//overshot security
				rightmotor.rawset(rightjoy.GetY());
			}
		}
		if (rightjoy.GetY() < rightmotor.rawget())
		{	//slow down
			int rightmotortemp1 = rightmotor.rawget();
			rightmotor.rawset(rightmotortemp1 - k);
			if (rightjoy.GetY() > rightmotor.rawget())
			{	//undershot security
				rightmotor.rawset(rightjoy.GetY());
			}
		}
	}
	}
};


	Start_Robot_Class(RobotDemo);
Edit: The code has been corrected for the most part. Please let us know if you can find any other problems.
__________________
Brandon Dusseau (website)
Monroe Trojan Robotics mentor
Software Engineer
Michigan Tech alumnus

Last edited by BrandonD-1528 : 30-01-2009 at 18:12.