Go to Post It worked in CAD. - ey206208 [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
  #5   Spotlight this post!  
Unread 08-12-2012, 13:45
CosmicCricket CosmicCricket is offline
Registered User
FRC #2517
 
Join Date: Apr 2012
Location: Vancouver, WA
Posts: 10
CosmicCricket is an unknown quantity at this point
Re: Need help with encoders

What I have so far is some skeleton drive code, and I'm pretty sure the encoders are giving me something because I am getting 0's and 1's depending on the way the motors are spinning. However, GetRaw() is supposed to count up or down, not return 0's and 1's.

The encoders are connected to the DIO slots indicated in the code.

Code:
#include "WPILib.h"

class DefaultRobot : public SimpleRobot{
	Joystick joystick;
	Jaguar leftDriveJag;
	Jaguar rightDriveJag;
	Jaguar combineJag;
	Encoder encoderL;
	Encoder encoderR;
	
	
	
public: 
	DefaultRobot(void):
		joystick(1), 
		leftDriveJag(1), 
		rightDriveJag(5), 
		combineJag(3),
		encoderL(4, 3, false, Encoder::k4X),
		encoderR(2, 1, false, Encoder::k4X)
		
		{
				Watchdog().SetExpiration(.75);
		}
	
	void Autonomous(void){
		
		
	}
	
	void OperatorControl(void){
		Watchdog().SetEnabled(true);
		encoderL.Start();
		encoderR.Start();
		while(IsOperatorControl()){
			Watchdog().Feed();
			//Operator Control
			printf("%d\n", encoderR.GetRaw());
			printf("%d\n", encoderL.GetRaw());
			if (joystick.GetRawAxis(4) > 0.2 || joystick.GetRawAxis(4) < -0.2) { //Deadband of .2
				leftDriveJag.Set(joystick.GetRawAxis(4)); //Run left motors based on left stick value.
			} else {
				leftDriveJag.Set(0); //Set the motors to 0.
			}
			if (joystick.GetRawAxis(2) > .2 || joystick.GetRawAxis(2) < -.2) { //Deadband of .2
				rightDriveJag.Set(joystick.GetRawAxis(2)); //Run right motors based on right stick value
			} else {
				rightDriveJag.Set(0); //Set the right drive motors to 0.
			}
			if (joystick.GetRawButton(2)){
				combineJag.Set(.5);
			} else {
				combineJag.Set(0);
			}
			if(joystick.GetRawButton(3)){
				combineJag.Set(.25);
			} else {
				combineJag.Set(0);
			}
			
			
		}
	}
	
};

START_ROBOT_CLASS(DefaultRobot);

Last edited by CosmicCricket : 08-12-2012 at 13:48.
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 03:34.

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