Go to Post If you have the time to be caught up on Delphi and the Q&A forum, then you have time to go write a WFA entry. No more excuses. Go! Write! Now! :) - Jessica Boucher [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 04-02-2015, 19:39
dash121 dash121 is offline
Registered User
FRC #4085
 
Join Date: Oct 2014
Location: Reynoldsburg Ohio
Posts: 23
dash121 is an unknown quantity at this point
Smile CAN Talon Encoder

Hey I am a programmer on 4085 and we are having a ton of struggle with the new encoders. We have an encoder hooked up directly to the pins on our Talon SR's. We are currently getting position and I have spent 3 hours working on a dry board trying to get it to move forward for 4' and stop. Simple right? But there's a catch! There is no reset encoder position command. So we have no way of making it "zero" at the beginning of autonomous. Now you understand why I had 3 hours at the dry board. Our "get encoder position" command returns a number that doesn't start a "zero". Our "get velocity" command returns a largely changing number so we are calling it "dead" and bugged. We do have the breakout board plugged into the encoders before we plug them into the Talon. What are you guise using this year? We want to know that the pin out on the speed controllers don't work before we just rewire it back to the analog ports. Can you help?

Code:
package org.usfirst.frc.team4085.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;

import org.usfirst.frc.team4085.robot.commands.ExampleCommand;
import org.usfirst.frc.team4085.robot.subsystems.ExampleSubsystem;

import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.smartdashboard.*;
import edu.wpi.first.wpilibj.Encoder;


 
public class Robot extends IterativeRobot {
	
	CANTalon ldrive = new CANTalon(5);
	CANTalon rdrive = new CANTalon(6);
	Joystick lstick = new Joystick(1);
	Joystick rstick = new Joystick(0);
	RobotDrive moving = new RobotDrive(ldrive, rdrive);
	SmartDashboard smart = new SmartDashboard();
	int d;
	int y;
	int z;
	int b;
	Encoder lenc1 = new Encoder(2);
	
	
	
	
	

	public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
	public static OI oi;
	 
	

    Command autonomousCommand;

    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
		oi = new OI();
        // instantiate the command used for the autonomous period
        autonomousCommand = new ExampleCommand();
    
    }
	
	public void disabledPeriodic() {
		Scheduler.getInstance().run();
			
	}

    public void autonomousInit() {
        // schedule the autonomous command (example)
        if (autonomousCommand != null) autonomousCommand.start();
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

    public void teleopInit() {
		// This makes sure that the autonomous stops running when
        // teleop starts running. If you want the autonomous to 
        // continue until interrupted by another command, remove
        // this line or comment it out.
        if (autonomousCommand != null) autonomousCommand.cancel();
        
        
        
      
    }

    /**
     * This function is called when the disabled button is hit.
     * You can use it to reset subsystems before shutting down.
     */
    public void disabledInit(){

    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        Scheduler.getInstance().run();
        moving.tankDrive(rstick,lstick);
      //  moving1.tankDrive(rstick, lstick)
        
        
      
        smart.putString("ldrive Position", Integer.toString(ldrive.getEncPosition()));
        smart.putString("rdrive Position", Integer.toString(rdrive.getEncPosition()));
                
        smart.putString("ldrive Velocity", Integer.toString(ldrive.getEncVelocity()));
        smart.putString("rdrive Velocity", Integer.toString(rdrive.getEncVelocity()));
       
        

             
     
    }
 
    public void testPeriodic() {
    	
    }
}
Reply With Quote
  #2   Spotlight this post!  
Unread 04-02-2015, 19:46
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: CAN Talon Encoder

What ports on the breakout board are the encoders plugged into. You made it wound like they are plugged into the analog ports. The A and B channels from the encoder should be plugged into the corresponding ports on the breakout.

As for resetting the encoder, how about just saving the current value whenever you want to reset it and just add that to your setpoint.
EDIT: Actually ignore this, Neal has a better answer

It would also help to know what type of encoder you are using and to see your autonomous command.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists

Last edited by Ben Wolsieffer : 04-02-2015 at 19:50.
Reply With Quote
  #3   Spotlight this post!  
Unread 04-02-2015, 19:46
Nyxyxylyth Nyxyxylyth is offline
Registered User
AKA: Neal Manson
FRC #1481 (The Riveters)
Team Role: Mentor
 
Join Date: Mar 2013
Rookie Year: 2013
Location: Southfield, MI
Posts: 70
Nyxyxylyth is just really niceNyxyxylyth is just really niceNyxyxylyth is just really niceNyxyxylyth is just really niceNyxyxylyth is just really nice
Re: CAN Talon Encoder

Quote:
Originally Posted by dash121 View Post
There is no reset encoder position command. So we have no way of making it "zero" at the beginning of autonomous.
Why can't you use ldrive->SetPosition(0)? See 13.2 in the Talon SRX Software Reference Manual.
Reply With Quote
  #4   Spotlight this post!  
Unread 04-02-2015, 20:13
ozrien's Avatar
ozrien ozrien is online now
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 531
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
Re: CAN Talon Encoder

Good question Neal

Also, are you using Analog Encoder or Quadrature Encoder?

If you're using Analog encoder be sure to update your Talon to 1.4 and also read the workaround for Functional Limitation 21.17 in the Talon SRX Software Reference Manual.

CANTalon defaults to Quadrature Encoder for the feedbackdevice. Follows the steps in Section 7 for selecting the feedback device (Sensor) and follow 7.4 for selecting the sensor direction correctly.

Use the Self-Test (section 2.4) to see what's going on in the Talon.
Reply With Quote
  #5   Spotlight this post!  
Unread 05-02-2015, 00:17
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
Founder and CEO, DeadMemes Studios
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 403
Poseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud of
Re: CAN Talon Encoder

Quote:
Originally Posted by dash121 View Post
So we have no way of making it "zero" at the beginning of autonomous.
Lowering the elevator/mechanism to the starting position and calling talon.setPosition(0) sets that position as zero for the encoder. We had the same problem as you, and just solved it.
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division
2017 - Team 5817: Return of the bench grinder


Reply With Quote
  #6   Spotlight this post!  
Unread 06-02-2015, 03:29
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 673
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: CAN Talon Encoder

We are trying to read the encoder value by calling leftMotor.getPosition or leftMotor.getEncPosition, both returned zero while the motor is running. Is there a trick to do this? Did I miss some sort of configuration to "enable" encoder on the CANTalon? I hooked the encoder wires to +5V, A, B and GND of the Talon. We are not using the breakout board (they are out-of-stock). We spliced the ribbon cable to a 8-pin molex connector. Encoder should have +5V on pin 2, A on pin 7, B on pin 5 and GND on pin 10. I assume the red wire on the ribbon is pin 1. I checked with a volt meter that pin 2 and pin 10 is indeed 5V to GND. So it means I did not flip the connector backward. In code, aside from instantiate the CANTalon motor controller, the only call we made is to leftMotor.setFeedbackDevice(CANTalon.FeedbackDevic e.QuadEncoder). I am thinking we may not even have to do that if we call getEncPosition. But we set the feedback device anyway so we can also call getPosition. But somehow both calls returned zero. Any help is appreciated.
BTW, everybody said there is new beta firmware for the Talon SRX but nobody seems to know where to download it. A link to it would be nice.
Thanks.
__________________

Last edited by mikets : 06-02-2015 at 03:51.
Reply With Quote
  #7   Spotlight this post!  
Unread 07-02-2015, 07:52
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 673
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: CAN Talon Encoder

Never mind, got it all working. The encoder was mis-wired.
__________________
Reply With Quote
  #8   Spotlight this post!  
Unread 08-02-2015, 13:47
ozrien's Avatar
ozrien ozrien is online now
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 531
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
Re: CAN Talon Encoder

Quote:
Originally Posted by mikets View Post
BTW, everybody said there is new beta firmware for the Talon SRX but nobody seems to know where to download it. A link to it would be nice.
Thanks.
Same place as the documentation...
http://www.crosstheroadelectronics.c...ol_system.html

Also please read the FRC team updates...
http://www.usfirst.org/roboticsprogr...ated-documents
...not only are the updates mentioned (and their links) but you don't want to miss API updates, firmware updates, rule changes, scoring updates, etc...
You can rely on CD for some stuff, but this is the source.
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:08.

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