Program Control#

Problem#

https://upload.wikimedia.org/wikipedia/commons/f/fb/Astronaut_Charles_Conrad_-_Cockpit_-_Lunar_Landing_Training_Vehicle_-_Ellington_AFB_%28EAFB%29%2C_TX_%28S69-56058%29.jpg

Fig. 2 25 Oct. 1969 - Commander of the Apollo 12 lunar landing mission, sits in the cockpit of a Lunar Landing Training Vehicle (LLTV) during a lunar simulation flight at Ellington Air Force Base.
Public domain. By NASA Johnson Space Center. Source: Wikimedia Commons
#

Various control systems#

Mechanical โš™๏ธ#

https://upload.wikimedia.org/wikipedia/commons/6/62/Steam_engine_in_action_%28two-thirds_speed%29.gif

Fig. 3 Steam engine using a centrifugal governor
CC BY-SA 3.0. By Panther. Source: Wikimedia Commons
#

Electronic ๐Ÿ’ป#

https://upload.wikimedia.org/wikipedia/commons/d/d9/Arduino_ftdi_chip-1.jpg

Fig. 4 A chip on an Arduino board
Public domain. By DustyDingo. Source: Wikimedia Commons
#

Manual ๐Ÿคน๐Ÿผ#

https://upload.wikimedia.org/wikipedia/commons/6/61/Hands_on_wheel.jpg

Fig. 5
CC BY 2.0. By Vernon Chan. Source: Wikimedia Commons
#

Table 1 Comparison of three control methods#

Type

Pro ๐Ÿ‘

Con ๐Ÿ‘Ž

Mechanical โš™๏ธ

simple, reliable

bulky, complex systems not feasible

Electronic ๐Ÿ’ป

flexibility through programmability (computers), small

complex, reliability

Manual ๐Ÿคน

very flexible, can cope with an unknown environment

costly, unreliable for repetitive tasks

Regardless of the method, we use electronics to connect all systems together

Exercise 2

As an engineer in the R&D department of the space agency you are designing the following subsystems of a lunar lander:

  1. a sensor for pointing the antenna to the world ๐Ÿ“ก

  2. subsystem for traveling from space to moonโ€™s proximity

  3. subsystem for landing on the moon ๐Ÿ›ฌ

For these scenarios:

  1. pick one control method

  2. explain with an example how electronics (and computers) can help in this scenario

Steps:

  1. ~1 min individually

  2. ~2 min compare with your partner

  3. Deliverable: Write down your result and keywords for explanation

Assumption: We use a programmable electronic system to solve our problem.

Mission: Safe landing#

https://gymnasium.farama.org/_images/lunar_lander.gif

Fig. 6 Lunar lander trying to land#

Problems:

  • limited fuel ๐ŸŒก๏ธ

  • crash if high speed ๐Ÿ’ฅ

How do we control โ“

Flowcharts#

@startuml
start

:Look at the clock;

if (is time >= 12:00 and time < 12:30?) then (yes)
  #palegreen:Eat;
elseif (is time >= 19:00 and time < 20:00?) then (yes)
  #palegreen:Eat;
else (no)
  #pink:Do not eat;
endif

:Work for 20 to 30 minutes;

stop
@enduml

Warning

We are repetitively running the program, i.e., if we are at the bottom, we come back to the beginning.

Exercise 3

Draw a flowchart for the following program

  • if the altitude is higher than 100

    • the thruster must be off.

  • if the altitude is lower than or equal 100

    • turn on the thruster

  • if the altitude lower than or equal 0 (landing)

    • the thruster must be off.

Steps:

  1. ~2 min individually

  2. ~1 min compare with your partner

Program control syntax#

General:

if (question1) {
  action1;
} else if (question2) {
  action2;
} else {
  action3;
}

Question examples:

  • is the time 1?

    • time == 1

  • is the temperature lower or equal 20?

    • temperature <= 20

Action examples:

  • set the speed to 10

    • speed = 10

In words:

  • if temperature is greater than 30 then activate air_conditioner

  • else if temperature greater than 25 activate ventilator

  • else turn everything off.

In code:

if (temperature > 30) {
  air_conditioner = 1;
} else if (temperature > 25) {
  ventilator = 1;
} else {
  air_conditioner = 0;
  ventilator = 0;
}

Exercise 4

Write code for landing using the following flowchart

@startuml
start

if (is altitude > 100?) then (yes)
  #pink:thruster off;
elseif (is altitude > 0?) then (yes)
  #palegreen:thruster on;
else (no)
  #pink:thruster off;
endif

stop
@enduml

using the following independent lines:

} else {
} else if (altitude > 0) {
if (altitude > 0) {
thruster = 1;
thruster = 0;
thruster = 0;
}

Steps:

  1. Work ~2 min individually. The program automatically tests your code.

  2. Compare your result with your neighbor and help them.

Appendix#

In a programmable computer, program is programmed into the memory and executed by the computer.

@startuml
package "Programmable computer" {
  
  [processor] as cpu
  [memory\n- ADD x1, x2\n- LOAD x3 ... (program)] as mem

  mem --> cpu : read
  cpu --> mem : write
}

@enduml