|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Accelerometer java code problems. Returns zero.
/*
* To change this template, choose Tools | Templates * and open the template in the editor. */ package edu.wpi.first.wpilibj.templates.subsystems; import edu.wpi.first.wpilibj.ADXL345_I2C; import edu.wpi.first.wpilibj.command.Subsystem; import edu.wpi.first.wpilibj.templates.RobotTemplate; import edu.wpi.first.wpilibj.Accelerometer; /** * * @author Developer */ public class ADXL extends Subsystem{ public ADXL() { super("accelerometer"); } protected void initDefaultCommand() { } public void printAcceleration() { ADXL345_I2C.AllAxes aa = RobotTemplate.getADXL().getAccelerations(); System.out.println("X: " + aa.XAxis); System.out.println("y: " + aa.YAxis); System.out.println("z: " + aa.ZAxis); } } here is our code. We're not sure why our accelerometer outputs zeros. Is it initialized right? Is there a better way to get the axis values? We're calling it from RobotTemplate, where the accelerometer is initialized as:adxl = new ADXL345_I2C(1, ADXL345_I2C.DataFormat_Range.k2G); We're wired to the I2C on the sidecar using a pair of double-female wires (0V,SCL,SDA,5V) so we're pretty sure we don't have wiring issues. Last edited by l0stboy : 11-02-2012 at 19:20. Reason: wiring details, new code |
|
#2
|
|||
|
|||
|
Re: Accelerometer java code problems. Returns zero.
For what it's worth - we're having exactly the same problem. The connectivity in the wiring is there, the pin connections are correct, and the test code doesn't get much simpler. But it seems to be a common issue if you look at other threads.
|
|
#3
|
|||
|
|||
|
Re: Accelerometer java code problems. Returns zero.
For what it's worth - in our case, the fix for this was to switch from the 'round' cable to the ribbon cable in connecting the digital sidecar to the cRIO module. We did that and all of a sudden starting getting values.
We are using the older 8-slot cRIO, and two of the 3 wire PWM cables (with two wires in each) to connect the accelerometer to the I2C connection on the sidecar. Our test code was pretty much the same as the first posting. |
|
#4
|
|||
|
|||
|
Re: Accelerometer java code problems. Returns zero.
The weird thing is if I remember correctly our problem was fixed by switching to the flat cable, but nothing else worked with the flat cable for us
|
|
#5
|
|||
|
|||
|
Re: Accelerometer java code problems. Returns zero.
We have always been using the flat cable, but the problem persists.
|
|
#6
|
|||
|
|||
|
Re: Accelerometer java code problems. Returns zero.
I had terrible issues trying to read the accelerometer. The eventual solution was to use a short I2C cable between the accelerometer and the digital breakout board. Keep it under 12", if that does not work make one that is 6" long and see if that help.
Good luck, I feel your pain Steve |
|
#7
|
||||
|
||||
|
Re: Accelerometer java code problems. Returns zero.
We had the same problem and switching to a ribbon ccable fixed it, but are you sure that aa.XAxis); is right? we do "x is" +accel.getAcceleration(ADXL345_I2C.Axes.kX); well about that,
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|