Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Reset Cruizcore Sensor #29

Open
jabrena opened this issue Oct 22, 2016 · 13 comments
Open

Reset Cruizcore Sensor #29

jabrena opened this issue Oct 22, 2016 · 13 comments

Comments

@jabrena
Copy link
Member

jabrena commented Oct 22, 2016

I need to find a solution to Reset the sensor using a I2C Block. Exist a solution for Arduino and to reading I2C registers but I am not sure if exist a solution to write.

I2C Registers:
XGL_PORT = 1; // Physical port in the EV3 block can be 1 to 4
XGL_ADDR = 0x02; // XG1300L device I2C address, this cannot be changed
XGL_RESET_REG = 0x60; // XG1300L reset register
message = {XGL_ADDR, XGL_RESET};
// I2Cwrite(port, return_len, buffer)
I2Cwrite(XGL_PORT, 0, message);

Arduino I2C Block:
http://www.dexterindustries.com/howto/connecting-ev3-arduino/
https://engmuhannadalkhudari.wordpress.com/2016/02/11/nxtev3-arduino-i2c-ultimate-guide/

EV3 Read I2C Block:
http://www.mindsensors.com/blog/how-to/check-basic-information-of-your-i2c-sensors

LeJOS Driver:
http://www.lejos.org/ev3/docs/lejos/hardware/sensor/CruizcoreGyro.html
https://sourceforge.net/p/lejos/ev3/code/ci/master/tree/ev3classes/src/lejos/hardware/sensor/CruizcoreGyro.java

NXT I2C Blocks:
http://www.teamhassenplug.org/NXT/NXTGAdditions.html

@jabrena
Copy link
Member Author

jabrena commented Nov 6, 2016

I receive and answer from Minfinity but using a Textual programming language:

The XG1300L device resets the angle value every time it is restarted.
The EV3G block that we provide resets the device every time you start
your program, but it does not provide the functionality to do so after
the program has started. Nevertheless our EV3 Block [1] is open source
and could be modified to add these function using a free version of
Labview [2].

The second alternative that you propose is valid. The way it works is
by addressing the RESET register. This is done by writing to the
XG1300L I2C address (0x2) the character 0x60 (reset register) without
expecting any return value. The following c-like pseudocode show the
process:
XGL_PORT = 1; // Physical port in the EV3 block can be 1 to 4
XGL_ADDR = 0x02; // XG1300L device I2C address, this cannot be changed
XGL_RESET_REG = 0x60; // XG1300L reset register
message = {XGL_ADDR, XGL_RESET};
// I2Cwrite(port, return_len, buffer)
I2Cwrite(XGL_PORT, 0, message);

I need to find a solution using EV3G

jabrena added a commit that referenced this issue Nov 6, 2016
@jabrena
Copy link
Member Author

jabrena commented Nov 6, 2016

I have written to Minfinity to know if with the Dexter I2C block is possible to send to the address 0x02 the register 0x60 to the sensor, in order to reset the sensor.

Besides, I have just sent a request to Dexter about the usage of the I2C Block in the forum.
http://forum.dexterindustries.com/t/doubt-with-the-i2c-block/2017

I think that the idea is right, re-reading this article from dexter:
http://www.dexterindustries.com/howto/connecting-ev3-arduino/

"For a 1 byte write, change the function to Write 1 Byte and enter the byte that you want to send to the Arduino. When you start the program, the EV3 will send the data to the Arduino and the Arduino will display the data on the Serial Terminal."

Another interesting article about the usage of I2C Block from Dexter is:
https://engmuhannadalkhudari.wordpress.com/2016/02/11/nxtev3-arduino-i2c-ultimate-guide/

@jabrena
Copy link
Member Author

jabrena commented Nov 6, 2016

I am using this 7 bits table:
http://www.neurophys.wisc.edu/comp/docs/ascii/

@jabrena
Copy link
Member Author

jabrena commented Nov 6, 2016

An interesting doc from EV3Dev:
http://www.ev3dev.org/docs/sensors/i2c-sensor-addressing/

@jabrena
Copy link
Member Author

jabrena commented Nov 6, 2016

""

@jabrena jabrena changed the title Research a way to reset Cruizcore Sensor Reset Cruizcore Sensor Nov 6, 2016
@jabrena jabrena added the I2C label Nov 6, 2016
@jabrena
Copy link
Member Author

jabrena commented Nov 9, 2016

It is possible to read the values from I2C Registers:
http://www.neurophys.wisc.edu/comp/docs/ascii/ (This link help in the process to convert HEX to Decimal)

@jabrena
Copy link
Member Author

jabrena commented Nov 9, 2016

Now, it is necessary to discover the calculus for the 5 outputs of the block.
Many thanks @DexterInd for the technical support and excellent EV3G I2C Block:
http://forum.dexterindustries.com/t/doubt-with-the-i2c-block/2017

@jabrena
Copy link
Member Author

jabrena commented Nov 12, 2016

@jabrena
Copy link
Member Author

jabrena commented Nov 13, 2016

@jabrena
Copy link
Member Author

jabrena commented Nov 14, 2016

The key point:

The inertial sensors in the CruizCore XG1300L are factory calibrated and the measurements provided in the form of signed short integers (16 bits or two bytes). The two bytes represent the sensor reading multiplied by a scale factor of 100.

The block used only read the first byte.

@jabrena
Copy link
Member Author

jabrena commented Nov 14, 2016

@jabrena
Copy link
Member Author

jabrena commented Nov 16, 2016

New answer from Minfinity:

I am glad you were able to read data using the I2C module directly.
You can access a total of 10 registers starting in address 66 (decimal). And your description in the comments section of your program is correct.
Angle = (LSB_66 + MSB_67 * 256) / 100; // (deg)
Rate = (LSB_67 + MSB_68 * 256) / 100; // (deg / sec)
AccX = (LSB_69 + MSB_70 * 256) / ACC_RANGE / 2; // (m / sec^2)
AccY = (LSB_71 + MSB_72 * 256) / ACC_RANGE / 2; // (m / sec^2)
AccZ = (LSB_73 + MSB_73 * 256) / ACC_RANGE / 2; // (m / sec^2)

ACC_RANGE can be 2, 4, or 8

You should also be able to reset the Angle value to zero by writing to the address 96 (decimal).

The Rate information can be integrated over time to compute angle as follows:
Angle_from_rate = 0 ; // Only during the initialization

Angle_from_rate = Angle_from_rate + Rate * PERIOD

However, this only works if PERIOD is constant or variable but known (not sure if this can be done in the EV3 dev environment).

A work around is to use the Angle value to compute the Angle difference and avoid having to deal with the PERIOD as follows
Angle_diff = 0 ; // Only during the initialization
Last_Angf = Angle ; // You must read at least once the angle to initialize

Angle_diff = Last_Angle - Angle;
Last_Angle = Angle;
Angle_from_diff = Angle_from_diff + Angle_diff;

@jabrena
Copy link
Member Author

jabrena commented Nov 16, 2016

Pending doubt:

The inertial sensors in the CruizCore XG1300L are factory calibrated and the measurements provided in the form of signed short integers (16 bits or two bytes). The two bytes represent the sensor reading multiplied by a scale factor of 100.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant