Go to Post FRC is a big tent. There's room for everybody. - Ether [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 12-02-2014, 17:15
Maxchrist Maxchrist is offline
Registered User
FRC #4458 (Infernobotix)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Center Moriches, NY
Posts: 10
Maxchrist is an unknown quantity at this point
motor encoder java

we are trying to get a magnetic motor encoder (AS5145B from ams) to give values and it only ever gives a value of zero. can someone help us out, we do not know why it isn't reading any pulses/rotations. A sample code would be much appreciated. Thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2014, 17:18
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: motor encoder java

Quote:
Originally Posted by Maxchrist View Post
we are trying to get a magnetic motor encoder (AS5145B from ams) to give values and it only ever gives a value of zero. can someone help us out, we do not know why it isn't reading any pulses/rotations. A sample code would be much appreciated. Thanks
What are you trying to sense (position? speed?) and how do you have it wired?

Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2014, 17:20
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,572
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: motor encoder java

Have you followed the directions here: http://wpilib.screenstepslive.com/s/...control-system
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2014, 17:25
Maxchrist Maxchrist is offline
Registered User
FRC #4458 (Infernobotix)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Center Moriches, NY
Posts: 10
Maxchrist is an unknown quantity at this point
Re: motor encoder java

we are trying to sense position. we have it on an a and b channel plugged into the digital i/0 on port 1 and 2.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2014, 17:28
Maxchrist Maxchrist is offline
Registered User
FRC #4458 (Infernobotix)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Center Moriches, NY
Posts: 10
Maxchrist is an unknown quantity at this point
Re: motor encoder java

@joe yeah
but we are not 100 percent sure how to program it.
Reply With Quote
  #6   Spotlight this post!  
Unread 12-02-2014, 17:48
irvingc irvingc is offline
Registered User
FRC #0948 (Newport Robotics Group)
Team Role: Leadership
 
Join Date: Jan 2014
Rookie Year: 2011
Location: Bellevue, WA
Posts: 31
irvingc is on a distinguished road
Re: motor encoder java

Quote:
Originally Posted by Maxchrist View Post
we are trying to sense position. we have it on an a and b channel plugged into the digital i/0 on port 1 and 2.
This is not the proper wiring to use the encoder as an absolute sensor (position). Refer to the last section of Joe Ross's link.


[ edit ]
Provided you do want to use it as a quadrature, though, you would first create a new Encoder object:
Code:
Encoder encoder = new Encoder(aChannel, bChannel);
Then enable it:
Code:
encoder.start();
Then, you would read it like so:
Code:
encoder.getDistance();
Depending on the application, you may also want to calibrate the distance per pulse:
Code:
encoder.setDistancePerPulse(someConstant);

Last edited by irvingc : 12-02-2014 at 17:56.
Reply With Quote
  #7   Spotlight this post!  
Unread 12-02-2014, 18:34
Maxchrist Maxchrist is offline
Registered User
FRC #4458 (Infernobotix)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Center Moriches, NY
Posts: 10
Maxchrist is an unknown quantity at this point
Re: motor encoder java

@irving that didn't work, I'm not sure whats wrong
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2014, 07:58
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: motor encoder java

Quote:
Originally Posted by Maxchrist View Post
@irving that didn't work, I'm not sure whats wrong
You'll need to post code so we can see what you have done.
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2014, 08:31
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: motor encoder java

Quote:
Originally Posted by notmattlythgoe View Post
You'll need to post code so we can see what you have done.
Also post some pictures showing:

- how you have the encoder mounted

- how you have it wired

(please use camera that can focus close-up)


Reply With Quote
  #10   Spotlight this post!  
Unread 17-02-2014, 11:38
shmet shmet is offline
Registered User
FRC #4178
 
Join Date: Feb 2014
Location: Declo, ID
Posts: 4
shmet is an unknown quantity at this point
Re: motor encoder java

I have also been having an issue with the same symptoms. I am using the AS5145B magnetic encoder. We one PWM wire soldered in to the board as well as the signal part of another PWM wire. PWM wire one is soldered to ground, 5v, and a; PWM wire two is soldered to b. PWM wire one is connected to Digital I/O 3 and PWM wire two is connected to Digital I/O 4.
Here is my code:
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.defaultCode;


import edu.wpi.first.wpilibj.CounterBase.EncodingType;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Watchdog;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Jaguar;
import java.lang.Math;

public class DefaultRobot extends IterativeRobot {
	// Declare variable for the robot drive system

	private int m_dsPacketsReceivedInCurrentSecond;	// keep track of the ds packets received in the current second
	private Encoder catapult;
	private XboxPaddle xboxController;
	// Local variables to count the number of periodic loops performed
	private int m_autoPeriodicLoops;
	private int m_disabledPeriodicLoops;
	private int m_telePeriodicLoops;
	
	private Victor frontLeftDrive;
	private Victor frontRightDrive;
	private Victor backLeftDrive;
	private Victor backRightDrive;
	private Jaguar wench;
	private Jaguar latch;
	private Jaguar intake;
	private Gyro gyro;
	private double magnitude;
	private double direction;
	private Vector vector;
	private double rotation;
	
	private double axis1;
	private double axis2;
	private double axis4;
	private double axis5;
	private double deadZone;
    /**
     * Constructor for this "BuiltinDefaultCode" Class.
     *
     * The constructor creates all of the objects used for the different inputs and outputs of
     * the robot.  Essentially, the constructor defines the input/output mapping for the robot,
     * providing named objects for each of the robot interfaces.
     */
    public DefaultRobot() {
        System.out.println("BuiltinDefaultCode Constructor Started\n");
	    m_dsPacketsReceivedInCurrentSecond = 0;
	}

