Go to Post I think that in general people should worry more about what they are doing, and less about what others are doing. That goes for a lot more than FIRST. - pfreivald [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Camera Code not Working in Autonomous? Mikesername Programming 6 28-01-2009 10:14
Any suggestions for Gyro displacement code? windell747 Programming 0 17-02-2008 16:03
Incrementation Code not working benhulett Programming 6 12-02-2007 17:39
easyc demo code not working sniggel Programming 5 28-01-2007 16:40
Camera code not working.... DemonYawgmoth Programming 5 11-02-2006 09:21


All times are GMT -5. The time now is 02:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi