Elevators

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 4.0pre8 • Viewed 1366 times • Downloaded 56 times • Run 0 times
Download the 'Elevators' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


VERSION

$Id: Elevators.nlogo 37529 2008-01-03 20:38:02Z craig $

WHAT IS IT?

Each student defines the motion of an elevator by setting its velocity as a function of time on their calculator. The students have 9 different intervals for which they can set the velocity of the elevator. They can then send these velocities to NetLogo, where the actions of each elevator can be displayed next to the others. This can serve as a jumping off point for concepts ranging from derivatives and integrals to wave mechanics.

For further documentation, see the Participatory Simulations Guide found at http://ccl.northwestern.edu/ps/

HOW TO USE IT

Quickstart Instructions:

------------------------

Buttons:

--------

SETUP - clears the world including turtles, patches and plots, and draws lines marking the floors when you select this option you should have all the students logout of the activity and log back in.

RESET-ELEVATORS - sets the clock to zero, returns all the elevators to their initial positions and clears the plots.

STEP - moves the elevators by 1 interval

GO - moves the elevators 9 intervals.

PICK ELEVATOR TO PLOT - allows the user to pick an elevator to plot the velocity and position information for.

NEXT >>> - shows the next quick start instruction

<<< PREVIOUS - shows the previous quick start instruction

RESET INSTRUCTIONS - shows the first quick start instruction

Sliders:

--------

SIMULATION-SPEED - The higher the number the faster the activity runs.

Switches:

---------

PLOT-ALL-ELEVATORS? - if true, the data for all the elevators will be shown in the plots. If it is false and if an elevator has been picked by using the PICK ELEVATOR TO PLOT button, only the picked elevator's information will be shown in the plot from the current time tick forward. Old plot data is not erased.

SHOW-USER-ID? - if true, all the turtles show their user-id as its label. If false, no label is shown.

THINGS TO NOTICE

Notice if an elevator moves more than 1 floor during an interval, it equally divides the amount of time spent traveling through each floor.

THINGS TO TRY

Identify your elevator (necessary even with the first use!)

Have your elevator sit at the third floor during the fourth time segment. What is the same / different between the solutions?

Make a traveling / standing wave.

Have a velocity of +2 during the fourth time interval.

Start and End at the same floor.

EXTENDING THE MODEL

A real elevator does not move at a constant speed when moving from floor to floor. It will build its speed gradually until it has reached a constant speed. Then before reaching the floor it is supposed to stop on, it will slow down. Try to make this happen as a part of the model.

CREDITS AND REFERENCES

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variable declarations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals
[
  clock             ;; keeps track of the number of times modulus total-intervals through the go procedure
  num-intervals     ;; the number of time intervals a elevator can move
  received-info?    ;; equals true if data has been sent from the calculators

  ;; variables for leaving a trail
  up-trail-color    ;; color of the trail left behind by an elevator as it moves upwards
  down-trail-color  ;; color of the trail left behind by an elevator as it moves downwards

  ;; plotting variables
  users             ;; list of the user ids for the current set of elevators
  elevator-to-plot  ;; the elevator to plot if plot-all-elevators? is false
  old-plot-all-elevators?  ;; the value of plot-all-elevators? in the last pass thru the go procedure

  ;; quick start instructions variables
  quick-start       ;; the current quickstart instruction displayed in the quickstart monitor
  qs-item           ;; the index of the current quickstart instruction
  qs-items          ;; the list of quickstart instructions
]

turtles-own
[
  ;; variable used in interactions with calculators
  user-id           ;; the id of a turtle which corresponds to the user-id of a calculator

  ;; position variables
  my-ycor           ;; the unwrapped vertical position of a turtle
  ycor-initial      ;; the initial vertical position of a turtle

  ;; variable to keep track of the time
  interval          ;; the current interval a turtle is moving through

  ;; variables keeping the velocities of a turtle
  velocity          ;; current velocity of an elevator
  velocities        ;; list of velocities
]

patches-own
[
  base-pcolor       ;; the original color of the patch before any trail was drawn on it
]

;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;

to startup
  setup
  setup-quick-start
  hubnet-set-client-interface "COMPUTER" []
  hubnet-reset
end 

;; Initializes the display, the plots, and the global variables.

to setup
  setup-patches
  setup-vars
  setup-plots
  set-default-shape turtles "elevator"
end 

;; setup the model to be ready to be run with
;; the current elevators and with clock set to zero

to re-run
  reset-elevators
  setup-plots
end 

;; set up the patches to have the floor numbers down the left side of the
;; view and color all even floor a gray color

to setup-patches
  clear-output
  cp
  ct

  ;; give the floors some color to be able to distinguish one floor from another
  ask patches with [ pycor mod 2 = 0 ]
  [ set pcolor 3 ]
  ask patches with [ pycor = 0 ]
  [ set pcolor 4 ]
  ;; label each row of pycors with a floor number
  ask patches with [ pxcor = min-pxcor ]
  [ set plabel pycor ]
  ask patches
  [ set base-pcolor pcolor ]
end 

;; set variables to initial values

to setup-vars
  set clock 0
  set num-intervals 9
  set received-info? false
  set up-trail-color green
  set down-trail-color red

  ;; by default have the elevator to plot be nobody
  set elevator-to-plot nobody
end 

;; give the user some information about what the setup button does so they can
;; know whether they want to proceed before actually doing the setup

to setup-prompt
  if user-yes-or-no? (word "The SETUP button should only be used when starting "
              "over with a new group (such as a new set of students) since "
              "all data is lost.  Use the RE-RUN button for continuing with "
              "an existing group."
              "\\n\\nDo you really want to setup the model?")
  [
    user-message (word "Before closing this dialog, please do the following:"
                 "\\n  -Have everyone that is currently logged in, log off and "
                 "clear the calculator memory. (Press 2nd MEM 7 1 2)"
                 "\\n  -Open the teacher console for this activity and press the ERASE ALL DATA button.")
    setup
  ]
end 

;; creates a set of num-turtles elevators.  only used in testing.

to make-test-turtles [ num-turtles ]
  crt num-turtles
  [
    set ycor-initial 3
    set color 5 + (10 * random 14)
    set heading 0
    set interval 0
    set user-id (word who)
    ifelse (who mod 3 = 0)
    [ set velocities [ 1 2 3 2 1 0 -1 0 0 ] ]
    [
      ifelse (who mod 3 = 1)
      [ set velocities [ 0 0 1 -1 3 -2 -1 0 0 ] ]
      [ set velocities [ 0 0 -1 4 3 -2 -3 0 5 ] ]
    ]

    ;; set initial positions of the elevators
    set my-ycor ycor-initial
    set ycor ycor-initial

    ifelse (abs my-ycor <= max-pycor)
    [ set hidden? false ]
    [ set hidden? true ]
    set label-color yellow
    show-or-hide-id-labels
  ]

  set received-info? true
end 


;;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;;

;; move the elevators one interval

to go
  listen-clients
  every delay  ;; we want to move to a new interval after delay seconds
  [
    if clock < num-intervals
    [
      ask turtles
      [
        show-or-hide-id-labels  ;; shows or hide the turtles labels
        assign-values           ;; set the turtles' velocity to the appropriate value
        move-elevators          ;; move the elevators by their velocity for this interval
      ]
      do-plotting
      ask patches with [ pcolor != base-pcolor ]
        [ fade-trail ]
      set clock clock + 1
    ]
  ]
end 

;; return the elevators to their initial positions and reset the clock

to reset-elevators
  set clock 0
  ask patches [ set pcolor base-pcolor ]
  ask turtles
  [
    set heading 0
    set ycor ycor-initial
    set interval 0
    set my-ycor ycor-initial
    st
    show-or-hide-id-labels
  ]
end 

;; calculate the delay in seconds based on the simulation speed

to-report delay
  ifelse simulation-speed <= 0
  [ report ln (10 / 0.001) ]
  [ report ln (10 / simulation-speed) ]
end 

to show-or-hide-id-labels  ;; turtle procedure
  ifelse show-user-id?
  [ set label word user-id "     " ]
  [ set label "" ]
end 

;; set the student selected elevator velocity for the current interval

to assign-values  ;; turtle procedure
  ifelse interval >= length velocities
  [ set velocity 0 ]
  [ set velocity item interval velocities ]
end 

;; move each turtle by its velocity for this interval

to move-elevators  ;; turtle procedure
  let delta-pos 0

  if velocity != 0
  [ set delta-pos (velocity / abs velocity) ]
  let inner-tick 0

  while [ inner-tick < abs velocity ]
  [
    ;; divide the amount of time till the next interval into equal amounts
    ;; so as to be able to make the motion of an elevator smooth
    every ( delay / (abs velocity) )
    [
      ifelse (velocity > 0)  ;; leave a trail behind the turtle.  the color of the trail will depend upon whether the turtle is moving up or down
      [ set pcolor up-trail-color ]
      [ set pcolor down-trail-color ]

      set my-ycor (my-ycor + delta-pos)  ;; add to the turtle's unwrapped ycor 1 or -1 based on the sign of its velocity
      ifelse patch-ahead delta-pos != nobody
      [ st
        fd delta-pos ]  ;; if my-ycor is on the screen, then have the turtle color the patch that it is on
      [ ht ]  ;; otherwise, hide this turtle so it doesn't wrap around the screen, but appears to go off the edge of the screen
      set inner-tick (inner-tick + 1)  ;; increase the inner clock of the turtle
    ]
  ]

  set interval (interval + 1)
end 

;; have any trails fade back to the base color of the patch

to fade-trail  ;; patch procedure
  set pcolor pcolor - 0.4
  if (pcolor mod 10 = 0)
  [ set pcolor base-pcolor ]
end 

;;;;;;;;;;;;;;;;;;;;;;;
;; HubNet Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;

to listen-clients
  while [ hubnet-message-waiting? ]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ setup-elevator ]
    [
      ifelse hubnet-exit-message?
      [ remove-elevator ]
      [ ask turtles with [ user-id = hubnet-message-source ]
        [ execute-cmd hubnet-message-tag ] ]
    ]
    set received-info? true
  ]
end 

to execute-cmd [ cmd ]
  ifelse cmd = "interval-1"
  [ set-velocity 0 ][
  ifelse cmd = "interval-2"
  [ set-velocity 1 ][
  ifelse cmd = "interval-3"
  [ set-velocity 2 ][
  ifelse cmd = "interval-4"
  [ set-velocity 3 ][
  ifelse cmd = "interval-5"
  [ set-velocity 4 ][
  ifelse cmd = "interval-6"
  [ set-velocity 5 ][
  ifelse cmd = "interval-7"
  [ set-velocity 6 ][
  ifelse cmd = "interval-8"
  [ set-velocity 7 ]
  [ set-velocity 8 ] ] ] ] ] ] ] ]
end 

to set-velocity [index]
  set velocities replace-item index velocities hubnet-message
end 

to setup-elevator
  let p one-of patches with [ pycor = 0 and pxcor > min-pxcor and not any? turtles-on patches with [ pxcor = [pxcor] of myself ] ]
  ifelse p = nobody
  [
    user-message "A user tried to join but there is no more space for another user."
  ]
  [
    crt 1
    [
      set user-id hubnet-message-source
      set velocities [0 0 0 0 0 0 0 0 0]
      set heading 0
      set interval 0
      set color 5 + 10 * random 14
      set ycor-initial random-pycor
      setxy [pxcor] of p ycor-initial
      set label-color yellow
      show-or-hide-id-labels
    ]
  ]
end 

