
Робот оснащён двумя отдельно управляемыми колёсами. Левым колесом управляет мотор A, правым колесом
управляет мотор B. Колёса напрямую подсоединены к моторам. На роботе установлен один датчик освещённости. Саша написал программу, чтобы робот ехал по чёрной линии. Этот фрагмент кода отвечает за движение по чёрной линии: k = 2; Eold = 0; while (true) { Ed = s1 – grey; u = k * (Ed – Eold); motor[motorA] = 50 – u; motor[motorB] = 50 + u; Eold = Ed; wait1msec(10); } При калибровке на чёрном датчик робота показал 7, при калибровке на белом показал 94. В качестве значения границы серого Саша взял среднее арифметическое показаний датчика на чёрном и на белом. Мощность моторов может быть выражена целым числом в пределах от –100 до 100. В случае, если на мотор подаётся не целое значение мощности, происходит отбрасывание дробной части. Открыть справочную информацию в отдельной вкладке Определите, какая мощность будет подана на моторы A и B при показаниях датчика s1, равных 57. Прошлое показание датчика было равно 45. Помогите пожалуйста

Ответы на вопрос

Ответ: А:90. Б:-90
наверно так



Understanding the Code
The provided code is responsible for controlling a robot equipped with two separately controlled wheels. The left wheel is controlled by motor A, and the right wheel is controlled by motor B. The wheels are directly connected to the motors. The robot also has one light sensor for detecting brightness.The code snippet provided is part of a program written by Sasha to make the robot follow a black line. Let's analyze the code to understand how it works:
```c k = 2; Eold = 0; while (true) { Ed = s1 - grey; u = k * (Ed - Eold); motor[motorA] += 50 - u; motor[motorB] += 50 + u; Eold = Ed; wait1msec(10); } ```
Here's a breakdown of the code:
- `k = 2;`: This line initializes the variable `k` with a value of 2. - `Eold = 0;`: This line initializes the variable `Eold` with a value of 0. - `while (true) { ... }`: This creates an infinite loop that continuously executes the code inside the curly braces. - `Ed = s1 - grey;`: This line calculates the difference between the sensor reading `s1` and the grey threshold value. The result is stored in the variable `Ed`. - `u = k * (Ed - Eold);`: This line calculates the control signal `u` by multiplying the difference between `Ed` and `Eold` by the value of `k`. - `motor[motorA] += 50 - u;`: This line adjusts the power of motor A by adding 50 and subtracting the value of `u`. - `motor[motorB] += 50 + u;`: This line adjusts the power of motor B by adding 50 and adding the value of `u`. - `Eold = Ed;`: This line updates the value of `Eold` with the current `Ed` value for the next iteration. - `wait1msec(10);`: This line pauses the program execution for 10 milliseconds before the next iteration.
Determining Motor Power
To determine the power that will be applied to motors A and B for a given sensor reading `s1`, we need to understand the calibration process and the range of values for the grey threshold.According to the information provided, the robot was calibrated on a black surface, resulting in a sensor reading of 7, and on a white surface, resulting in a sensor reading of 94. Sasha took the average of these two values as the grey threshold.
To calculate the power applied to motors A and B, we need to know the previous sensor reading (`s1_previous`) and the current sensor reading (`s1`). In this case, the previous sensor reading was 45, and the current sensor reading is 57.
Let's calculate the power for motors A and B using the given formula:
```c Ed = s1 - grey; u = k * (Ed - Eold); motor[motorA] += 50 - u; motor[motorB] += 50 + u; ```
Substituting the values:
```c Ed = 57 - (7 + 94) / 2; u = 2 * (57 - 45); motor[motorA] += 50 - u; motor[motorB] += 50 + u; ```
Simplifying the calculations:
```c Ed = 57 - 50.5; u = 2 * 12; motor[motorA] += 50 - 24; motor[motorB] += 50 + 24; ```
Final calculations:
```c Ed = 6.5; u = 24; motor[motorA] += 26; motor[motorB] += 74; ```
Therefore, the power applied to motor A will be 26, and the power applied to motor B will be 74 when the sensor reading `s1` is 57 and the previous sensor reading `s1_previous` was 45.
Please note that the power values are integers within the range of -100 to 100. If a non-integer power value is calculated, the fractional part is discarded.
I hope this helps! Let me know if you have any further questions.


Похожие вопросы
Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili