Changes between Initial Version and Version 1 of Python Quagents Client


Ignore:
Timestamp:
Aug 10, 2011 2:36:04 PM (13 years ago)
Author:
xwang
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Python Quagents Client

    v1 v1  
     1== Python Quagents Client ==
     2
     3=== Client.py: ===
     4This file contains the Client class. Clients connect to the server on port 6000. Each client stores information about it's name, id, commandid, etc. Calling the ready() function spawn a quagent. [[BR]]
     5NOTE: Sometimes calling ready() too fast will not spawn a quagent and the program will be stuck waiting for a response from the server. Calling setName() before ready() usually avoids this problem.
     6
     7=== Command.py ===
     8This file contains the Command class and the individual command classes that inherit from the Command class. Each individual command takes in a different number of parameters and has a unique opcode. Each command must be attached to a client which is done by calling the setExecuter() function. The command can then be executed by calling execute(). [[BR]]
     9NOTE: All the execute() function does is send the command to the server and then calls recv to wait for a response. I'm not sure if this is the correct way to do this. Executing multiple commands causes the received data to get screwed up at times so I included a time.sleep(0.05) after executing each command. There is also a bug with the responses from the radar command. The response seems to be broken up into two messages. The first message only contains the first line of the response and the second message contains everything else. The way execute() is implemented now only the first message is received.
     10
     11=== Example Code ===
     12Writing a script to control a quagent is very simple. See the following example.
     13{{{
     14# Main.py
     15import client
     16import command
     17import time
     18
     19agent = client.Client("127.0.0.1")      # Creates a quagent
     20agent.setName('Quagent')
     21agent.ready()                           # Spawn
     22
     23# Give commands to quagent by creating the command object and setting the quagent as the executor
     24fo = command.Follow('n')       
     25fo.setExecutor(agent)
     26fo.execute()
     27pu = command.PickUp('n')
     28pu.setExecutor(agent)
     29pu.execute()
     30ci = command.CheckInventory('n')       
     31ci.setExecutor(agent)
     32ci.execute()
     33pd = command.PutDown(0, 20, 'n')        # The parameters correspond to protocolzero. The last parameter is always the priority
     34pd.setExecutor(agent)
     35pd.execute()
     36ci.execute()
     37}}}