当前位置:首页-所有文章-VEX机器人大赛-正文

[VEX][RobotC]How to use an Ultrasonic Range Finder.如何使用超声波传感器.<<

This article will guide you to use an Ultrasonic Range Finder.

这篇文章将介绍如何使用超声波传感器。

1 >

[VEX][RobotC]How to use an Ultrasonic Range Finder.如何使用超声波传感器.<< - 第1张[VEX][RobotC]How to use an Ultrasonic Range Finder.如何使用超声波传感器.<< - 第2张

On a sonar , there are two 3-pin wires, one for input and another one for output. Both should be plugged into digital ports.

在一个超声波上,有两个3针数据线,一个用于输入,一个用于输出。两条线都应该插入digital口中。

2>

Configure the sensor in Motor and Sensor Setup.

在 Motor and Sensor Setup配置传感器。

[VEX][RobotC]How to use an Ultrasonic Range Finder.如何使用超声波传感器.<< - 第3张

You can choose the unit system that you prefer. After choosing the second port will be automatically configured for you.

你可以选择你喜欢的单位制。选择后,第二个端口会被自动配置。

You can put the input/output wire into either one of the configured ports. The orders does NOT influence your codes.

input/output口的插入顺序可以随意,不会影响你的代码。

[VEX][RobotC]How to use an Ultrasonic Range Finder.如何使用超声波传感器.<< - 第4张

You can use the code below to read its value.

你可以用下面的代码读取它的值。

#pragma config(Sensor, dgtl1, sonar ,               sensorSONAR_cm)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
	int Val = SensorValue(dgtl1);
// or you can use
        int Val2= SensorValue(sonar);
}

你也可以用下面这篇文章的方法读取它的实时值。

You can also read its real-time value by the method mentioned by the article below.

We can use sonar to detect obstacles or targets, and adjust robot's position by detecting the opponent or the distance to the edge of the compound .

Try it out yourself!

我们可以使用超声波传感器去检测物品或障碍,也可以基于它的数据(检测对手的位置或离场地边缘的距离)来调整机器人的位置。

自己尝试吧!

作者/Author :Alpar.