|
111 | 111 | _TRIGGER_REGISTER = const(0x3F)
|
112 | 112 | _POWER_REGISTER = const(0x3E)
|
113 | 113 | _ID_REGISTER = const(0x00)
|
| 114 | +# Axis remap registers and values |
| 115 | +_AXIS_MAP_CONFIG_REGISTER = const(0x41) |
| 116 | +_AXIS_MAP_SIGN_REGISTER = const(0x42) |
| 117 | +AXIS_REMAP_X = const(0x00) |
| 118 | +AXIS_REMAP_Y = const(0x01) |
| 119 | +AXIS_REMAP_Z = const(0x02) |
| 120 | +AXIS_REMAP_POSITIVE = const(0x00) |
| 121 | +AXIS_REMAP_NEGATIVE = const(0x01) |
114 | 122 |
|
115 | 123 |
|
116 | 124 | class _ScaledReadOnlyStruct(Struct): # pylint: disable=too-few-public-methods
|
@@ -620,6 +628,72 @@ def _write_register(self, register, value):
|
620 | 628 | def _read_register(self, register):
|
621 | 629 | raise NotImplementedError("Must be implemented.")
|
622 | 630 |
|
| 631 | + @property |
| 632 | + def axis_remap(self): |
| 633 | + """Return a tuple with the axis remap register values. |
| 634 | +
|
| 635 | + This will return 6 values with the following meaning: |
| 636 | + - X axis remap (a value of AXIS_REMAP_X, AXIS_REMAP_Y, or AXIS_REMAP_Z. |
| 637 | + which indicates that the physical X axis of the chip |
| 638 | + is remapped to a different axis) |
| 639 | + - Y axis remap (see above) |
| 640 | + - Z axis remap (see above) |
| 641 | + - X axis sign (a value of AXIS_REMAP_POSITIVE or AXIS_REMAP_NEGATIVE |
| 642 | + which indicates if the X axis values should be positive/ |
| 643 | + normal or negative/inverted. The default is positive.) |
| 644 | + - Y axis sign (see above) |
| 645 | + - Z axis sign (see above) |
| 646 | +
|
| 647 | + Note that the default value, per the datasheet, is NOT P0, |
| 648 | + but rather P1 () |
| 649 | + """ |
| 650 | + # Get the axis remap register value. |
| 651 | + map_config = self._read_register(_AXIS_MAP_CONFIG_REGISTER) |
| 652 | + z = (map_config >> 4) & 0x03 |
| 653 | + y = (map_config >> 2) & 0x03 |
| 654 | + x = map_config & 0x03 |
| 655 | + # Get the axis remap sign register value. |
| 656 | + sign_config = self._read_register(_AXIS_MAP_SIGN_REGISTER) |
| 657 | + x_sign = (sign_config >> 2) & 0x01 |
| 658 | + y_sign = (sign_config >> 1) & 0x01 |
| 659 | + z_sign = sign_config & 0x01 |
| 660 | + # Return the results as a tuple of all 3 values. |
| 661 | + return (x, y, z, x_sign, y_sign, z_sign) |
| 662 | + |
| 663 | + @axis_remap.setter |
| 664 | + def axis_remap(self, remap): |
| 665 | + """Pass a tuple coinsidting of x, y, z, x_sign, y-sign, and z_sign. |
| 666 | +
|
| 667 | + Set axis remap for each axis. The x, y, z parameter values should |
| 668 | + be set to one of AXIS_REMAP_X (0x00), AXIS_REMAP_Y (0x01), or |
| 669 | + AXIS_REMAP_Z (0x02) and will change the BNO's axis to represent another |
| 670 | + axis. Note that two axises cannot be mapped to the same axis, so the |
| 671 | + x, y, z params should be a unique combination of AXIS_REMAP_X, |
| 672 | + AXIS_REMAP_Y, AXIS_REMAP_Z values. |
| 673 | + The x_sign, y_sign, z_sign values represent if the axis should be |
| 674 | + positive or negative (inverted). See section 3.4 of the datasheet for |
| 675 | + information on the proper settings for each possible orientation of |
| 676 | + the chip. |
| 677 | + """ |
| 678 | + x, y, z, x_sign, y_sign, z_sign = remap |
| 679 | + # Switch to configuration mode. Necessary to remap axes |
| 680 | + current_mode = self._read_register(_MODE_REGISTER) |
| 681 | + self.mode = CONFIG_MODE |
| 682 | + # Set the axis remap register value. |
| 683 | + map_config = 0x00 |
| 684 | + map_config |= (z & 0x03) << 4 |
| 685 | + map_config |= (y & 0x03) << 2 |
| 686 | + map_config |= x & 0x03 |
| 687 | + self._write_register(_AXIS_MAP_CONFIG_REGISTER, map_config) |
| 688 | + # Set the axis remap sign register value. |
| 689 | + sign_config = 0x00 |
| 690 | + sign_config |= (x_sign & 0x01) << 2 |
| 691 | + sign_config |= (y_sign & 0x01) << 1 |
| 692 | + sign_config |= z_sign & 0x01 |
| 693 | + self._write_register(_AXIS_MAP_SIGN_REGISTER, sign_config) |
| 694 | + # Go back to normal operation mode. |
| 695 | + self._write_register(_MODE_REGISTER, current_mode) |
| 696 | + |
623 | 697 |
|
624 | 698 | class BNO055_I2C(BNO055):
|
625 | 699 | """
|
|
0 commit comments