i need help with this code please

44 visualizaciones (últimos 30 días)
Sandy
Sandy el 6 de Dic. de 2024 a las 14:47
Editada: Walter Roberson el 10 de Dic. de 2024 a las 2:37
Move your robot forward until you are approximately 10" away from the obstacle in front of you and read the color ("red" is right, "blue" is left) to indicate which way to turn. Proceed until your touch sensor hits the obstacle (2x4) backup for a second, read the color ("red" is right, "blue" is left) to determine the direction to turn. Proceed straight until you are 10" from the next obstacle, read the color ("red" is right, "blue" is left) to determine the direction to turn. Proceed until you read the color green then complete at least a full circle all the while playing a song on the Lego. To complete is 100%. To win the speed test earns an extra 10%.
  5 comentarios
Image Analyst
Image Analyst el 8 de Dic. de 2024 a las 19:37
Sorry, it's difficult for me to debug unless I have your Lego hardware.
Walter Roberson
Walter Roberson el 10 de Dic. de 2024 a las 2:34
Editada: Walter Roberson el 10 de Dic. de 2024 a las 2:37
MATLAB does not use elif -- it uses elseif
The nesting of your code is questionable. Your while for the color sensor being green is nested withing the elif case. It is more likely that you want
if color == "red":
turn_right()
elseif color == "blue":
turn_left()
end
while color_sensor.get_color(touchsensor) == "green"
so that the while loop is done regardlesss if you turned right or left (or neither.)

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 6 de Dic. de 2024 a las 15:24
You can use the AI Chat Playground to get you started.
I went there and entered
use matlab code to "Move your robot forward until you are approximately 10" away from the obstacle in front of you and read the color ("red" is right, "blue" is left) to indicate which way to turn. Proceed until your touch sensor hits the obstacle (2x4) backup for a second, read the color ("red" is right, "blue" is left) to determine the direction to turn. Proceed straight until you are 10" from the next obstacle, read the color ("red" is right, "blue" is left) to determine the direction to turn. Proceed until you read the color green then complete at least a full circle all the while playing a song on the Lego."
and it gave me some commented code. It probably will not work right out of the box but it will give you a start.

Más respuestas (0)

Categorías

Más información sobre LEGO MINDSTORMS EV3 Hardware en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by