GoGo Cars2

No preview image

1 collaborator

55 Nathan Holbert (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 4.1beta3 • Viewed 281 times • Downloaded 26 times • Run 4 times
Download the 'GoGo Cars2' modelDownload this modelEmbed this model

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


WHAT IS IT?

HOW TO USE IT

THINGS TO NOTICE

THINGS TO TRY

EXTENDING THE MODEL

NETLOGO FEATURES

RELATED MODELS

CREDITS AND REFERENCES

Comments and Questions

Observer and Turtle Problems

Hi Nathan! Thanks for uploading the model. It looks like the problem is that plotting is something that should be done by the observer, but "speed", the thing that you're trying to plot, is a turtle-specific variable. So when you're telling the procedure do-plots to "plot speed", you're telling it to plot a turtle-specific value that's different for each car. So the plotting procedure thinks that it belongs to turtles, rather than to the observer. Depending on what you want, you could fix this by trying to plot some average of the car speeds, or by asking the plot procedure to plot the speed of each car, or something like that. Does that make sense?

Posted over 11 years ago

Plotting

Nice. I got the plot working and it looks ok so far. The velocity plot works great but I'm going to have to figure out a different way to try to plot "acceleration"...as it is speed change is so small (no matter how hard you press) that the line doesn't move enough... I guess I could create two plots, one for each velocity and acceleration. The acceleration one could have a smaller y range making the movement of the line more noticeable.

Posted over 11 years ago

Click to Run Model

extensions [gogo]
globals [serial-port blue-car-speed]
turtles-own [ speed speed-min speed1 speed2 speed-other ]
breed [ blue-cars blue-car ]                                             ;; moving car (blue)
breed [ other-cars other-car ]                                   ;; red car
breed [ trees tree ]                                             ;; stationary trees
breed [ stripes stripe ]

to setup
  clear-all
  ask patches [ setup-road ]
  make-stripes
  setup-cars
  if gogo:open? = false
    [set serial-port user-one-of "Select a port:" gogo:ports
      gogo:open serial-port
      repeat 5
      [ if not gogo:ping
      [ user-message "The GoGo Board is not responding." ] ]
      gogo:talk-to-output-ports [ "a" "b" "c" "d" ] ]
end 

to setup-road                                                     ;; patch procedure
  if ( pycor < 10 ) and ( pycor > -10 )
    [ set pcolor random white ]
end 

to make-stripes                                                   ;; create a turtle to draw
  create-stripes 1 [                                              ;; stripes on the road
    set color yellow
    set size 2
    set xcor -320
    set ycor 0
    set heading 90
  ]
  repeat 16 [
    ask stripes [
      pen-down
      fd 20
      pen-up
      fd 20
     ]
   ]
  ask stripes [ die ]                                            ;; kill drawing turtle
end 

to setup-cars
  set-default-shape turtles "car"
  create-blue-cars 1 [                                                  ;; create moving car
    set color blue
    setxy -20 -2.5
    set heading  90
    set speed start-speed
    set speed-min  0
    set speed2 speed
    set size 15
  ]
  
  create-other-cars 1 [                                             ;; create other car tree
    set shape "car"
    set color red
    setxy -70 7
    set size 15
    set heading 90
    set speed-other start-speed + 0.4                                    ;; set speed a tad faster
  ]                                                                 ;; than blue car
  create-trees 1 [                                                  ;; create surrounding trees
    set shape "tree"
    set color green
    setxy 0 15
    set size 20
  ]
  
  create-trees 1 [
    set shape "tree"
    set color green
    setxy 0 -15
    set size 20
  ]
  ifelse first-person?                                             ;; choose 1st or 3rd person view
    [ ride blue-car 1 ]
    [ follow blue-car 1 ] 
end 

to go
  ask blue-car 1 [
    set speed1 speed2                                             ;; set speed1 to previous speed
    ifelse gogo:sensor 1 > 1000                                   ;; sensor reads over 1000 when untouched
      [ set speed speed - 0.03 ]                                  ;; slows down when the sensor isn't pressed
      [ set speed speed + ( 1 / ( gogo:sensor 1 / 2 ) ) ]         ;; speed up when pressing sensor
    if speed < 0
      [ set speed 0 ]                                             ;; keeps speed from goign negative
    fd speed
    set speed2 speed                                              ;; set speed2 to new speed
     ]
  ask other-car 2 [
     fd speed-other
   ]
  tick
  do-plots
end 

to reset-cars
  ask blue-car 1 [                                                  ;; reset moving car
    setxy -20 -2.5
    set heading  90
    set speed start-speed
  ]
  
  ask other-car 2 [                                             ;; reset other car tree
    setxy -70 7
    set heading 90
    set speed-other start-speed + 0.4                               ;; set speed a tad faster
  ]                                                                 ;; than blue car
end 

to do-plots
  set-current-plot "Car-Stats"
  set-current-plot-pen "velocity"
  plot [speed] of blue-car 1
end 

There are 3 versions of this model.

Uploaded by When Description Download
Nathan Holbert about 10 years ago (Default description) Download this version
Nathan Holbert about 10 years ago (Default description) Download this version
Nathan Holbert about 10 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.