Go to Post FIRST is not about building a robot, it's about the experience of it all... - Beth Sweet [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 Rating: Thread Rating: 11 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 26-01-2010, 20:36
NerdGuy's Avatar
NerdGuy NerdGuy is offline
Registered User
FRC #2974
 
Join Date: Jan 2010
Location: Atlanta
Posts: 16
NerdGuy is an unknown quantity at this point
2010 Accelerometer I2C Object/Class

Hey so we discovered that the 2010 Accelerometer is not Analog it is Completely Digital.

And the Class the Java API provides is for the 2009 Analog Accelerometer.

It even says in the Documentation that they forgot to write a class for the new accelerometer and will try to add it soon.

But Soon isn't soon enough. (Patience Fail)

Does anyone know how to go about extending the I2C class in order to create a valid Accelerometer Class?

This would be unbelievable helpful.
Thx
__________________
"Life would be so much easier if we only had the source code."
Reply With Quote
  #2   Spotlight this post!  
Unread 26-01-2010, 22:54
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: 2010 Accelerometer I2C Object/Class

I am working on one now. I have a class for an I2C compass which is now working great. Accelerometer is next.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2010, 01:26
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by NerdGuy View Post
Hey so we discovered that the 2010 Accelerometer is not Analog it is Completely Digital.

And the Class the Java API provides is for the 2009 Analog Accelerometer.

It even says in the Documentation that they forgot to write a class for the new accelerometer and will try to add it soon.

But Soon isn't soon enough. (Patience Fail)

Does anyone know how to go about extending the I2C class in order to create a valid Accelerometer Class?

This would be unbelievable helpful.
Thx

It should be trivial to port the C++ version that I posted. http://decibel.ni.com/content/thread/5634
Reply With Quote
  #4   Spotlight this post!  
Unread 29-01-2010, 22:24
NerdGuy's Avatar
NerdGuy NerdGuy is offline
Registered User
FRC #2974
 
Join Date: Jan 2010
Location: Atlanta
Posts: 16
NerdGuy is an unknown quantity at this point
Re: 2010 Accelerometer I2C Object/Class

Thanks,

We converted the code to Java and are going to test it tomorrow.

One thing that we had to change was that instead of using enumerations we used arrays.

This was because the Version of Java the robot is running on does not support the use of enumerations, but i don't see how that could affect the return values.

Again Thanks A Lot!!
__________________
"Life would be so much easier if we only had the source code."
Reply With Quote
  #5   Spotlight this post!  
Unread 01-02-2010, 08:54
NerdGuy's Avatar
NerdGuy NerdGuy is offline
Registered User
FRC #2974
 
Join Date: Jan 2010
Location: Atlanta
Posts: 16
NerdGuy is an unknown quantity at this point
Re: 2010 Accelerometer I2C Object/Class

I am saddened our ported code did not work.

It may be that we just didnt translate some of the syntax correctly or something else IDK.
Returned 0.0

Heres the code

Quote:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.*;

