Go to Post Keep reading. - Billfred [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 22-01-2013, 23:16
JCrusoe JCrusoe is offline
Jacque Crusoe
FRC #3880 (Tiki Techs)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Hawaii
Posts: 5
JCrusoe is an unknown quantity at this point
Smile Gyro not sending values?

Hello =) This is our first year using C++ and the WPI Library as opposed to LabView, and it's been a bit rough getting on our feet. Our current issue is that of the gyro. Modelling off of the example code included, as well as just reading the documentation, you can see what I tried. It seems as if it should work, but it hasn't. In order to test if I am even getting values I created an autonomous that should run the intake motor according to the values the gyro gives. The wiring is correct (to the extent of my knowledge) with the PWM plugged into the "gyro" plug on the gyro (not temp), with the signal cable facing outwards (I've flipped it both ways to see if it makes a difference; it hasn't), and plugged into the 2nd slot of the analog breakout (which is in module 1 of the cRIO).

In short, the gyro just doesn't seem to be working, and during the autonomous I created to test it, nothing happens. The wiring seems to be correct, and I was wondering if it could be code? [code below]

Code:
#include "WPILib.h"


class RobotDemo : public SimpleRobot
{
	Jaguar frontRight; // robot drive system
	Jaguar frontLeft;
	Jaguar backLeft;
	Jaguar backRight;
	
	Jaguar intakeMotor;
	
	Jaguar leftArm;
	Jaguar rightArm;
	
	Jaguar shooter;
	
	Joystick driveStick; 
	Joystick toolStick;
	Joystick armStick;
	
	Gyro gyro;
	
	Timer timer;

public:
	RobotDemo(void):
		
		frontRight(1),	// these must be initialized in the same order
		frontLeft(2),	// as they are declared above.
		backLeft(3),
		backRight(4),
		
		intakeMotor(5),
		
		leftArm(6),
		rightArm(7),
		
		shooter(10),
		
		driveStick(1),		
		toolStick(1),
		armStick(0),
		gyro(1, 2),
		timer()
	{
		
		frontRight.SetExpiration(0.1);
		frontLeft.SetExpiration(0.1);	
		backLeft.SetExpiration(0.1);
		backRight.SetExpiration(0.1);
		
		intakeMotor.SetExpiration(0.1);
		
		leftArm.SetExpiration(0.1);
		rightArm.SetExpiration(0.1);
		
		shooter.SetExpiration(0.1);
		
	}
	
	void driveSystems()
	{
		
	}
	
	void motorDrive(float speed)//Positive is forward; Negative is backwards
	{
		frontRight.Set(speed);
		frontLeft.Set(-speed);
		backLeft.Set(-speed);
		backRight.Set(speed);	
	}
	
	void motorTurn(float speed)//Positive is right; Negative is left
	{
		frontRight.Set(-speed);
		frontLeft.Set(-speed);
		backLeft.Set(-speed);
		backRight.Set(-speed);
	}
	
	void gyroDrive(float speed, float time) //For automouse only! Uses gyro measurements to keep you straight
	{
		timer.Reset();
		timer.Start();
		while( timer.Get() < time)
		{
			if( gyro.GetAngle() > 1 )
			{
				frontRight.Set( (speed*0.25) );
				frontLeft.Set(-speed);
				backLeft.Set(-speed);
				backRight.Set( (speed*0.25) );
			}
			else if( gyro.GetAngle() < -1 )
			{
				frontRight.Set(speed);
				frontLeft.Set( (-speed*0.25) );
				backLeft.Set( (-speed*0.25) );
				backRight.Set(speed);
			}
			else
			{
				frontRight.Set(speed);
				frontLeft.Set(-speed);
				backLeft.Set(-speed);
				backRight.Set(speed);				
			}
		}
	}
		
	void raiseAndShoot()
	{
		intakeMotor.Set(0.5);
		Wait(0.5);
		intakeMotor.Set(0);
		leftArm.Set(1.0);
		rightArm.Set(1.0);
		Wait(2);
		leftArm.Set(0);
		rightArm.Set(0);
		Wait(1);
		shooter.Set(-0.6);
		Wait(3);
		intakeMotor.Set(0.5);
		Wait(1.5);
		intakeMotor.Set(0);
		shooter.Set(0);
	}
	
	void Autonomous(void)
	{
		gyro.Reset();
		while (IsAutonomous())
		{
			if((gyro.GetAngle()) == 0)
			{
				intakeMotor.Set(0.0);
			}
			else if((gyro.GetAngle()) > 0)
			{
				intakeMotor.Set(0.1);
			}
			else if((gyro.GetAngle()) < 0)
			{
				intakeMotor.Set(-0.1);
			}
			else
			{
				intakeMotor.Set(0.0);
			}
		}
	}

	
	void OperatorControl(void)
	{

		while (IsOperatorControl())
		{
	
			
			frontRight.Set( - ( driveStick.GetX() ) - ( driveStick.GetY() ) );
			frontLeft.Set( - ( driveStick.GetX() ) + ( driveStick.GetY() ) );
			backLeft.Set( - ( driveStick.GetX() ) + ( driveStick.GetY() ) );
			backRight.Set( - ( driveStick.GetX() ) - ( driveStick.GetY() ) );
			
			leftArm.Set( armStick.GetY() );
			rightArm.Set( armStick.GetY() );
			
			if(toolStick.GetRawButton(6))
			{
				intakeMotor.Set(0.7);
			}
			else if(toolStick.GetRawButton(8))
			{
				intakeMotor.Set(-(0.7));
			}
			else
			{
				intakeMotor.Set(0.0);
			}
			
			
			if(toolStick.GetRawButton(4))
			{
				shooter.Set(-1.0);
			}
			else if(toolStick.GetRawButton(3))
			{
				shooter.Set(-0.6);
			}
			else if(toolStick.GetRawButton(1))
			{
				shooter.Set(-0.3);
			}
			else
			{
				shooter.Set(0.0);
			}
			
			
			if(toolStick.GetRawButton(5))
			{
				leftArm.Set(1.0);
				rightArm.Set(1.0);
			}
			else if(toolStick.GetRawButton(7))
			{
				leftArm.Set(-1.0);
				rightArm.Set(-1.0);
			}
			else
			{
				leftArm.Set(0.0);
				rightArm.Set(0.0);
			}
			
			
			Wait(0.005);				// wait for a motor update time
		}
	}
	
	/**
	 * Runs during test mode
	 */
	void Test() {

	}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote
 


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


All times are GMT -5. The time now is 18:25.

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