جهاز تحديد المدى#
مقدمة#
The sonar class is used with the Ultrasonic Range Finder, which measures the distance to the nearest object using sound waves. It works by sending out an ultrasonic pulse and measuring how long it takes for the sound to bounce back.

مُنشئ الفئة#
sonar(
triport::port &port);
مُدمِّر الفئة#
يدمر الكائن sonar ويحرر الموارد المرتبطة به.
virtual ~sonar();
حدود#
المعلمة |
يكتب |
وصف |
|---|---|---|
|
|
المنفذ الأول ثلاثي الأسلاك من مجموعة منافذ ثنائية مطلوبة يستخدمها جهاز تحديد المدى. يشغل جهاز تحديد المدى منفذين متجاورين (A–B، C–D، E–F، أو G–H) إما على وحدة التحكم الرئيسية أو على موسع ثلاثي الأسلاك. حدد المنفذ الأول في الزوج (A، C، E، أو G)، ويكتب كالتالي: |
أمثلة#
// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);
الدوال الأعضاء#
تتضمن فئة sonar الدوال الأعضاء التالية:
foundObject— تُرجع ما إذا كان برنامج البحث عن النطاق يكتشف كائنًا.distance— تُرجع المسافة بين جهاز تحديد المدى وأقرب جسم تم اكتشافه.
قبل استدعاء أي من وظائف أعضاء sonar sonar يجب إنشاء مثيل sonar sonar كما هو موضح أدناه:
/* This constructor is required when using VS Code.
Range Finder configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);
foundObject#
تُرجع هذه الدالة ما إذا كان جهاز تحديد المدى يكتشف وجود جسم ما ضمن مجال رؤيته.
Available Functionsbool foundObject();
لا تقبل هذه الدالة أي معلمات.
Return Valuesيُرجع قيمة منطقية bool تُشير إلى ما إذا كان مُحدد النطاق قد اكتشف كائنًا أم لا:
true— جهاز تحديد المدى يكتشف وجود جسم.false— لا يكتشف جهاز تحديد المدى أي جسم.
// Check if an object is detected.
if (RangeFinderA.foundObject()){
// Print to screen on the brain that an object was found.
Brain.Screen.print("object found");
}
distance#
يعيد المسافة المقاسة إلى أقرب جسم تم اكتشافه بواسطة المستشعر.
Available Functionsdouble distance(
distanceUnits units );
المعلمة |
يكتب |
وصف |
|---|---|---|
|
|
الوحدة التي تمثل المسافة: |
Returns a double representing the distance in the specified units.
// Get the Range Finder distance in millimeters.
double value = RangeFinderA.distance(mm);
// Print the current distance detected by the Range Finder to the
// Brain's screen.
Brain.Screen.print(value);