/**
*
* @author ported to Java by Sam Meyer
*
* ADXL345 Accelerometer on I2C.
*
* This class alows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus.
* This class assumes the default (not alternate) sensor address of 0x3A (8-bit address).
*/
public class ADXL345 extends SensorBase
{
private static final int kAddress = 0x3A;
private static final int kPowerCtlRegister = 0x2D;
private static final int kDataFormatRegister = 0x31;
private static final int kDataRegister = 0x32;
private static final double kGsPerLSB = 0.004;

/***********************************************
* PowerCtlFields
* *********************************************/
private static final int kPowerCtl_Link = 0x20;
private static final int kPowerCtl_AutoSleep = 0x10;
private static final int kPowerCtl_Measure = 0x08;
private static final int kPowerCtl_Sleep = 0x04;

/***********************************************
* PowerCtlFields
* *********************************************/
private static final int kDataFormat_SelfTest = 0x80;
private static final int kDataFormat_SPI = 0x40;
private static final int kDataFormat_IntInvert = 0x20;
private static final int kDataFormat_FullRes = 0x08;
private static final int kDataFormat_Justify = 0x04;


/***********************************************
* DataFormat_Range
* *********************************************/
private static final int kRange_2G = 0x00;
private static final int kRange_4G = 0x01;
private static final int kRange_8G = 0x02;
private static final int kRange_16G = 0x03;
/***********************************************
* Axes
* *********************************************/
private static final int kAxis_X = 0x00;
private static final int kAxis_Y = 0x02;
private static final int kAxis_Z = 0x04;

/**
* The Default Constructor
* @param slot The slot of the digital module that the sensor is plugged into.
* The default range is 2G (0x00)
*/
public ADXL345(int slot)
{
this(slot, 0x00); // kRange_2G (0x00) is default
}
/**
* Constructor.
*
* @param slot The slot of the digital module that the sensor is plugged into.
* @param range The range (+ or -) that the accelerometer will measure.
*/
public ADXL345(int slot, int range)
{
m_i2c = null;
DigitalModule module = DigitalModule.getInstance(slot);
m_i2c = module.getI2C(kAddress);
m_i2c.write(kPowerCtlRegister, kPowerCtl_Measure);
m_i2c.write(kDataFormatRegister, kDataFormat_FullRes | (int)range);
}



public static final int[] Axes = {0x00, 0x02, 0x04};

private I2C m_i2c;

/**
*
* @param Axis IMPORTANT Axes must be an integer: X = 0x00, Y = 0x02, Z = 0x04
* @return the acceleration in Gs
*/
public double getAcceleration(int Axis)
{
byte[] rawAccel = new byte[2];
m_i2c.read(kDataRegister + (int)Axis, 2, rawAccel);

// Sensor is little endian... swap bytes
byte temp = rawAccel[0];
rawAccel[0] = rawAccel[1];
rawAccel[1] = temp;

int partialAccel = rawAccel[0] * 0x100 + rawAccel[1];
return partialAccel * kGsPerLSB;
}
}
Please if you see any mistakes post them.

Also if we cant get this to work where do you buy the analog accelerometer from last year?
__________________
"Life would be so much easier if we only had the source code."

Last edited by NerdGuy : 01-02-2010 at 09:00.
Reply With Quote
  #6   Spotlight this post!  
Unread 01-02-2010, 09:12
LeelandS's Avatar
LeelandS LeelandS is offline
Robots don't quit, and neither do I
AKA: Leeland
FRC #1405 (Finney Falcons)
Team Role: Tactician
 
Join Date: Nov 2007
Rookie Year: 2005
Location: Webster, NY
Posts: 545
LeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond reputeLeelandS has a reputation beyond repute
Re: 2010 Accelerometer I2C Object/Class

We also attempted a I2C accelerometer port and read 0.0 on x,y, and z.

I think the next step we may take is to flash our crio for C programming and see if we read anything but 0 in that environment.
__________________
My heart will forever lie with SparX
1126: 2008 - 2011; Where it All Began.
1405: 2013 - Present; A Wanderer is Born.

Work hard, play hard. And maybe someday...
Reply With Quote
  #7   Spotlight this post!  
Unread 01-02-2010, 11:17
NerdGuy's Avatar
NerdGuy NerdGuy is offline
Registered User
FRC #2974
 
Join Date: Jan 2010
Location: Atlanta
Posts: 16
NerdGuy is an unknown quantity at this point
Re: 2010 Accelerometer I2C Object/Class

Does anyone know if they plan to release a new update for Java with support for an I2C Accelerometer anytime soon.

In the documentation it said that they would release it in later update.

Also in case this never works is it legal to use the analog accelerometer from last year and just use the Accelerometer class in Java that was built for the analog Accelerometer?
__________________
"Life would be so much easier if we only had the source code."
Reply With Quote
  #8   Spotlight this post!  
Unread 01-02-2010, 13:32
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by NerdGuy View Post
Does anyone know if they plan to release a new update for Java with support for an I2C Accelerometer anytime soon.

In the documentation it said that they would release it in later update.
I'm not sure if it has been ported to Java or not... I'll check on that.

Quote:
Originally Posted by NerdGuy View Post
Also in case this never works is it legal to use the analog accelerometer from last year and just use the Accelerometer class in Java that was built for the analog Accelerometer?
Yes, it is legal to use the Accelerometers from last year.
Reply With Quote
  #9   Spotlight this post!  
Unread 01-02-2010, 15:00
NerdGuy's Avatar
NerdGuy NerdGuy is offline
Registered User
FRC #2974
 
