Go to Post Wow, that is awfully impressive! How can a guy in the WWF be so smart? Oh, it's LIKE the WWF...:p - DonRotolo [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 07-02-2013, 20:00
Clint3176's Avatar
Clint3176 Clint3176 is offline
Registered User
FRC #3176
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2010
Location: Indiana
Posts: 7
Clint3176 is an unknown quantity at this point
Encoders with Java

Hello,
My team is using encoders (E4P-360-250-D-H-D-B) for the very first time and we are writing in Java. We really don't know where to even begin. We do believe that the encoders are wired correctly. Sample code would be very much appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 07-02-2013, 21:07
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Encoders with Java

Encoder encoder = new Encoder(portA, portB); //ask your electrical team for the pots
encoder.start();
encoder.reset();
System.out.println(encoder.get());

Where are your encoders setup? on the drive train motors?
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2013, 18:34
Clint3176's Avatar
Clint3176 Clint3176 is offline
Registered User
FRC #3176
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2010
Location: Indiana
Posts: 7
Clint3176 is an unknown quantity at this point
Re: Encoders with Java

The encoders are placed on the drive train (wheel axle) and are wired to the digital sidecar. We tried the code you posted and when we run the code we only receive a constant number (most of the time its 0 but sometimes it will gives us numbers such as -2, -32, 1)

P.S
Thank you very much for your quick response and help
Reply With Quote
  #4   Spotlight this post!  
Unread 11-02-2013, 15:44
The_Colonel The_Colonel is offline
Registered User
FRC #4456
 
Join Date: Feb 2013
Location: Washington, DC
Posts: 4
The_Colonel is an unknown quantity at this point
Re: Encoders with Java

Use the function setDistancePerPulse() and set it to 360 (this is based on the model you are using). That should help.
Reply With Quote
  #5   Spotlight this post!  
Unread 11-02-2013, 17:57
Clint3176's Avatar
Clint3176 Clint3176 is offline
Registered User
FRC #3176
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2010
Location: Indiana
Posts: 7
Clint3176 is an unknown quantity at this point
Re: Encoders with Java

We tried that but it seems not matter what we do we only get a value of zero for everything. Could you re-post some working sample code?

Thanks again though
Reply With Quote
  #6   Spotlight this post!  
Unread 11-02-2013, 20:58
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Encoders with Java

Quote:
Originally Posted by Clint3176 View Post
We tried that but it seems not matter what we do we only get a value of zero for everything. Could you re-post some working sample code?

Thanks again though
That sample code still works. Try playing with the PWM values. If it still doesnt work, contact your electrical team
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2013, 18:17
Clint3176's Avatar
Clint3176 Clint3176 is offline
Registered User
FRC #3176
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2010
Location: Indiana
Posts: 7
Clint3176 is an unknown quantity at this point
Re: Encoders with Java

We wired a new encoder to different PWM pins using the code you've (graciously) provided. We will get a single number over and over until we disable then re-enable which will then give us the updated value. Is there a way to update the
System.out.println(encoders.get());
function?
Could this problem be occurring for any other reason?
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2013, 19:03
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Encoders with Java

Quote:
Originally Posted by Clint3176 View Post
We wired a new encoder to different PWM pins using the code you've (graciously) provided. We will get a single number over and over until we disable then re-enable which will then give us the updated value. Is there a way to update the
System.out.println(encoders.get());
function?
Could this problem be occurring for any other reason?
Are you moving the robot..? Is the C-RIO updated to 2013 along with the driver station?
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2013, 19:18
Clint3176's Avatar
Clint3176 Clint3176 is offline
Registered User
FRC #3176
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2010
Location: Indiana
Posts: 7
Clint3176 is an unknown quantity at this point
Re: Encoders with Java

Yes, everything is up to date and we are moving the robot (and the encoder disk is moving with the axle).
Reply With Quote
  #10   Spotlight this post!  
Unread 13-02-2013, 19:47
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Encoders with Java

Quote:
Originally Posted by Clint3176 View Post
Yes, everything is up to date and we are moving the robot (and the encoder disk is moving with the axle).
Could you post your code? I dont think your doing anything wrong...
Reply With Quote
  #11   Spotlight this post!  
Unread 14-02-2013, 18:11
Clint3176's Avatar
Clint3176 Clint3176 is offline
Registered User
FRC #3176
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2010
Location: Indiana
Posts: 7
Clint3176 is an unknown quantity at this point
Re: Encoders with Java

package BasicMecanumDrive;


import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import edu.wpi.first.wpilibj.*;


public class BasicMecanumDrive extends IterativeRobot {
CANJaguar frontLeft, frontRight, backLeft, backRight;

Joystick leftStick, rightStick;
RobotDrive robotDrive;

private final Encoder encoder = new Encoder(13,14);


public void robotInit() {

leftStick = new Joystick(1);
rightStick = new Joystick(2);



try {
frontLeft = new CANJaguar(4);
frontRight = new CANJaguar(1);
backLeft = new CANJaguar(3);
backRight = new CANJaguar(2);

encoder.start();
encoder.reset();

robotDrive = new RobotDrive(frontLeft, backLeft, frontRight, backRight);
} catch (CANTimeoutException ex) {
ex.printStackTrace();
}


}



public void autonomousPeriodic() {

}


public void teleopInit () {


}
public void teleopPeriodic() {
robotDrive.mecanumDrive_Cartesian(rightStick.getX( ), rightStick.getY(), -leftStick.getY(), 0);


if (encoder.getRaw()> 20000) {
System.out.println("Gots It");
}
System.out.println(encoder.get());

DriverStationLCD.getInstance().println(DriverStati onLCD.Line.kUser2, 2, "Encoder"+ encoder.get());
DriverStationLCD.getInstance().updateLCD();



}

}



Here's our code currently. We are just running a few things to eliminate potential problems from other systems.
Reply With Quote
  #12   Spotlight this post!  
Unread 12-03-2013, 02:05
kidteddy kidteddy is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: New York
Posts: 1
kidteddy is an unknown quantity at this point
Re: Encoders with Java

Hi,
I also started using encoders this year. After reading this thread and researching online in the past few weeks, I understood part of programming encoders. Now, I'm just wondering how to move the bot x feet in autonomous using encoders on drivetrain. What methods do I use if I want the bot to move forward, let's say, for 7 feet? If you provide me with sample code for this, it would be greatly appreciated. I'm writing in java commandbased, and drivetrain that consists of left and right motors where encoders mounted on each side.
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 11:20.

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