Mindsensors AbsoluteIMU-ACG

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Mindsensors AbsoluteIMU-ACG

Postby Stone » Thu Dec 20, 2012 1:33 pm

Hi,
I was wondering if someone has interest in implementing the mindsensors AbsoluteIMU-ACG in the lejos API.
Because I wan't to buy that sensor from mindsensors but I haven't yet the knowledge to make my own classes for using this sensor.

Gratz, Stone
Stone
Novice
 
Posts: 27
Joined: Tue Apr 10, 2012 4:29 pm
Location: Belgium

Re: Mindsensors AbsoluteIMU-ACG

Postby mtbradle » Sun Jan 06, 2013 8:25 pm

I'm interested in this too. I might take a shot at implementing this myself if I don't hear anything.
mtbradle
New User
 
Posts: 8
Joined: Wed Nov 24, 2010 7:33 pm

Re: Mindsensors AbsoluteIMU-ACG

Postby kirkpthompson » Mon Jan 07, 2013 2:11 am

Send me the sensor and I will write a driver for it. ;-)

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: Mindsensors AbsoluteIMU-ACG

Postby skoehler » Mon Jan 07, 2013 3:07 am

Rudolf Lapie started writing a driver last October. But I haven't heard from him since. I contacted him.
skoehler
leJOS Team Member
 
Posts: 1399
Joined: Thu Oct 30, 2008 4:54 pm

Re: Mindsensors AbsoluteIMU-ACG

Postby mtbradle » Mon Jan 07, 2013 2:57 pm

Actually, parts of this seem to be done already. If you look in the API, there is a CompassMindSensor and AccelMindSensor:

http://lejos.sourceforge.net/nxt/nxj/ap ... ensor.html
http://lejos.sourceforge.net/nxt/nxj/ap ... ensor.html

At first glance, I believe these will work with the ACG model. The only thing I can't seem to find is a Gyro implementation. So creating a full driver under one class should be easy, as you could simply use the code from the above two classes, and then implement the Gyro side of things. There is code in NXC for it as well that could be used as a reference while you do it in Java.

I just ordered my AbsoluteIMU-ACG yesterday and plan on doing just that once it arrives. I'll let you know how it goes.
mtbradle
New User
 
Posts: 8
Joined: Wed Nov 24, 2010 7:33 pm

Re: Mindsensors AbsoluteIMU-ACG

Postby BlueHaze » Mon Feb 25, 2013 9:45 am

Hello,

I started developing a driver for the Absolute IMU and a test program to check its function.

Usage : The driver has 4 inner classes (one for each sensor : accelerometer, tilt sensor, gyroscope and compass). Simply create those that your model supports to start reading its values. The testprogram shows all values from the 4 sub-sensors. It shows the actual values on the screen of the brick and shows a chart on the PC for historic data. Before starting you will need to setup a bluetooth connection on the PC to your brick. Then run the program on the brick, start 'nxjchartinglogger.bat' (in the bin subfolder of the LEJOS program) and connect to your brick from nxjchartinglogger. This should start showing 10 lines with the data. Now shake your IMU and the charts should go bezerk.

You can download everything here : http://my.rapidshare.com/BlueHaze/17095

Let me know if you have any issues with it or made enhancements to the driver.

Kind regards,
BlueHaze.
BlueHaze
New User
 
Posts: 2
Joined: Thu Dec 24, 2009 3:11 pm

Re: Mindsensors AbsoluteIMU-ACG

Postby hwkramer » Sat Sep 28, 2013 6:05 pm

Hi,

I would be interested in the Mindsensors AbsoluteIMU-ACG leJOS examples made available by BlueHaze.

Unfortunately, the given Rapidshare-Link does not work anymore.

Could somebody care to upload this code anywhere else.

Thanks in advance!

Hans
hwkramer
New User
 
Posts: 2
Joined: Thu Sep 26, 2013 9:09 am

Re: Mindsensors AbsoluteIMU-ACG

Postby nikolaj » Mon Nov 11, 2013 9:11 pm

I too would like to use the AbsoluteIMU-ACG driver.

Unfortunately, the link is still invalid.

regards
Nikolaj
nikolaj
New User
 
Posts: 1
Joined: Sun Oct 06, 2013 4:36 pm