to remove-elevator
  ask turtles with [ user-id = hubnet-message-source ] [ die ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;
;; Plotting Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;;;

;; plot the positions and velocities for the elevators in the appropriate plot

to do-plotting
  ifelse plot-all-elevators?
  [
    let positions [ my-ycor ] of turtles
    let all-velocities [ velocity ] of turtles

    set-current-plot "Elevator Position vs. Intervals"
    plot-list positions false

    set-current-plot "Elevator Velocity vs. Intervals"
    plot-list all-velocities true
    set old-plot-all-elevators? plot-all-elevators?
  ]
  [
    ifelse( elevator-to-plot = nobody )
    [
      if plot-all-elevators? != old-plot-all-elevators?
      [
        user-message (word "If you want to view just 1 elevator's data in the plots, "
                  "please use the PICK ELEVATOR TO PLOT button to pick an "
                  "elevator to plot.\\n"
                  "Alternately, switch PLOT-ALL-ELEVATORS? to true.\\n"
                  "Until you do one of these things, nothing will be plotted.")
        set old-plot-all-elevators? plot-all-elevators?
      ]
    ]
    [
      set-current-plot "Elevator Position vs. Intervals"
      set-current-plot-pen [ user-id ] of elevator-to-plot
      plotxy (clock + 1) [ my-ycor ] of elevator-to-plot

      set-current-plot "Elevator Velocity vs. Intervals"
      set-current-plot-pen [ user-id ] of elevator-to-plot
      plotxy clock [ velocity ] of elevator-to-plot
    ]
  ]
  plot-x-axis "Elevator Velocity vs. Intervals"
  plot-x-axis "Elevator Position vs. Intervals"
end 

;; for each element in users, plot the element in info at the same index

to plot-list [ info use-clock? ]
  let index 0

  repeat length users
  [
    set-current-plot-pen item index users  ;; set the pen to be the user-id at index
    ;; plot the data in info at the current index with the current pen
    ifelse use-clock?
    [ plotxy clock item index info ]
    [ plotxy (clock + 1) item index info ]
    set index index + 1
  ]
end 

;; plots a black line at the x-axis of the plot this-plot

to plot-x-axis [ this-plot ]
  set-current-plot this-plot
  set-current-plot-pen "x-axis"
  plotxy plot-x-min 0
  plotxy plot-x-max 0
end 

;; pick the column of an elevator to show in the plots
;; the plots are not shown unless plot-single? is true

to pick-elevator-to-plot
  if( mouse-down? )
  [
    let x-mouse ( round mouse-xcor )
    let y-mouse ( round mouse-ycor )
    ifelse( count turtles with [ pxcor = x-mouse ] = 1 )
    [
      set elevator-to-plot one-of turtles with [ pxcor = x-mouse ]
      stop
    ]
    [
      ask patch x-mouse y-mouse
      [
        if( count turtles-here = 1 )
        [
          set elevator-to-plot one-of turtles-here
          stop
        ]
      ]
    ]
  ]
end 

to-report selected-elevator
  if plot-all-elevators?
   [ report "everybody" ]
  ifelse is-turtle? elevator-to-plot
    [ report [user-id] of elevator-to-plot ]
    [ report "nobody" ]
end 

;; setup the position and velocity plot

to setup-plots
  clear-all-plots

  ;; set the list of users to the user-id's of the existing elevators
  set users []

  if any? turtles
  [
    set users [ user-id ] of turtles
    let initial-positions [ ycor-initial ] of turtles

    set-current-plot "Elevator Position vs. Intervals"
    setup-pens false
    plot-list initial-positions true

    set-current-plot "Elevator Velocity vs. Intervals"
    setup-pens true
  ]
end 

;; create pens for each of the existing elevators and color the pens to be the same color as
;; their corresponding elevator.  if bars? is true, set the pen mode to be 1 for bar mode.

to setup-pens [ bars? ]
  if any? turtles
  [
    let index 0
    let colors [ color ] of turtles

    repeat length users
    [
      create-temporary-plot-pen item index users
      if bars?
      [ set-plot-pen-mode 1 ]
      set-plot-pen-color item index colors
      set index index + 1
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Quick Start functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; instructions to quickly setup the model to run this activity

to setup-quick-start
  set qs-item 0
  set qs-items
  [
    "Teacher: Follow these directions to setup the HubNet activity."
    "Optional- Zoom In (see Tools in the Menu Bar) - optional"
    "Press the LOGIN button."
    "Everyone: Open up a HubNet Client on your machine and..."
    "type your user name, select this activity and press ENTER."
    "Teacher: Ask the students to set the velocity of their elevator at each interval."
    "When all the students are ready press the GO button to run an entire sample..."
    "...or press STEP to run one interval."
    "Teacher: To run the activity again with the same students press the RESET-ELEVATORS button"
    "Optional- Pick a single elevator to watch in the plots and..." "set PLOT-ALL-ELEVATORS? to OFF. - optional"

    "Teacher: To start the simulation over with a new group,..."
    "Have everyone logout of the activity."
    "Press the SETUP button."
    "Follow these instructions from the beginning again."
  ]
  set quick-start (item qs-item qs-items)
end 

;; view the next item in the quickstart monitor

to view-next
  set qs-item qs-item + 1
  if qs-item >= length qs-items
  [ set qs-item length qs-items - 1 ]
  set quick-start (item qs-item qs-items)
end 

;; view the previous item in the quickstart monitor

to view-prev
  set qs-item qs-item - 1
  if qs-item < 0
  [ set qs-item 0 ]
  set quick-start (item qs-item qs-items)
end 

;; copyright 2000

There are 2 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 14 years ago Elevators Download this version
Uri Wilensky almost 14 years ago Elevators Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.