Robo-cup simulation

Robo-cup simulation preview image

1 collaborator

Tags

robocup 

Tagged by Steven R. Brenes Chavarría almost 11 years ago

robotics 

Tagged by Steven R. Brenes Chavarría almost 11 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 244 times • Downloaded 30 times • Run 0 times
Download the 'Robo-cup simulation' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;     Agentes inteligentes - Modelo de simulacion de la Rubocup
;;  
;;     Autores:
;;
;;        Steven R. Brenes Chavarría (sbrenes@una.cr)
;;        Martin Mendez 
;;
;;
;;     22/junio/2013    version 1.0
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


breed [bolas bola]        
breed [jugadores jugador]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;     VARIABLES GLOBALES
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals 
[
  marcador1       ; marcador para equipo 2 
  marcador2       ; marcador para equipo 1
  jornada         ; representa la jornada actual
  friccion        ; coeficiente de frinccion aleatorio, [0-1]
  tipo-jugador-1  ; 1. Representa un unidireccional
  tipo-jugador-2  ; 2. Representa un humanoide
]

to globals-init
  set marcador1 0
  set marcador2 0
  set jornada 1
  set tipo-jugador-1 1
  set tipo-jugador-2 1
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;     VARIABLES ESTATICAS POR AGENTE
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

jugadores-own 
[
  heading-futuro    ; representa la ruta futura
  distancia         ; distancia hacia la bola
  tipo-robot        ; tipo equivalente a las variables globales
  caido?            ; indica si el robot esta caido o levantado
  ultimo-movimiento ; indica la ultima vez que logro moverse
]

bolas-own
[
  velocidad        ; velocidad actual de movimiento, tiende a reducir la velocidad
]


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;     PROCEDIMIENTO DE INICIALIZACION
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to bolas-init
  set shape "circle"   
  set size 9          
  set color yellow   
  set velocidad 0    
end 

to p-init ;; inicializa las parcelas
  ask patches [set pcolor green]
  ask patches with [pxcor = 0] [set pcolor black]
  ask patches with [(pxcor < -180 and pycor < 40 and pycor > -40) or (pxcor > 180 and pycor < 40 and pycor > -40)]  [set pcolor white]  
end 

to equipo-init  
  create-jugadores cantidad-por-equipo
  [   
    set size 18
    set color red
    set shape "circle 2"
    set tipo-robot tipo-jugador-1
    set caido? false
    setxy -20 + (-1 * abs(random-xcor)) / 2 random-ycor       
  ]
  create-jugadores cantidad-por-equipo
  [ 
    set size 18
    set color blue
    set shape "circle 2"
    set caido? false
    set tipo-robot tipo-jugador-2
    setxy 20 + abs(random-xcor) / 2 random-ycor   
  ]  
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;     PROCEDIMIENTOS DE BOTONES
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ; establecer los colores de la cancha
  clear-all
  set friccion random 1
  globals-init
  p-init
  create-bolas 1 [bolas-init]
  equipo-init
  reset-ticks  
end 

to go
  tick
  if ticks > 3 * tiempo-por-encuentro * 60 [stop] ;; control de tiempos, para jornadas de 60 minutos por 3 encuentros
  if jornada != int (ticks / (60 * tiempo-por-encuentro)) + 1
  [
      reiniciar-sistema-posiciones
  ]
  set jornada int (ticks / (60 * tiempo-por-encuentro)) + 1  
  ;
  ;
  ;; Implementa la regla de que sólo el que esta más cerca puede recoger la bola
  ifelse mas-proximo
  [
    ask min-n-of 1 jugadores with [color = red ] [distancia] [perseguir-bola-equipo]
    ask min-n-of 1 jugadores with [color = blue] [distancia] [perseguir-bola-equipo]        
  ]
  [
    ask turtles with [color != yellow] [perseguir-bola-equipo]
  ]
  ;
  ; mover bolas
  ask bolas
  [
    bolas-rastrear   ; establece el valor del heading-futuro y las distancias entre los elementos
    bola-movimiento  ; mueve la bola, en caso del rebote contra la pared
    grafica          ; grafica las distancias
  ]
end 

