旋转传感器#
介绍#
rotation 类用于控制和访问来自 V5 旋转传感器的数据。
旋转传感器用于测量轴的旋转。它可以用于机器人上任何有轴旋转的地方,即使该轴没有直接连接到电机。
电机内置编码器,可以跟踪自身的旋转。旋转传感器的工作原理类似于外部编码器,可以跟踪独立轴的旋转。
旋转传感器可以返回轴的角度、位置和速度。角度是指轴的绝对位置,范围从 0 度到 359.99 度。当项目开始或机器人断电时,角度不会重置。位置传感器跟踪轴在项目进行期间正向或反向旋转的角度或圈数,并且可以根据需要进行重置。
旋转传感器兼容 1/8 英寸和 1/4 英寸标准 VEX 轴。
类构造函数#
rotation(
int32_t index,
bool reverse = false );
类析构函数#
销毁旋转角度为 rotation 对象并释放相关资源。
virtual ~rotation();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
旋转传感器连接的智能端口,记为 |
|
|
Optional. Whether to reverse the Rotation Sensor output:
|
示例#
// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);
成员功能#
rotation 类包含以下成员函数:
setPosition— 将旋转传感器的当前位置设置为特定值。angle— 返回轴的当前角度,范围从 0 到 359.99 度。position— 返回轴旋转的角度或圈数。velocity— 返回轴的旋转速度。
在调用任何 rotation 成员函数之前,必须创建一个 rotation 实例,如下所示:
// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);
setPosition#
将旋转传感器的当前位置设置为特定值。
位置是指轴在项目进行过程中旋转的距离。设置位置会在不移动轴的情况下改变当前位置值。
Available Functionsvoid setPosition(
double value,
rotationUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
要分配给旋转传感器的位置值。该值可以是整数或小数。 |
|
|
The position unit:
|
此函数不返回值。
angle#
返回轴的当前角度。
角度值表示轴在一个旋转周期内的绝对位置,范围从 0 到 359.99 度。项目开始或机器人断电时,该值不会重置。
Available Functionsdouble angle( rotationUnits units = degrees );
范围 |
类型 |
描述 |
|---|---|---|
|
|
可选。角度单位:
|
返回一个 double ,表示轴的当前角度(以指定的单位表示)。
// Get the current angle of the shaft
double angle = Rotation1.angle(degrees);
// Print the current angle of the shaft to the
// Brain's screen.
Brain.Screen.print(angle);
position#
返回轴旋转的距离。
与角度不同,位置可以超过 359.99 度,也可以低于 0 度。位置参数跟踪轴在项目进行过程中正向或反向旋转的距离,并可根据需要进行重置。
Available Functionsdouble position( rotationUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The position unit:
|
返回一个 double 表示轴以指定单位旋转了多少度。
velocity#
返回轴的旋转速度。
Available Functionsdouble velocity( velocityUnits units );
范围 |
类型 |
描述 |
|---|---|---|
|
|
速度单位:
|
返回一个 double 表示轴以指定单位旋转的速度。