Technology Careers Contact
Documentation Community Download

Imu module type

The Imu module handles an inertial sensor.

Its type has access to all common capabilities.

Imu modules can measure:

  • Compass – Magnetic field data in micro-tesla on each axis
  • Gyro – X, Y, Z axis rotational acceleration data in degrees per second
  • Accel – X, Y, Z axis linear acceleration data in G
  • Heading – 360 degrees from North with Y+ axis as the pointer
  • Rotational Matrix – linear math 9 element matrix representation
  • Euler Angles – Pitch, roll, yaw based in degrees with frame reference
  • Quaternions – Sensor fused w, x, y, z rotational angles
  • Linear Acceleration – Linear acceleration in body frame coordinates
  • Gravity Vector – Which access gravity effects
  • Pedometer – Step number
  • walk time – Duration (second) of the walk

By default, the module will send only quaternions to keep a low number of data and avoid bus congestion. Retrieving any other types of measures requires to enable them first.

The easiest way to enable a measure is by using it, as pyluos automatically enables a called measure. For example, to retrieve the linear acceleration value when it’s disabled, you can execute:

device.Imu_mod.linear_acceleration

This command doesn’t allow you to disable the value after using it in order to keep your device responsive. Another way to enable or disable a value is to set it to True or False. For example, if you want to disable the linear acceleration measure previously activated, you can execute:

device.Imu_mod.linear_acceleration = False

Functions

Function name and parametersActionComment
control(self)Displays module type graphical interfaceOnly available using Jupyter notebook

Variables

Variable nameActionType
compassMagnetic field data in micro-tesla on each axisread only: [Float, Float, Float]
compassStarts/Stops compass measurement actualizationwrite only: Boolean (True or False)
gyroX, Y, Z axis rotational acceleration data in degrees per secondread only: [Float, Float, Float]
gyroStarts/Stops gyro measurement actualizationwrite only: Boolean (True or False)
accelerationX, Y, Z axis linear acceleration data in Gread only: [Float, Float, Float]
accelerationStarts/Stops acceleration measurement actualizationwrite only: Boolean (True or False)
heading360 degrees from North with Y+ axis as the pointerread only: [Float, Float, Float]
headingStarts/Stops heading measurement actualizationwrite only: Boolean (True or False)
rotational_matrixLinear math 9 element matrix representationread only: [Float, Float, Float, Float, Float, Float, Float, Float, Float]
rotational_matrixStarts/Stops rotational_matrix measurement actualizationwrite only: Boolean (True or False)
eulerPitch, roll, yaw based in degrees with frame referenceread only: [Float, Float, Float]
eulerStarts/Stops euler measurement actualizationwrite only: Boolean (True or False)
quaternionSensor fused w, x, y, z rotational anglesread only: [Float, Float, Float, Float]
quaternionStarts/Stops quaternion measurement actualizationwrite only: Boolean (True or False)
linear_accelerationLinear acceleration in body frame coordinatesread only: [Float, Float, Float]
linear_accelerationStarts/Stops linear_acceleration measurement actualizationwrite only: Boolean (True or False)
gravity_vectorWhich access gravity effectsread only: [Float, Float, Float]
gravity_vectorStarts/Stops gravity_vector measurement actualizationwrite only: Boolean (True or False)
pedometerStep numberread only: int
pedometerStarts/Stops pedometer measurement actualizationwrite only: Boolean (True or False)
walk_timeDuration (second) of the walkread only: Float
walk_timeStarts/Stops walk_time measurement actualizationwrite only: Boolean (True or False)

Example of use of your IMU module using Jupyter notebook

In this example, we will display in 3D the rotation sensor by using quaternions. In order to do that, we will use the pythreejs lib and jupyter notebook.

First, install and enable this library by typing these commands in a terminal:

pip install pythreejs

jupyter nbextension install --py --symlink --sys-prefix pythreejs

jupyter nbextension enable --py --sys-prefix pythreejs

Now, restart jupyter notebook and add this code to a new python script:

from pyluos import Device
import time
from pythreejs import *

# Create a cube to move following our sensor
cube = Mesh(
BoxBufferGeometry(3, 3, 3),
MeshPhysicalMaterial(color='green'),
position=[0, 0, 0],
castShadow = True
)

# Create a floor
plane = Mesh(
PlaneBufferGeometry(100, 100),
MeshPhysicalMaterial(color='gray'),
position=[0, -1.5, 0], receiveShadow = True)
plane.rotation = (-3.14/2, 0, 0, 'XYZ')

# Create a directional light following our cube
key_light = SpotLight(position=[0, 10, 10], angle = 0.3, penumbra = 0.1, target = cube, castShadow = True)
key_light.shadow.mapSize = (2048, 2048)

# Create a camera
c = PerspectiveCamera(position=[4, 12, 10], up=[0, 1, 0],
aspect=800/400)

# Create a scene
scene = Scene(children=[plane, cube, c, key_light, AmbientLight()])

# Display the scene with shadow and everything.
renderer = Renderer(camera=c,
scene=scene,
controls=[OrbitControls(controlling=c)],
width=800, height=400,
)
renderer.shadowMap.enabled = True
renderer.shadowMap.type = 'PCFSoftShadowMap'
display(renderer)

# Connect your Luos network (here using an USB module)
r = Device('/dev/cu.usbserial-DN38OIYT')

# Control the rotation of the cube with the rotation of the Imu sensor
while(True):
cube.quaternion = r.Imu_mod.quaternion
time.sleep(0.05)

You should obtain a result like this:


Follow Watch Star

Luos is constantly evolving! Keep in touch to follow the last updates: