View Single Post
  #1   Spotlight this post!  
Unread 30-01-2009, 15:16
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
Drive code not working; any suggestions?

We are testing code for our motors/servos. Apparently after downloading the code to our cRIO, nothing seems to function. It builds, so we are sure it is not a syntax error.
The code is as follows:

Code:
#include "WPILib.h"

void update_drive;

class RobotDemo : public SimpleRobot 
{ 
	RobotDemo(void)
	{ 	// put initialization code here
		pwm leftmotor(1);
		pwm 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();
	}
};


	start_robot_class(RobotDemo);


void update_drive()
{
	int k = /*your value here*/;		//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());
			}
		}
	}
}
Any suggestions would be greatly appreciated. Our team is really falling behind this year, and nothing seems to be going right.

Thanks,
iPirates 1528

Last edited by BrandonD-1528 : 30-01-2009 at 15:46.