	/********************************** Init Routines *************************************/

	public void robotInit() {
		// Actions which would be performed once (and only once) upon initialization of the
		// robot would be put here.
	    frontLeftDrive = new Victor (1);
	    frontRightDrive = new Victor (2);
	    backLeftDrive = new Victor (3);
	    backRightDrive = new Victor (4);
	    wench = new Jaguar(5);
	    latch = new Jaguar(6);
	    intake = new Jaguar(7);
	    xboxController = new XboxPaddle(1);
	    catapult = new Encoder(3, 4, true, EncodingType.k4X);
	    System.out.println("RobotInit() completed.\n");
	    //robotDrive.setSafetyEnabled(false);
	    Watchdog.getInstance().kill();
	    gyro = new Gyro(2);
	    deadZone = .15;
	    catapult.setMaxPeriod(.1);
	    catapult.setMinRate(10);
	    catapult.setDistancePerPulse(1024);
	    catapult.setReverseDirection(true);
	    catapult.setSamplesToAverage(7);
	    catapult.start();
	}
	
	private void drive(double multiplier){
	    if (multiplier>Math.abs(1)) return; //make sure a value between -1 and 1 will be received by motor controllers
	    //create deadzones for the xbox controller
	    if (Math.abs(xboxController.getRawAxis(1)) < deadZone) axis1 = 0;
	    else axis1 = xboxController.getRawAxis(1);
	    if (Math.abs(xboxController.getRawAxis(2)) < deadZone) axis2 = 0;
	    else axis2 = xboxController.getRawAxis(2);
	    if (Math.abs(xboxController.getRawAxis(4)) < deadZone) axis4 = 0;
	    else axis4 = xboxController.getRawAxis(4);
	    if (Math.abs(xboxController.getRawAxis(5)) < deadZone) axis5 = 0;
	    else axis5 = xboxController.getRawAxis(5);
	    //set the drive motors
	    frontRightDrive.set((axis2 + axis1)*multiplier);
	    backRightDrive.set((axis2 - axis1)*multiplier);
	    frontLeftDrive.set((axis5 - axis4)*multiplier);
	    backLeftDrive.set((axis5 + axis4)*multiplier);
	}
	
	public void disabledInit() {
		m_disabledPeriodicLoops = 0;		// Reset the loop counter for disabled mode
		startSec = (int)(Timer.getUsClock() / 1000000.0);
		printSec = startSec + 1;
	}

	public void autonomousInit() {
		m_autoPeriodicLoops = 0;				// Reset the loop counter for autonomous mode
	}

	public void teleopInit() {
		m_telePeriodicLoops = 0;				// Reset the loop counter for teleop mode
		m_dsPacketsReceivedInCurrentSecond = 0;	// Reset the number of dsPackets in current second
		//catapult.start();
	}

	/********************************** Periodic Routines *************************************/
	static int printSec;
	static int startSec;

	public void disabledPeriodic()  {
		// feed the user watchdog at every period when disabled
		Watchdog.getInstance().feed();

		// increment the number of disabled periodic loops completed
		m_disabledPeriodicLoops++;

		// while disabled, printout the duration of current disabled mode in seconds
		if ((Timer.getUsClock() / 1000000.0) > printSec) {
			System.out.println("Disabled seconds: " + (printSec - startSec));
			printSec++;
		}
	}

	public void autonomousPeriodic() {
		Watchdog.getInstance().feed();

		m_autoPeriodicLoops++;

	}

	public void teleopPeriodic() {
        Watchdog.getInstance().feed();

        // increment the number of teleop periodic loops completed
        m_telePeriodicLoops++;

	//Drive////////////////////////////////////////////////
        m_dsPacketsReceivedInCurrentSecond++;// increment DS packets received
	drive(1);
	System.out.println(catapult.get());
    }

    int GetLoopsPerSec() {
        return 20;
    }
}
Reply With Quote
  #11   Spotlight this post!  
Unread 17-02-2014, 11:43
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: motor encoder java

Quote:
Originally Posted by shmet View Post
PWM wire one is soldered to ground, 5v, and a;
You are soldering the same wire to ground and 5V?


Reply With Quote
  #12   Spotlight this post!  
Unread 17-02-2014, 12:20
shmet shmet is offline
Registered User
FRC #4178
 
Join Date: Feb 2014
Location: Declo, ID
Posts: 4
shmet is an unknown quantity at this point
Re: motor encoder java

No.
Reply With Quote
  #13   Spotlight this post!  
Unread 17-02-2014, 12:22
shmet shmet is offline
Registered User
FRC #4178
 
Join Date: Feb 2014
Location: Declo, ID
Posts: 4
shmet is an unknown quantity at this point
Re: motor encoder java

I meant to say that the cluster of the three PWM wires are connected to those pins.
Reply With Quote
  #14   Spotlight this post!  
Unread 17-02-2014, 13:03
shmet shmet is offline
Registered User
FRC #4178
 
Join Date: Feb 2014
Location: Declo, ID
Posts: 4
shmet is an unknown quantity at this point
Re: motor encoder java

We got it working. The problem was that we didn't have csn grounded.
Reply With Quote
  #15   Spotlight this post!  
Unread 17-02-2014, 13:07
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: motor encoder java


Just a thought: We might have been able to save you 4 days of troubleshooting had you posted pictures of the wiring.

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 13:15.

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