جهاز تحديد المدى#

مقدمة#

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.

جهاز قياس المسافة VEX V5.

مُنشئ الفئة#

sonar(
  triport::port &port);

مُدمِّر الفئة#

يدمر الكائن sonar ويحرر الموارد المرتبطة به.

virtual ~sonar();

حدود#

المعلمة

يكتب

وصف

port

triport::port &

المنفذ الأول ثلاثي الأسلاك من مجموعة منافذ ثنائية مطلوبة يستخدمها جهاز تحديد المدى. يشغل جهاز تحديد المدى منفذين متجاورين (A–B، C–D، E–F، أو G–H) إما على وحدة التحكم الرئيسية أو على موسع ثلاثي الأسلاك. حدد المنفذ الأول في الزوج (A، C، E، أو G)، ويكتب كالتالي: Brain.ThreeWirePort.X أو ExpanderName.X حيث X هو حرف المنفذ (على سبيل المثال، Brain.ThreeWirePort.A أو Expander1.C).

أمثلة#

// 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 Functions
bool foundObject();

Parameters

لا تقبل هذه الدالة أي معلمات.

Return Values

يُرجع قيمة منطقية bool تُشير إلى ما إذا كان مُحدد النطاق قد اكتشف كائنًا أم لا:

  • true — جهاز تحديد المدى يكتشف وجود جسم.

  • false — لا يكتشف جهاز تحديد المدى أي جسم.

Examples
// 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 Functions
double distance(
  distanceUnits units );

Parameters

المعلمة

يكتب

وصف

units

distanceUnits

الوحدة التي تمثل المسافة: inches أو mm — مليمترات.

Return Values

Returns a double representing the distance in the specified units.

Examples
// 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);