University of Calgary
Rob Kremer
Group Assignment: Robot Soccer (sorta...)



CPSC 662/568: Agent Communication

Winter 2015

Department of Computer Science
Computer
Science

Note: This is an group assignment. The work is shared among the group members and each member is responsible for all of the work. For example, if there is plagiarism is foun d in the assignment, every member is responsible. The group is expected to do it's own work, and must properly cite any and all work taken from external sources.
Each member is responsible to carry their own portion of the workload. To this end, there is a peer assessment process where each member must assess each other member's contribution. Individual marks may differ based on the peer assessment, the instructor's assessment, and other factors.
Another note: You will need to download the CASA project and the iRobotCreate project to this assignment. For details, see the getting CASA and the iRobot code page.

room diagram Implement a CASA agent that plays robotic soccer. For this assignment, you will use a real robot and an overhead-mounted camera. The camera is an agent at 136.159.7.26:9001, which responds to commands allowing you to calibrate colors, request the position of the ball, and request the position and orientation of the robot (which will have a colored triangle mounted on the top of it). You should make use of

You should implement several command-line interface commands (specified below) using CASA's @LispAccesable annotation or its CasaLispOperator class (as discussed in class, see the class notes). You may implement other interface commands if you wish. You can communicate with the camera at port 9001 using request methods as specified in the *.init.lisp files under the "hints" section below. For example to get the position and angle of your robot (assuming it's color is green) from the camera, send the following message:

(request
:act get-color-position
:receiver 136.159.7.26:9001
:content "triangle,green"
)

You will get back a message like this:

(propose
:act discharge|request|get-color-position
:sender 136.159.7.26:9001
:receiver <you>
:content "triangle,(LIST 445 388 90)"
)

which means your robot is at coordinate (445,388) and has a heading of 90 degrees ("downward").

To request the position of the ball, use the following message similarly:

(request
:act get-color-position
:receiver 136.159.7.26:9001
:content "circle,red"
)

Your can recalibrate any color (or introduce new ones) on the camera by completely covering the center mark on the field with a sample of the color and sending the camera the following command:

(request
:act execute
:receiver 136.159.7.26:9001
:content "(camera-agent.calibrate-color \"<color>\")"
)

The colors "red", "blue", "green", "yellow", and "purple" are predefined, but you may wish the recalibrate them if lighting conditions change. These colors have been calibrated in daytime with the shades down, and the fluorescent lights turned on.

The basic requirements are:

Startup

At startup, the robot should just acknowledge it's ready by flashing lights, playing a short song, or something appropriate of your choice. (This is the default anyway for iRobotCreate.)

Commands

The agent should accept the following run-time commands:

You may implement other commands as appropriate.

Play

The game is simplified so your only objective is to get the ball into the target goal. The opposing team will try to get the ball into your goal. There are no rules, except for trying to get a goal. You do not necessarily need to pay any attention to the opposing team (as a matter of fact, this is recommended as your first try). You do not necessarily need to defend your goal. You do have to pay attention to bumps and overcurrents by stopping an taking appropriate action. If there is no real wall at the edge of the playing field, you may use your foot in place of the wall. The game ends as soon as someone scores a goal. If there is a goal scored, the server should beep (3 times). (Note that if I'm in my office, those beeps get annoying, so they will probably be turned off. I'll try to turn the sound up when I'm not there.) Bonus points for doing a victory dance when you have scored.

We will play two versions of the game:

  1. There will be only one robot per team. This is pretty simple: just get the "ball" in the right goal.
  2. There will be two robots per team. In this case, you can use actual strategy as you have one robot for offense and one for defence.

Notes

The State pattern is highly recommended to implement your controller.

You can download the basic iRobot software, just like CASA download, at the iRobotCreate download site.

Hints

The camera agent will NOT always give you accurate data as color recognition and pattern detection are difficult under changing light conditions. Be aware of this, and take all data with a grain of salt.

To support the conversations with the camera, your .ont.lisp file should look like this:

(declOntology "camera.CameraClientAgent"
      '("casa.TransientAgent") ; super ontologies
      '(
      (ont.assert isa-parent           "register-color" register)
      (ont.assert isa-parent           "get-color-position" get-info)
      (ont.assert isa-parent           "calibrate-color" get-info)
      (ont.assert isa-parent           "set-display" get-info)
      )
    )

Your .init.lisp file should look like this:

;the request content should contain <color>,<R>,<G>,<B>
(request-client "register-color" 
   `(jcall
      (jmethod (agent.get-class-name) "receiveRegisterColor" "casa.MLMessage") 
        agent (event.get-msg)
    )
  )

;the request content should contain <color>,<shape>
;the propose/discharge content contains <color>,<x>,<y>,<angle>
(request-client "get-color-position" 
   `(jcall
      (jmethod (agent.get-class-name) "receiveGetColorPosition" "casa.MLMessage") 
        agent (event.get-msg)
    )
  )
  
