Go to Post Congratulations! You have been successful! You got what you wished for! Now get to work. - gblake [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 06-12-2012, 22:21
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
Need help with encoders

I'm trying to read from a pair of US Digital E4P-250-250-D-D-D-B encoders, but I'm not sure how to get started with them. I am familiar with coding for FRC, as I have done it for past seasons. However, this is the first time I've been asked to work with encoders.

I've read up on the WPILib API and it looks as if reading from the encoders should be as simple as declaring an encoder, and then sticking encoderName.Get() in a printf statement. As is the case with many things in programming, it is not that easy.

I've already verified that the encoders and the DIO ports they are connected to are returning some sort of signal, so I'm pretty sure the problem is on my end.

Any help with would be really appreciated. Thanks in advance.
Reply With Quote
  #2   Spotlight this post!  
Unread 06-12-2012, 22:42
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Need help with encoders

Quote:
Originally Posted by CosmicCricket View Post
I've read up on the WPILib API and it looks as if reading from the encoders should be as simple as declaring an encoder, and then sticking encoderName.Get() in a printf statement. As is the case with many things in programming, it is not that easy.
You need to .Start() the encoder before it will return any values.
Reply With Quote
  #3   Spotlight this post!  
Unread 06-12-2012, 22:58
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

Whoops, I forgot to mention that part.

Yes, I did start the encoders
Reply With Quote
  #4   Spotlight this post!  
Unread 07-12-2012, 09:28
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Need help with encoders

Let's start at the beginning.

Hardware: How do you have the encoder connected? Where exactly does each of its wires go to?

Software: Show us the relevant code. How are you defining the encoder object? How are you initializing it, and how are you reading its value?

What do you expect to see, and what do you see instead?
Reply With Quote
  #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
  #6   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,561
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 12:54.

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