惯性#
初始化惯性类#
使用以下构造函数创建惯性传感器:
inertial
构造函数使用 EXP Brain 的内部惯性传感器创建一个惯性对象。
范围 |
描述 |
---|---|
目录 |
directionType 对应正航向值。默认值为 |
// Create a new object "Inertial" with the
// inertial class.
inertial Inertial = inertial();
inertial(port, dir)
构造函数使用 EXP Brain 的内部惯性传感器创建一个惯性对象。
范围 |
描述 |
---|---|
|
惯性传感器连接到的有效 智能端口。 |
目录 |
directionType 对应正航向值。默认值为 |
// Construct a Inertial Sensor "Inertial" with the
// inertial class.
inertial Inertial = inertial(PORT1);
当引用惯性类方法时,此“Inertial”对象将在整个 API 文档的所有后续示例中使用。
类方法#
校准()#
陀螺仪或惯性传感器将根据校准期间 EXP Brain 的方向自动调整其值,以便它在所有可能的 EXP Brain 方向上保持一致。
该方法通过以下方式调用:
calibrate()
方法用于校准惯性传感器。校准应在惯性传感器静止不动时进行。校准至少需要 2 秒钟才能完成。
**返回:**无。
// Start calibration.
Inertial.calibrate();
calibrate(value)
方法用于校准惯性传感器。校准应在惯性传感器静止不动时进行。校准至少需要 2 秒钟才能完成。
参数 |
描述 |
---|---|
价值 |
设置校准时间。默认值为 0。 |
**返回:**无。
// Start calibration with the calibration time set to 3 seconds.
Inertial.calibrate(3);
正在校准()#
isCalibrating()
方法检查惯性传感器当前是否正在校准。
**返回:**如果惯性传感器正在校准,则返回“true”。如果不是,则返回“false”。
// Start calibration.
Inertial.calibrate();
// Print that the Inertial Sensor is calibrating while
// waiting for it to finish calibrating.
while(Inertial.isCalibrating()){
Brain.Screen.clear();
Brain.Screen.print("Inertial Calibrating");
wait(50, msec);
}
重置标题()#
resetHeading()
方法将惯性传感器的航向重置为 0。
**返回:**无。
设置标题()#
setHeading(value, units)
方法将惯性传感器的航向设置为指定值。
参数 |
描述 |
---|---|
价值 |
要设置的航向值。 |
单位 |
有效的 rotationUnit。 |
**返回:**无。
// Set the Inertial Sensor's heading to 180 degrees.
Inertial.setHeading(180);
标题()#
heading(units)
方法返回惯性传感器的当前航向。
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。默认值为“度”。 |
**返回:**以指定单位表示惯性传感器当前航向的双精度值。
// Get the current heading for the Inertial Sensor.
double value = Inertial.heading();
重置旋转()#
resetRotation()
方法将惯性传感器的旋转度重置为 0。
**返回:**无。
设置旋转()#
setRotation(value, units)
方法将惯性传感器的旋转设置为指定值。
参数 |
描述 |
---|---|
价值 |
要设置的旋转值。 |
单位 |
有效的 rotationUnit。 |
**返回:**无。
// Set the Inertial Sensor's rotation to 180 degrees.
Inertial.setRotation(180);
旋转()#
rotation(units)
方法返回惯性传感器的当前旋转。
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。默认值为“度”。 |
返回: 以指定单位表示惯性传感器当前旋转的双精度值。
// Get the current rotation for the Inertial Sensor.
double value = Inertial.rotation();
角度()#
angle(units)
方法返回惯性传感器的当前角度。
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。默认值为“度”。 |
**返回:**以指定单位表示惯性传感器当前角度的双精度值。
// Get the current angle for the Inertial Sensor.
double value = Inertial.angle();
卷()#
roll(units)
方法返回惯性传感器的滚动角。
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。默认值为“度”。 |
**返回:**表示惯性传感器滚动值的双精度数。
沥青()#
pitch(units)
方法返回惯性传感器的滚动角。
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。默认值为“度”。 |
**返回:**表示惯性传感器的俯仰值的双精度数。
偏航()#
yaw(units)
方法返回惯性传感器的偏航角。
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。默认值为“度”。 |
**返回:**表示惯性传感器偏航值的双精度数。
方向()#
orientation(axis, units)
方法返回惯性传感器一个轴的方向。
参数 |
描述 |
---|---|
轴 |
有效的 axisType。 |
单位 |
有效的 rotationUnit。 |
**返回:**以指定单位表示轴方向的双精度值。
// Get the orientation value for the X axis of the
// Inertial Sensor.
double orient = Inertial.orientation(xaxis);
陀螺仪速率()#
gyroRate(axis, units)
方法返回惯性传感器一个轴的陀螺仪速率。
参数 |
描述 |
---|---|
轴 |
有效的 axisType。 |
单位 |
有效的 velocityUnit。 |
**返回:**以指定的单位表示轴的陀螺仪速率的双精度值。
// Get the gyro rate for the Z axis of the Inertial Sensor.
double zrate = Inertial.gyroRate(zaxis);
加速度()#
acceleration(axis)
方法返回惯性传感器特定轴的加速度。
参数 |
描述 |
---|---|
轴 |
有效的 axisType。 |
**返回:**以重力单位表示轴加速度的双精度值。
// Get the acceleration for the Z axis of the
// Inertial Sensor.
double accel = Inertial.acceleration(zaxis);
// Print the value of the current acceleration of the z-axis
// of the Inertial Sensor to the Brain's screen.
Brain.Screen.print(accel);
已更改()#
changed(callback)
方法注册一个当惯性传感器航向改变时的回调函数。
参数 |
描述 |
---|---|
打回来 |
当惯性传感器航向改变时调用的回调函数。 |
**返回:**事件类的一个实例。
// Define the inertialChanged function with a void return
// type, showing it doesn't return a value.
void inertialChanged() {
// The brain will print that the Inertial Sensor changed
// on the Brain's screen.
Brain.Screen.print("accelerometer changed");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn the robot right.
Drivetrain.turn(right);
// Run inertialChanged when the value of the
// Inertial Sensor changes.
Inertial.changed(inertialChanged);
}
碰撞()#
collision(axis, x, y, z)
方法注册一个当惯性传感器检测到碰撞时的回调函数。
参数 |
描述 |
---|---|
轴 |
有效的 axisType。 |
x |
x 轴加速度值的双精度数。 |
y |
y 轴加速度值的双精度数。 |
z |
z 轴加速度值的双精度数。 |
**返回:**事件类的一个实例。
时间戳()#
timestamp()
方法请求惯性传感器最后接收到的状态包的时间戳。
**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。
安装()#
如果惯性传感器已安装,则 installed()
方法返回。
**返回:**如果安装了惯性传感器,则返回“true”。如果没有安装,则返回“false”。