;the request content should contain <color> and your target should cover the centre circle in the image
;the propose/discharge content contains the average pixel color and the color is remembered
(request-client "calibrate-color"
   `(jcall
      (jmethod (agent.get-class-name) "receiveColorCalibration" "casa.MLMessage") 
        agent (event.get-msg)
    )
  )

To assist you if you have trouble with colors and need to calibrate, you can get a snapshot of the camera agent's view of the world by asking it for snapshot showing you the positions and orientations of the objects superimposed on an actual camera image.

simulated environmentThe assignment can also be done in a simulator environment. A simple agent running in the simulator environment is shown in the Lisp file below. These agens don't play soccer, they just chase the ball around aimlessly. You will need to downloaded the lastest copy of the iRobot software to run this file.

A few precautions about using the simulator environment:

Lisp script for simulated robot environment.
(let (
        (trace-tags "info5,warning,msg,iRobot,-boundSymbols,-policies9,-commitments,-eventqueue,-conversations")
        (trace-code 10) ; bit 1=off, 2=on, 4=to-monitor-window, 8=trace-to-file
        (sleep-time 2) ; time to sleep between starting dependent agents, adjust for slower machines
        )
  
        ;; Set the options for the agent running the commandline
        (agent.options :options.tracing T)
        (agent.options :options.tracetags trace-tags)
  
        ;(new-agent "casa.LAC" "ResearchLAC" 9000 :process "CURRENT" :markup "KQML" :trace :traceFile :traceTags "warning,msg,commitments,policies5")
        (sleep 2)
  
        (agent.new-agent "iRobotCreate.simulator.Environment" "RoomEnvironment" 5780 :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :markup "KQML")
        (sleep 5)
        (declare (integer width))    (setq width 2304)
        (declare (integer height))   (setq height 1384)
        (declare (integer goalCtrX)) (setq goalCtrX (/ width 2))
        (agent.tell ":5780" "(iRobot-env.new-bounds 2304 1382)") 
        (agent.tell ":5780" "(iRobot-env.new \"goal0\" \"Rectangle2D\" goalCtrX 25            (floor (/ width 3)) 50 :paint T :corporeal NIL :color #x8888FF)")
        (agent.tell ":5780" "(iRobot-env.new \"goal1\" \"Rectangle2D\" goalCtrX (- height 25) (floor (/ width 3)) 50 :paint T :corporeal NIL :color #xFFFF88)")
  
        (agent.tell ":5780" "(iRobot-env.puck :name \"puck\")")
        (agent.tell ":5780" "(iRobot-env.set \"puck\" :labeled NIL)")
        (agent.tell ":5780" "(iRobot-env.circle \"puck\" :color-name \"red\")")
  
        (agent.new-agent "iRobotCreate.simulator.CameraSimulation" "camera" 9001  :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :scale (/ 1280.0 width))
  
        (sleep-ignoring-interrupts 2)
        (agent.new-agent "iRobotCreate.iRobotCreate" "Alice2" 9100  :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :markup "KQML" :outstream "Alice.out" :instream "Alice.in")
        (agent.tell ":5780" "(iRobot-env.triangle \"Alice2\" :name \"red-tri\" :color-name \"purple\")")
        (agent.new-agent "iRobotCreate.iRobotCreate" "Bob2"   9101  :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :markup "KQML" :outstream "Bob.out" :instream "Bob.in")
        (agent.tell ":5780" "(iRobot-env.triangle \"Bob2\" :name \"green-tri\" :color-name \"green\")")
        (agent.new-agent "iRobotCreate.iRobotCreate" "Carol2" 9102  :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :markup "KQML" :outstream "Carol.out" :instream "Carol.in")
        (agent.tell ":5780" "(iRobot-env.triangle \"Carol2\" :name \"yellow-tri\" :color-name \"yellow\")")
  
        (sleep-ignoring-interrupts 2)
        (agent.new-agent "iRobotCreate.BallPusher" "ControllerOfAlice" 9200 :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :markup "KQML" :controls ":9100" :color "purple" :ball-color "red" :scale (/ width 1280.0))
        (agent.new-agent "iRobotCreate.BallPusher" "ControllerOfBob"   9201 :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :markup "KQML" :controls ":9101" :color "green"  :ball-color "red" :scale (/ width 1280.0))
        (agent.new-agent "iRobotCreate.BallPusher" "ControllerOfCarol" 9202 :LAC 9000 :process "CURRENT" :trace trace-code :traceTags trace-tags :markup "KQML" :controls ":9102" :color "yellow" :ball-color "red" :scale (/ width 1280.0))
    ) ;let   

 


UofC
CPSC 662/568: Agent Communication
Department of Computer Science

Last updated 2012-12-17 21:42
Rob Kremer