Go to Post I know alot of the rookie teams were helped out alot this year. Do the same thing for the rookie Volunteers as well. - wilsonmw04 [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

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   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
  #2   Spotlight this post!  
Unread 08-12-2012, 15:15
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,562
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Need help with encoders

Quote:
Originally Posted by CosmicCricket View Post
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.
An encoder that only returns 0 or 1 indicates that the B input is not working. I would double check your wiring and encoders.
Reply With Quote
Reply


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:23.

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