Derived from Device and Solid.
The Accelerometer node can be used to model accelerometer devices such as those commonly found in mobile electronics, robots and game input devices.
The Accelerometer node measures acceleration and gravity induced reaction forces over 1, 2 or 3 axes.
It can be used for example to detect fall, the up/down direction, etc.
The parent node of an Accelerometer node should have a Physics node defined in its physics field, so that correct measurements can be performed.
Accelerometer {
SFString name "accelerometer" # used by wb_robot_get_device()
MFVec3f lookupTable [ ] # lookup table
SFBool xAxis TRUE # {TRUE, FALSE}
SFBool yAxis TRUE # {TRUE, FALSE}
SFBool zAxis TRUE # {TRUE, FALSE}
SFFloat resolution -1 # [0, inf)
}
Note: The above description lists only the fields specific to the Accelerometer node. The complete field list can be found in the [Accelerometer.wrl]({{ url.github_tree }}/resources/nodes/Accelerometer.wrl) definition file.
-
name: This field defines the string name used bywb_robot_get_device()to get theWbDeviceTaghandle of this sensor. Its default value is "accelerometer". -
lookupTable: This field optionally specifies a lookup table that can be used for mapping the raw acceleration values [m/s²] to device specific output values. By default the lookup table is empty and therefore the raw acceleration values are returned (no mapping). See the section on the DistanceSensor node for more explanation on how alookupTableworks. -
xAxis, yAxis, zAxis: Each of these boolean fields enables or disables computation for the specified axis. If one of these fields is set to FALSE, then the corresponding vector element will not be computed and will return NaN (Not a Number). For example, ifzAxisis FALSE, then second element of the array returned by thewb_accelerometer_get_valuesfunction will always be NaN. The default is that all three axes are enabled (TRUE). Modifying these fields makes it possible to choose between a single, dual or three-axis accelerometer and to specify which axes will be used. -
resolution: This field allows to define the resolution of the sensor, the resolution is the smallest change that it is able to measure. The raw measurement is first interpolated according to the lookup table and subsequently sampled with respect to the specified resolution, if one is defined. For example, ifresolutionis 0.2 instead of returning 1.767 the sensor will return 1.8. Setting this field to -1 (default) means that the sensor has an 'infinite' resolution (it can measure any infinitesimal change). This field accepts any value in the interval (0.0, inf).
%tab-component "language"
%tab "C"
#include <webots/accelerometer.h>
void wb_accelerometer_enable(WbDeviceTag tag, int sampling_period)
void wb_accelerometer_disable(WbDeviceTag tag)
int wb_accelerometer_get_sampling_period(WbDeviceTag tag)
const double *wb_accelerometer_get_values(WbDeviceTag tag)
int wb_accelerometer_get_lookup_table_size(WbDeviceTag tag)
const double *wb_accelerometer_get_lookup_table(WbDeviceTag tag)%tab-end
%tab "C++"
#include <webots/Accelerometer.hpp>
namespace webots {
class Accelerometer : public Device {
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const double *getValues() const;
int getLookupTableSize() const;
const double *getLookupTable() const;
// ...
}
}%tab-end
%tab "Python"
from controller import Accelerometer
class Accelerometer (Device):
def enable(self, samplingPeriod):
def disable(self):
def getSamplingPeriod(self):
def getValues(self):
def getLookupTable(self):
# ...%tab-end
%tab "Java"
import com.cyberbotics.webots.controller.Accelerometer;
public class Accelerometer extends Device {
public void enable(int samplingPeriod);
public void disable();
public int getSamplingPeriod();
public double[] getValues();
public double[] getLookupTable();
// ...
}%tab-end
%tab "MATLAB"
wb_accelerometer_enable(tag, sampling_period)
wb_accelerometer_disable(tag)
period = wb_accelerometer_get_sampling_period(tag)
x_y_z_array = wb_accelerometer_get_values(tag)
lookup_table_array = wb_accelerometer_get_lookup_table(tag)%tab-end
%end
enable, disable and read the output of the accelerometer
The wb_accelerometer_enable function allows the user to enable the acceleration measurements.
The sampling_period argument specifies the sampling period of the sensor and is expressed in milliseconds.
Note that the first measurement will be available only after the first sampling period elapsed.
The wb_accelerometer_disable function turns the accelerometer off, saving computation time.
The wb_accelerometer_get_sampling_period function returns the sampling period given to the wb_accelerometer_enable function, or 0 if the device is disabled.
The wb_accelerometer_get_values function returns the current values measured by the Accelerometer.
These values are returned as a 3D-vector, therefore only the indices 0, 1, and 2 are valid for accessing the vector.
Each element of the vector represents the acceleration along the corresponding axis of the Accelerometer node, expressed in meters per second squared [m/s²].
The first element corresponds to the x-axis, the second element to the y-axis, etc.
An Accelerometer at rest with earth's gravity will indicate 1 g (9.81 m/s²) along the vertical axis.
Note that the gravity can be specified in the gravity field in the WorldInfo node.
To obtain the acceleration due to motion alone, this offset must be subtracted.
The device's output will be zero during free fall when no offset is substracted.
The wb_accelerometer_get_lookup_table_size function returns the number of rows in the lookup table.
The wb_accelerometer_get_lookup_table function returns the values of the lookup table.
This function returns a matrix containing exactly N * 3 values (N represents the number of mapped values optained with the wb_accelerometer_get_lookup_table_size function) that shall be interpreted as a N x 3 table.
Note [C, C++]: The returned vector is a pointer to the internal values managed by the Accelerometer node, therefore it is illegal to free this pointer. Furthermore, note that the pointed values are only valid until the next call to the
wb_robot_steporRobot::stepfunctions. If these values are needed for a longer period they must be copied.
Note [Python]: The
getValuesfunction returns the 3D-vector as a list containing three floats.