Accelerometer#

The Accelerometer measures the acceleration of the robot along one or more axes. The sensor outputs an analog voltage that changes based on acceleration in G-forces (G).

A jumper on the Accelerometer determines its sensitivity range:

  • 2G – Measures acceleration from -2G to +2G

  • 6G – Measures acceleration from -6G to +6G

The VEX V5 Analog accelerometer.

This page uses accel_a as the example Accelerometer name. Replace it with your own configured name as needed.

Below is a list of available methods:

  • acceleration – Returns the acceleration detected by the Accelerometer in Gs.

  • changed – Registers a function to be called whenever the Accelerometer’s value changes.

Constructor – Manually initialize and configure an Accelerometer.

acceleration#

acceleration returns the acceleration value from which axis is connected on the Accelerometer as a float.

Usage:
accel_a.acceleration()

Parameters

Description

This method has no parameters.

changed#

changed registers a function to be called whenever the Accelerometer’s value changes.

Usage:
accel_a.changed(callback, arg)

Parameters

Description

callback

A previously defined function that executes when the Accelerometer’s value changes.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

def my_function():
  brain.screen.print("Value changed")

# Call my_function whenever accel_a's value changes
accel_a.changed(my_function)

Constructor#

Constructors are used to manually create Accelerometer objects, which are necessary for configuring an Accelerometer outside of VEXcode.

Accelerometer#

Accelerometer creates an Accelerometer.

Usage:
Accelerometer(port, sensitivity)

Parameter

Description

port

The 3-Wire Port that the Accelerometer is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

sensitivity

Optional. Whether to enable high sensitivity mode on the Accelerometer:

  • True – Enable high sensitivity (+/- 2g)
  • False (default) – Enable low sensitivity (+/- 6g)

# Create a high sensitivity Accelerometer in Port A
accel_a = Accelerometer(brain.three_wire_port.a, True)