Join Date: Jan 2010
Location: Atlanta
Posts: 16
NerdGuy is an unknown quantity at this point
Re: 2010 Accelerometer I2C Object/Class

does anyone know where to buy the Analog Accelerometer Breakout ?
__________________
"Life would be so much easier if we only had the source code."
Reply With Quote
  #10   Spotlight this post!  
Unread 01-02-2010, 15:17
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by NerdGuy View Post
does anyone know where to buy the Analog Accelerometer Breakout ?
You can't get the exact board from last year since it was made custom for FIRST... Here is a reasonable replacement: http://www.sparkfun.com/commerce/pro...roducts_id=849

Alternately, you could manufacture your own from the designs posted of last year's boards.

-Joe
Reply With Quote
  #11   Spotlight this post!  
Unread 01-02-2010, 16:33
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: 2010 Accelerometer I2C Object/Class

Here is java class for the ADXL345 when connected as I2C device at default address.

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;



/**
 *
 * digital accelerometer from the 2010 KOP
 *
 * this implementation just gets the 3 axis values and allows setting the range
 *
 * Possible enhancements:
 *      Add access to other features of the chip
 *      Add measurement of error during intialization and set channel offsets
 */
public class ADXL345DigitalAccelerometer extends SensorBase {
    private I2C i2c;
    // default address
    private static final byte kAddress = 0x3A;
    // register map from datasheet
    private static final byte OFSX = 0x1E;
    private static final byte OFSY = 0x1F;
    private static final byte OFSZ = 0x20;
    private static final byte BW_RATE = 0x2C;
    private static final byte  POWER_CTL = 0x2D;
    private static final byte DATA_FORMAT = 0x31;
    private static final byte DATAX0 = 0x32;
    private static final byte DATAY0 = 0x34;
    private static final byte DATAZ0 = 0x36;
    private static final byte FIFO_CTL = 0x38;
    private static final byte FIFO_STATUS = 0x39;

    // would use enums here if we had them
    // BW_RATE 0x2C
    private static final byte BW_RATE_R3200B1600 = 0x0F;
    private static final byte BW_RATE_R1600B0800 = 0x0E;
    private static final byte BW_RATE_R0800B0400 = 0x0D;
    private static final byte BW_RATE_R0400B0200 = 0x0C;
    private static final byte BW_RATE_R0200B0100 = 0x0B;
    private static final byte BW_RATE_R0100B0050 = 0x0A;
    private static final byte BW_RATE_R0050B0025 = 0x09;
    private static final byte BW_RATE_R0025B0012 = 0x08;
    private static final byte BW_RATE_R0012B0006 = 0x07;
    private static final byte BW_RATE_R0006B0003 = 0x06;

    private static final byte BW_RATE_LOW_POWER = 0x10;
    
    // POWER_CTL 0x2D
    private static final byte POWER_CTL_LINK = 0x20;
    private static final byte POWER_CTL_AUTO_SLEEP = 0x10;
    private static final byte POWER_CTL_MEASURE = 0x08;
    private static final byte POWER_CTL_SLEEP = 0x04;
    private static final byte POWER_CTL_WAKEUP8 = 0x00;
    private static final byte POWER_CTL_WAKEUP4 = 0x01;
    private static final byte POWER_CTL_WAKEUP2 = 0x02;
    private static final byte POWER_CTL_WAKEUP1 = 0x03;

    // DATA_FORMAT
    public static final byte DATA_FORMAT_02G = 0x00;
    public static final byte DATA_FORMAT_04G = 0x01;
    public static final byte DATA_FORMAT_08G = 0x02;
    public static final byte DATA_FORMAT_16G = 0x03;

    // store the current
    private byte range = DATA_FORMAT_02G;

    public class ADXL345Exception extends RuntimeException {

        /**
         * Create a new exception with the given message
         * @param message the message to pass with the exception
         */
        public ADXL345Exception(String message) {
            super(message);
        }

    }

    //
    // constuctior with slot number parameter
    //
    public ADXL345DigitalAccelerometer(int slot) {
        i2c = new I2C( DigitalModule.getInstance(slot), kAddress );
    }