Re: Mindsensors AbsoluteIMU-ACG

Postby Baschdl » Tue Dec 24, 2013 1:36 pm

Hi,

I implemented the AbsoluteIMU-ACG and gloomyandy reviews it. You can download it from https://www.dropbox.com/s/6g42r24cvol6j ... U_ACG.java

I also wrote classes for the LightSensorArray and NXTVoltMeter.
https://www.dropbox.com/s/ikhhp9ovv77bx ... Array.java
https://www.dropbox.com/s/30jwl3fpdul8i ... Meter.java

Regards,
Baschdl
Baschdl
New User
 
Posts: 8
Joined: Fri Jul 05, 2013 8:29 pm

Re: Mindsensors AbsoluteIMU-ACG

Postby Baschdl » Sat Feb 01, 2014 1:07 pm

Sorry, the links don't work anymore. Here's the code:

AbsoluteIMU-ACG:

Code: Select all
import lejos.nxt.I2CPort;
import lejos.nxt.I2CSensor;
import lejos.util.Delay;

public class AbsoluteIMU_ACG extends I2CSensor {
   /**
    * @author Sebastian Bischoff (sebastian@salzreute.de)
    */

   /**
    *
    * @param port
    *            The port where the sensor is plugged, for example
    *            "SensorPort.S1"
    * @param address
    *            The I2C bus address of AbsoluteIMU_ACG
    */
   public AbsoluteIMU_ACG(I2CPort port, int address) {
      super(port, address, I2CPort.LEGO_MODE, TYPE_LOWSPEED_9V);
   }

   /**
    *
    * @param port
    *            The port where the sensor is plugged, for example
    *            "SensorPort.S1"
    */
   public AbsoluteIMU_ACG(I2CPort port) {
      super(port, 0x22 /* DEFAULT_I2C_ADDRESS */, I2CPort.LEGO_MODE,
            TYPE_LOWSPEED);
   }

   private byte[] bufTilt = { -99, -99, -99 };
   private byte[] bufAccelerometer = { -99, -99, -99, -99, -99, -99 };
   private byte[] bufCompass = { -99, -99 };
   private byte[] bufMagneticField = { -99, -99, -99, -99, -99, -99 };
   private byte[] bufGyro = { -99, -99, -99, -99, -99, -99 };
   private byte[] bufFilterValue = { -99 };

   private final static byte COMMAND = 0x41;

   public enum Command {
      CALIBRATE_COMPASS_BEGIN('C'), CALIBRATE_COMPASS_END('c'), SET_SENSITIVITY_2G(
            '1'), SET_SENSITIVITY_4G('2'), SET_SENSITIVITY_8G('3'), SET_SENSITIVITY_16G(
            '4');

      final char value;

      private Command(char value) {
         this.value = value;
      }
   }

   /**
    * @param cmd
    *            The command which is sent to the AbsoluteIMU_ACG.
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */

   public int sendCommand(Command cmd) {
      return sendData(COMMAND, (byte) cmd.value);
   }


   /**
    * Starts the calibration of the Compass.
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int calibrateCompassBegin() {
      return this.sendCommand(Command.CALIBRATE_COMPASS_BEGIN);
   }

   /**
    * Ends the calibration of the Compass.
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int calibrateCompassEnd() {
      return this.sendCommand(Command.CALIBRATE_COMPASS_END);
   }

   /**
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int setSensitivity2G() {
      return this.sendCommand(Command.SET_SENSITIVITY_2G);
   }

   /**
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int setSensitivity4G() {
      return this.sendCommand(Command.SET_SENSITIVITY_4G);
   }

   /**
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int setSensitivity8G() {
      return this.sendCommand(Command.SET_SENSITIVITY_8G);
   }

   /**
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int setSensitivity16G() {
      return this.sendCommand(Command.SET_SENSITIVITY_16G);
   }

   /**
    * Returns the Tilt data from the Accelerometer
    *
    * @return Array of ints: x-axis-tilt, y-axis-tilt, z-axis-tilt; -1 when an
    *         error occured
    */
   public int[] getTiltData() {
      int[] ret = new int[3];

      int err = getData(0x42, bufTilt, 3);
      if (err == 0) {
         for (int i = 0; i < 3; i++) {
            ret[i] = bufTilt[i] & 0xff;
         }
      } else {
         for (int i = 0; i < 3; i++) {
            ret[i] = -1;
         }
      }

      return ret;
   }

