Leccin 3: Sensores y Untils Soluciones de Programacin RoboLab a NQC PowerPoint PPT Presentation

presentation player overlay
1 / 10
About This Presentation
Transcript and Presenter's Notes

Title: Leccin 3: Sensores y Untils Soluciones de Programacin RoboLab a NQC


1
Lección 3 Sensores y UntilsSoluciones de
ProgramaciónRoboLab a NQC
2
Ejercicio 1 Solución RoboLab
  • Encienda el motor A para que avance. Si el sensor
    de contacto es presionado y se mantiene
    presionado, invierta la dirección del motor. Al
    liberar el sensor de contacto, apague el motor.

until (SENSOR_1 1)
task main()
Off(OUT_A)
OnRev(OUT_A)

OnFwd(OUT_A)
until (SENSOR_1 0)
SetSensor(SENSOR_1, SENSOR_TOUCH)
3
Ejercicio 1 Solución NQC
En el puerto 1 hay un sensor de contacto
  • task main()
  • SetSensor(SENSOR_1, SENSOR_TOUCH)
  • OnFwd(OUT_A)
  • until (SENSOR_1 1)
  • OnRev(OUT_A)
  • until (SENSOR_1 0)
  • Off(OUT_A)

1 significa pressionado. 0 significa liberado.
No olvide usar el doble signo igual!
4
Ejercicio 1 Solución NQC
Use macros para facilitar la lectura del código
  • define TOUCH SENSOR_1
  • define PRESSED 1
  • define RELEASED 0
  • task main()
  • SetSensor(TOUCH, SENSOR_TOUCH)
  • OnFwd(OUT_A)
  • until (TOUCH PRESSED)
  • OnRev(OUT_A)
  • until (TOUCH RELEASED)
  • Off(OUT_A)

5
Ejercicio 2 Solución RoboLab
  • Al partir el sensor está sobre una superficie
    blanca. Al moverse sobre una superficie negra,
    encienda el motor A para que avance. Al volver a
    la superficie blanca, apague el motor.

until (LIGHT lt THRESHOLD)
task main()
Off(OUT_A)
OnFwd(OUT_A)

SetSensor(LIGHT, SENSOR_LIGHT)
until (LIGHT gt THRESHOLD)
6
Ejercicio 2 Solución NQC
Macros para facilitar la lectura
  • define LIGHT SENSOR_1
  • define THRESHOLD 45
  • task main()
  • SetSensor(LIGHT, SENSOR_LIGHT)
  • until (LIGHT lt THRESHOLD)
  • OnFwd(OUT_A)
  • until (LIGHT gt THRESHOLD)
  • Off(OUT_A)

45 es el valor medio entre negro y blanco
7
Ejercicio 3 Solución RoboLab
  • Escriba un programa que ejecuta un sonido cada
    vez que el sensor de rotación completa 1/4 de
    vuelta. Haga esto 10 veces.

ClearSensor(ROT) until ( abs(ROT) gt QUARTER_REV
)
repeat (10)
task main()


PlaySound(SOUND_FAST_UP)
SetSensor(ROT, SENSOR_ROTATION)
8
Ejercicio 3 Solución NQC
  • define ROT SENSOR_1
  • define QUARTER_REV 4
  • task main()
  • SetSensor(ROT, SENSOR_ROTATION)
  • repeat(10)
  • ClearSensor(ROT)
  • until ( abs(ROT) gt QUARTER_REV )
  • PlaySound(SOUND_FAST_UP)

Pone a 0 el número de pulsos a través del lazo
Si usa valor absoluto, el sentido de rotación
no importa
9
Ejercicio 4 Solución RoboLab
  • Al presionar el sensor de contacto, hace
    avanzar al motor. Cuando el sensor de rotación
    completa 1 1/2 vueltas, apaga el motor.

OnFwd(OUT_A)
task main()

until (TOUCH 1)
Off(OUT_A)
ClearSensor(ROT) until ( abs(ROT) gt 24 )
SetSensor(TOUCH, SENSOR_TOUCH) SetSensor(ROT,
SENSOR_ROTATION)
10
Ejercicio 4 Solución NQC
  • define TOUCH SENSOR_1
  • define ROT SENSOR_3
  • task main()
  • SetSensor(TOUCH, SENSOR_TOUCH)
  • SetSensor(ROT, SENSOR_ROTATION)
  • until (TOUCH 1)
  • OnFwd(OUT_A)
  • ClearSensor(ROT)
  • until ( abs(ROT) gt 24 )
  • Off(OUT_A)
Write a Comment
User Comments (0)
About PowerShow.com