    // initialize the sensor
    public void intitialize()
    {
        // set BW_RATE
        i2c.write(BW_RATE, BW_RATE_R0100B0050);
        // set POWER_CTL
        i2c.write(POWER_CTL, POWER_CTL_MEASURE);
    }

    // set the range (default is =/- 2g
    public void setRange( byte rangeParam )
    {
        if ( !( rangeParam == DATA_FORMAT_02G ||
                rangeParam == DATA_FORMAT_04G ||
                rangeParam == DATA_FORMAT_08G ||
                rangeParam == DATA_FORMAT_16G ) )
        {
            throw new ADXL345Exception("Invalid range!");
        }


        range = rangeParam;

        i2c.write(DATA_FORMAT, range);
    }

    // get acceleration routines
    public double getXAxis()
    {
        return getAxis( DATAX0 );
    }

    public double getYAxis()
    {
        return getAxis( DATAY0 );
    }

    public double getZAxis()
    {
        return getAxis( DATAZ0 );
    }

    protected double getAxis( byte registerParam )
    {
        // setup array for our data
        byte[] data = new byte[2];
        // read consecutive registers
        this.i2c.read( registerParam, (byte) data.length, data);

        // convert to 2s complement integer
        // [0] has low byte [1] has the high byte
        // jave does not have unsigned so we have to do it this way
        int intResult = ( data[0] & 0xFF ) | ( data[1] << 8 );

        // convert to double based on 10 bit result
        double returnValue = (double)intResult / 512.0 ;

        // now scale based upon our range
        switch( range )
        {
            case DATA_FORMAT_02G:
                returnValue *= 2.0;
                break;
            case DATA_FORMAT_04G:
                returnValue *= 4.0;
                break;
            case DATA_FORMAT_08G:
                returnValue *= 8.0;
                break;
            case DATA_FORMAT_16G:
                returnValue *= 16.0;
                break;
        }
        return returnValue;
    }
}
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Reply With Quote
  #12   Spotlight this post!  
Unread 01-02-2010, 16:35
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by jhersh View Post
You can't get the exact board from last year since it was made custom for FIRST... Here is a reasonable replacement: http://www.sparkfun.com/commerce/pro...roducts_id=849

Alternately, you could manufacture your own from the designs posted of last year's boards.

-Joe
Note, the sparkfun board is 3.3V not 5.0V so you need to order their bidirectional level converter and 3.3V regulator to make it work.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Reply With Quote
  #13   Spotlight this post!  
Unread 01-02-2010, 16:48
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by charrisTTI View Post
Note, the sparkfun board is 3.3V not 5.0V so you need to order their bidirectional level converter and 3.3V regulator to make it work.
From the sparkfun website:

Quote:
Originally Posted by SparkFun
The ADXL320 can be powered from 2.4V-5.25V.
Surely they aren't just giving irrelevant information.
Reply With Quote
  #14   Spotlight this post!  
Unread 01-02-2010, 17:40
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by jhersh View Post
From the sparkfun website:

Surely they aren't just giving irrelevant information.
Sorry for the confusion. The ADXL345 (same as this year KOP) from sparkfun is 3.3V.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Reply With Quote
  #15   Spotlight this post!  
Unread 01-02-2010, 23:49
NerdGuy's Avatar
NerdGuy NerdGuy is offline
Registered User
FRC #2974
 
Join Date: Jan 2010
Location: Atlanta
Posts: 16
NerdGuy is an unknown quantity at this point
Re: 2010 Accelerometer I2C Object/Class

RAWR!!!

thanks alot for help.

I will try the above I2C class, looks better than ours.
but then again ours was coded on a hope and a prayer seeing that we did not understand any of that low level stuff.

thanks again.

Also thanks for the analog accel link.
__________________
"Life would be so much easier if we only had the source code."
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with 2010 Accelerometer & I2C wt200999 C/C++ 33 08-02-2010 15:16
2010 accelerometer chsr C/C++ 1 22-01-2010 02:28
2010 Accelerometer Documentation? JDM Sensors 13 18-01-2010 12:42
Where to find a Gyro and Accelerometer Sensor Board for 2010 FRC? xSpongeX Sensors 4 18-01-2010 06:17
Accelerometer class - isn't reading zero at rest? oddjob C/C++ 3 02-02-2009 17:11


All times are GMT -5. The time now is 12:09.

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