to reiniciar-bola
  ask bolas
  [
    setxy 0 0
    set heading 0
    set velocidad 0
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;     PROCEDIMIENTOS DEL MODELO
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to perseguir-bola-equipo
  ;;
  let ejecutar? true;
  ifelse tipo-robot = 1
  [set heading heading-futuro]  ;; el robot unidireccional gira hacia donde el quiera
  [
    ; Probabilidad 2% de que se caiga y su movimiento sea levantarse por los proximos 9 segundos
    ifelse random 100 <= 2 or (caido? = true and ultimo-movimiento + 9 >= ticks)
    [
      set ejecutar? false
      set caido? true
      set shape "person"
    ]
    [
      set caido? false
      set shape "default"
      
      ; Obtener el heading entre 0 y 360
      while [heading-futuro > 360] [set heading-futuro heading-futuro - 360]

      ; Obtener vuelta mas corta hacia el heading-futuro
      ; opcionA sería quedarse como está
      let opcionB abs (heading - heading-futuro + 360)
      let opcionC abs (heading - heading-futuro - 360)
      if opcionB < 180 [set heading-futuro heading-futuro - 360]
      if opcionC < 180 [set heading-futuro heading-futuro + 360]

      ; Girar 15 grados como máximo
      if heading < heading-futuro
      [
        ifelse heading-futuro - heading >= 15
        [set heading heading + 15]
        [set heading heading-futuro]
      ]
      if heading > heading-futuro
      [
        ifelse heading - heading-futuro >= 15
        [set heading heading - 15]
        [set heading heading-futuro]
      ]
    ]
  ] 
  ;; si a variables es true se ejecuta el siguiente bloque
  ;; sino, simplemente se obvia
  if ejecutar?
  [
    set ultimo-movimiento ticks
    let velocidad-actual 0
    let masa-actual 0    
    ask bolas
    [
      ifelse [color] of myself = red
      [
        set velocidad-actual velocidad-robot-t1
        set masa-actual masa-robot-t1
      ]
      [
        set velocidad-actual velocidad-robot-t2
        set masa-actual masa-robot-t2
      ]
      ;
      ; 
      if distance myself < 10
      [
        set velocidad velocidad-resultante masa-actual velocidad-actual velocidad
        ifelse estrategia
        [
          let col [color] of myself
          ifelse col = red
          [set heading random 180]
          [set heading random 180 + 180]
        ]
        [set heading (heading + [heading] of myself) / 2]
      ]
    ]
    ifelse other jugadores in-cone (velocidad-actual + 15) 90 = no-turtles
    [forward velocidad-actual]
    [
      ; si el unidireccional no puede ir hacia adelante, intenta moverse hacia uno de los lados
      if tipo-robot = 1
      [
        set heading heading + 90
        ifelse other jugadores in-cone (velocidad-actual + 15) 90 = no-turtles
        [forward velocidad-actual]
        [
          set heading heading + 180
          if other jugadores in-cone (velocidad-actual + 15) 90 = no-turtles
          [forward velocidad-actual]
        ]
      ]
    ]
  ]
end 

to bola-movimiento  
  if pcolor = white
  [
    ifelse xcor > 0 
      [set marcador1 marcador1 + 1]
      [set marcador2 marcador2 + 1]    
    reiniciar-bola
    if reiniciar-posiciones
    [
      reiniciar-sistema-posiciones
    ]
  ]
  if abs pxcor = max-pxcor [ set heading (- heading) ]
  if abs pycor = max-pycor [ set heading (180 - heading) ]  
  forward velocidad
  ifelse velocidad >= 0.1
     [set velocidad velocidad - 0.1]
     [set velocidad 0]
end 

to reiniciar-sistema-posiciones
  ask jugadores with [color = red]  [setxy -20 + (-1 * abs(random-xcor)) / 2 random-ycor]
  ask jugadores with [color = blue] [setxy 20 + abs(random-xcor) / 2 random-ycor   ]
  reiniciar-bola      
end 

to bolas-rastrear
  let i 45
  let temp heading
  repeat 8
  [
    set heading i
    ask jugadores in-cone 200 45
    [
      set heading-futuro abs random 45 + i - 22.5 + 180
      set distancia distance myself
    ]
    set i i + 45
  ]
  set heading temp
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;     PROCEDIMIENTOS AUXILIARES
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to grafica
  set-current-plot "Distancia-entre-bolas"         
  set-current-plot-pen "pen-0"        
  plot  distancexy -180 0         
  set-current-plot-pen "pen-1"
  plot distancexy 180 0 
end 

to-report velocidad-resultante[masaRobot velocidadRobot velocidadBola]  
  report (friccion * masaRobot * (velocidadRobot - velocidadBola)  + masaRobot * velocidadRobot + masa-bola * velocidadBola) 
     / (masaRobot * masa-bola) * 1000
end 

to actualizarRobots[tipo]
  ifelse tipo = 1
  [
    ask jugadores with [color = red]
    [
      
      set tipo-robot tipo-jugador-1
    
      ifelse tipo-jugador-1 = 1
        [set shape "circle 2"]
        [set shape "default"]
    ]
  ]
  [
    ask jugadores with [color = blue]
    [
      set tipo-robot tipo-jugador-2
      
      ifelse tipo-jugador-2 = 1
        [set shape "circle 2"]
        [set shape "default"]
    ]
  ]
end 

There is only one version of this model, created almost 11 years ago by Steven R. Brenes Chavarría.

Attached files

File Type Description Last updated
Robo-cup simulation.png preview Preview for 'Robo-cup simulation' almost 11 years ago, by Steven R. Brenes Chavarría Download

This model does not have any ancestors.

This model does not have any descendants.