   /**
    * Returns the acceleration data from the Accelerometer
    *
    * @return Array of ints: x-axis-acceleration, y-axis-acceleration,
    *         z-axis-acceleration; -1 when an error occured
    */
   public int[] getAcceleration() {
      int[] ret = new int[3];

      int err = getData(0x45, bufAccelerometer, 6);
      if (err == 0) {
         int j = 0;
         for (int i = 0; i < 3; i++) {

            ret[i] = (bufAccelerometer[j] & 0xff)
                  + ((bufAccelerometer[j + 1] & 0xff) * 256);
            j = j + 2;
         }
      } else {
         for (int i = 0; i < 3; i++) {
            ret[i] = -1;
         }
      }

      return ret;
   }

   /**
    * Returns the Compass heading from the Compass
    *
    * @return Returns the Compass Heading; -1 when an error occured
    */
   public int getCompassHeading() {
      int ret = -1;

      int err = getData(0x4B, bufCompass, 2);
      if (err == 0) {

         ret = (bufCompass[0] & 0xff) + ((bufCompass[1] & 0xff) * 256);

      }

      return ret;
   }

   /**
    * Returns the raw Magnetic field from the Accelerometer
    *
    * @return Array of ints: Magnetic field along x-axis, Magnetic field along
    *         y-axis, Magnetic field along z-axis; -1 when an error occured
    */
   public int[] getMagneticField() {
      int[] ret = new int[3];

      int err = getData(0x4D, bufMagneticField, 6);
      if (err == 0) {
         int j = 0;
         for (int i = 0; i < 3; i++) {

            ret[i] = (bufMagneticField[j] & 0xff)
                  + ((bufMagneticField[j + 1] & 0xff) * 256);
            j = j + 2;
         }
      } else {
         for (int i = 0; i < 3; i++) {
            ret[i] = -1;
         }
      }

      return ret;
   }

   /**
    * Returns the Gyro data from the Accelerometer
    *
    * @return Array of ints: x-axis Gyro data, y-axis Gyro data, z-axis Gyro
    *         data; -1 when an error occured
    */
   public int[] getGyro() {
      int[] ret = new int[3];

      int err = getData(0x53, bufGyro, 6);
      if (err == 0) {
         int j = 0;
         for (int i = 0; i < 3; i++) {

            ret[i] = (bufGyro[j] & 0xff) + ((bufGyro[j + 1] & 0xff) * 256);
            j = j + 2;
         }
      } else {
         for (int i = 0; i < 3; i++) {
            ret[i] = -1;
         }
      }

      return ret;
   }

   public int getFilter() {
      int ret = -1;
      int err = getData(0x5A, bufFilterValue, 1);
      if (err == 0) {
         ret = bufFilterValue[0];
      }
      return ret;
   }

   /**
    *
    * @param newFilterValue
    *            New filter value between 0 and 7, 4 is the default value. 0
    *            means no filter (fast), 7 is the highest filter.
    * @return
    */
   public int setFilter(int newFilterValue) {
      int ret = -1;
      if (newFilterValue > 7 || newFilterValue < 0) {
         throw new IllegalArgumentException(
               "Filter value MUST be between 0 and 7!");
      } else {
         int err = sendData(0x5A, (byte) newFilterValue);
         if (err == 0) {
            ret = 0;
         }
      }
      return ret;
   }
   // Only code to test this class
   // public void testWriteReadFilter(int exampleValue) {
   // System.out.println(sendData(0x5A, (byte) exampleValue));
   // Delay.msDelay(1000);
   // System.out.println(getData(0x5A, bufFilterValue, 1));
   // Delay.msDelay(1000);
   // System.out.println(bufFilterValue[0]);
   // if (exampleValue == bufFilterValue[0]) {
   // System.out.println("Connection works");
   // } else {
   // System.out.println("Connection doesn't work");
   // }
   // Delay.msDelay(1000);
   // }
   //
   // public void testWriteReadCompass(int exampleValue) {
   // System.out.println(sendData(0x50, (byte) exampleValue));
   // Delay.msDelay(1000);
   // System.out.println(getData(0x50, bufCompass, 1));
   // Delay.msDelay(1000);
   // System.out.println(bufCompass[0]);
   // if (exampleValue == bufCompass[0]) {
   // System.out.println("Connection works");
   // } else {
   // System.out.println("Connection doesn't work");
   // }
   // Delay.msDelay(1000);
   // }
}


