|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|
#2
|
||||
|
||||
|
Re: motor encoder java
Quote:
|
|
#3
|
||||||
|
||||||
|
Re: motor encoder java
Have you followed the directions here: http://wpilib.screenstepslive.com/s/...control-system
|
|
#4
|
|||
|
|||
|
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.
|
|
#5
|
|||
|
|||
|
Re: motor encoder java
@joe yeah
but we are not 100 percent sure how to program it. |
|
#6
|
|||
|
|||
|
Re: motor encoder java
Quote:
[ 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); Code:
encoder.start(); Code:
encoder.getDistance(); Code:
encoder.setDistancePerPulse(someConstant); Last edited by irvingc : 02-12-2014 at 05:56 PM. |
|
#7
|
|||
|
|||
|
Re: motor encoder java
@irving that didn't work, I'm not sure whats wrong
|
|
#8
|
|||||
|
|||||
|
Re: motor encoder java
You'll need to post code so we can see what you have done.
|
|
#9
|
||||
|
||||
|
Re: motor encoder java
Quote:
- how you have the encoder mounted - how you have it wired (please use camera that can focus close-up) |
|
#10
|
|||
|
|||
|
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;
}
}
|
|
#11
|
||||
|
||||
|
Re: motor encoder java
You are soldering the same wire to ground and 5V?
|
|
#12
|
|||
|
|||
|
Re: motor encoder java
No.
|
|
#13
|
|||
|
|||
|
Re: motor encoder java
I meant to say that the cluster of the three PWM wires are connected to those pins.
|
|
#14
|
|||
|
|||
|
Re: motor encoder java
We got it working. The problem was that we didn't have csn grounded.
|
|
#15
|
||||
|
||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|