Level IMU Data

Description

This object is being used to level received IMU Data.


App Builder Object


Source Code

function getOffset(axle) { const val = parseFloat(inPorts[0].value[axle]); const offset = parseFloat(context[`${axle}Ref`]); let retVal; if (val === offset) { retVal = 0; } if (offset < 0 && val < 0) { if (offset < val) { retVal = (Math.abs(offset) - Math.abs(val)); } else if (offset > val) { retVal = (Math.abs(val) - Math.abs(offset)) * (-1); } else { return 0; } } if (offset >= 0 && val >= 0) { retVal = (val - offset); } if (offset >= 0 && val < 0) { const res = (offset + (Math.abs(val))) * (-1); if (res < (-180)) { retVal = (360 - Math.abs(res)); } else { retVal = res; } } if (offset <= 0 && val >= 0) { const res = Math.abs(offset) + Math.abs(val); if (res > 180) { retVal = (180 - (res - 180)) * -1; } else { retVal = res; } } if (retVal) { return retVal.toFixed(2); } return null; } function execute() { if (!context.initialized) { context.rollRef = 0; context.pitchRef = 0; context.yawRef = 0; context.initialized = true; } switch (trigger) { case 0: return [getOffset('roll'), getOffset('pitch'), getOffset('yaw'), inPorts[0].value.heading]; case 1: context.rollRef = (inPorts[0].value.roll) || 0; context.pitchRef = (inPorts[0].value.pitch) || 0; context.headingRef = (inPorts[0].value.yaw) || 0; break; default: break; } return []; }

In Ports

Position

Name

Message Type

Description

Position

Name

Message Type

Description

1

IMU

IMU

This port is being used to receive a message containing the combined IMU data.

2

Set Level

Trigger

This port is being used to trigger the leveling of the IMU data.


Out Ports

Position

Name

Message Type

Description

Position

Name

Message Type

Description

1

Roll

Number

This port is being used to send out the leveled roll value of the IMU data.

2

Pitch

Number

This port is being used to send out the leveled pitch value of the IMU data.

3

Yaw

Number

This port is being used to send out the leveled yaw value of the IMU data.

4

Heading

Number

This port is being used to send out the leveled heading value of the IMU data.


Properties

Name

Description

Name

Description

Object Name

The name of the object on the canvas.

Show Code View

The switch to turn on code view for the Code Object.

Duplicate code into custom Code Object