LightSensorArray:

Code: Select all
import lejos.nxt.I2CPort;
import lejos.nxt.I2CSensor;

/**
 * @author MisterErwin, skoehler and Sebastian Bischoff (sebastian@salzreute.de)
 *
 *         {@link http://lejos.sourceforge.net/forum/viewtopic.php?f=7&t=4312}
 *         Information from {@link http
 *         ://www.mindsensors.com/index.php?module=documents
 *         &JAS_DocumentManager_op= downloadFile&JAS_File_id=1260}
 */
public class LightSensorArray extends I2CSensor {

   byte[] buf = new byte[8];

   private final static byte COMMAND = 0x41;

   public enum Command {
      CALIBRATE_WHITE('W'), CALIBRATE_BLACK('B'), SLEEP('D'), WAKEUP('P'), FREQ_60HZ(
            'A'), FREQ_50HZ('E'), FREQ_UNIVERSAL('U');

      private Command(char value) {
         this.value = value;
      }

      final char value;
   }

   /**
    *
    * @param port
    *            The port where the sensor is plugged, for example
    *            "SensorPort.S1"
    * @param address
    *            The I2C bus address of LightSensorArray
    */

   public LightSensorArray(I2CPort port, int address) {
      super(port, address, I2CPort.LEGO_MODE, TYPE_LOWSPEED_9V);
   }

   /**
    *
    * @param port
    *            The port where the sensor is plugged, like "SensorPort.S1"
    */

   public LightSensorArray(I2CPort port) {
      this(port, 0x14 /* DEFAULT_I2C_ADDRESS */);
   }

   /**
    *
    * @param cmd
    *            The command which is sent to the LightSensorArray.
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */

   public int sendCommand(Command cmd) {
      return sendData(COMMAND, (byte) cmd.value);
   }

   /**
    * Sets an new I2C-address for the LightSensorArray
    *
    * @param newAddress
    *            The new I2C-address of the LightSensorArray
    */
   public void newI2CAddress(byte newAddress) {
      this.sendData(COMMAND, (byte) 0xA0);
      this.sendData(COMMAND, (byte) 0xAA);
      this.sendData(COMMAND, (byte) 0xA5);
      this.sendData(COMMAND, newAddress);
   }

   /**
    * Configure LightSensorArray for US region and other regions with 60 Hz
    * electrical frequency.
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int configureUS() {
      return this.sendCommand(Command.FREQ_60HZ);
   }

   /**
    * Configure LightSensorArray for EU region and other regions with 50 Hz
    * electrical frequency.
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int configureEU() {
      return this.sendCommand(Command.FREQ_50HZ);
   }

   /**
    * Configure LightSensorArray for universal frequency so you can use it
    * everywhere, this is the default mode.
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int configureUniversal() {
      return this.sendCommand(Command.FREQ_UNIVERSAL);
   }

   /**
    * Wakes up the LightSensorArray. The sensor wakes up on its own when any
    * activity begins.
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int wakeUp() {
      return this.sendCommand(Command.WAKEUP);
   }

   /**
    * Put the LightSensorArray to sleep. After 1 minute of inactivity the
    * sensor goes automatically to sleep. "Sleep"-mode conserves power (Current
    * Consumption: 3.0 mA in "Sleep"-mode, while awake max 5.7 mA).
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int sleep() {
      return this.sendCommand(Command.SLEEP);
   }

   /**
    * Calibrates black (All sensors should be on a black surface)
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */

   public int calibrateBlack() {
      return this.sendCommand(Command.CALIBRATE_BLACK);
   }

   /**
    * Calibrates white (All sensors should be on a white surface)
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */

   public int calibrateWhite() {
      return this.sendCommand(Command.CALIBRATE_WHITE);
   }

   /**
    * Gets a value from one Light Sensor
    *
    * @param slot
    *            The slot on the Light Sensor Array
    * @return the Light Value
    * @throws IllegalArgumentException
    *             If slot is not between 0 and 7
    */
   public int getLightValue(int slot) {
      if (slot > 7 || slot < 0) {
         throw new IllegalArgumentException("Slot MUST be between 0 and 7!");
      }

      int b = getData(0x42, buf, 1);

      return (b == 0 ? (buf[0] & 0xff) : -1);
   }

   /**
    * Gets the values from the LightSensorArray
    *
    * @return Array of ints
    */
   public int[] getLightValues() {
      int[] ret = new int[8];

      int err = getData(0x42, buf, 8);
      if (err == 0) {
         for (int i = 0; i < 8; i++)
            ret[i] = buf[i] & 0xff;
      } else {
         for (int i = 0; i < 8; i++)
            ret[i] = -1;
      }

      return ret;
   }

}


NXTVoltMeter:

Code: Select all
import lejos.nxt.I2CPort;
import lejos.nxt.I2CSensor;

/**
 * @author Sebastian Bischoff (sebastian@salzreute.de)
 *
 */
public class NXTVoltMeter extends I2CSensor {

   byte[] bufAbsoluteVoltage = new byte[2];
   byte[] bufRelativeVoltage = new byte[2];
   byte[] bufReferenceVoltage = new byte[2];

   private final static byte COMMAND = 0x41;

   public enum Command {
      ChangeReferenceVoltage('d');

      private Command(char value) {
         this.value = value;
      }

      final char value;
   }

   /**
    *
    * @param port
    *            The port where the sensor is plugged, for example
    *            "SensorPort.S1"
    * @param address
    *            The I2C bus address of NXTVoltMeter
    */

   public NXTVoltMeter(I2CPort port, int address) {
      super(port, address, I2CPort.LEGO_MODE, TYPE_LOWSPEED_9V);
   }

   /**
    *
    * @param port
    *            The port where the sensor is plugged, like "SensorPort.S1"
    */

   public NXTVoltMeter(I2CPort port) {
      this(port, 0x26 /* DEFAULT_I2C_ADDRESS */);
   }

   /**
    *
    * @param cmd
    *            The command which is sent to the NXTVoltMeter.
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */

   public int sendCommand(Command cmd) {
      return sendData(COMMAND, (byte) cmd.value);
   }

   /**
    * Gets the absolute value from the NXTVoltMeter
    *
    * @return int value
    */
   public int getAbsoluteVoltage() {
      int ret = -99;

      int err = getData(0x43, bufAbsoluteVoltage, 2);
      if (err == 0) {
         ret = bufAbsoluteVoltage[0] & 0xff + bufAbsoluteVoltage[1] & 0xff;
      } else {
         ret = -1;
      }

      return ret;
   }
   /**
    * Gets the relative value from the NXTVoltMeter
    *
    * @return int value
    */
   public int getRelativeVoltage() {
      int ret = -99;

      int err = getData(0x45, bufRelativeVoltage, 2);
      if (err == 0) {
         ret = bufRelativeVoltage[0] & 0xff + bufRelativeVoltage[1] & 0xff;
      } else {
         ret = -1;
      }

      return ret;
   }
   /**
    * Gets the reference value from the NXTVoltMeter
    *
    * @return int value
    */
   public int getReferenceVoltage() {
      int ret = -99;

      int err = getData(0x47, bufReferenceVoltage, 2);
      if (err == 0) {
         ret = bufReferenceVoltage[0] & 0xff + bufReferenceVoltage[1] & 0xff;
      } else {
         ret = -1;
      }

      return ret;
   }

   /**
    *
    * @param newFilterValue
    *            New Reference Voltage value.
    * @return error Negative number when a error occured, 0 otherwise.
    */
   public int setReferenceVoltage(int newReferenceVoltage) {
      int ret = -1;
      int err = sendData(0x47, (byte) newReferenceVoltage);
      if (err == 0) {
         ret = 0;

      }
      return ret;
   }

   /**
    * Change Reference voltage to current absolute voltage.
    *
    * @return Returns 0 when no error occured and a negative number when an
    *         error occured.
    */
   public int writeCurrentAbsoluteVoltage() {
      return this.sendCommand(Command.ChangeReferenceVoltage);
   }
}


Regards
Baschdl
Baschdl
New User
 
Posts: 8
Joined: Fri Jul 05, 2013 8:29 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff