Using Actions

From Multiagent Robots and Systems Group
Jump to: navigation, search

Kicking Video

Types of Actions

There are two type of actions currently implemented in Actions.py.

Kick('ball to kick', 'egocentric vector of direction to kick in', 'kick intensity')
Stun('agent to stun', 'duration in seconds')

'ball to kick' and 'agent to stun' are the references to the objects passed in balls and enemyTeam.

Stunning other agents:

Lets, modify the brain so that agents in team "A" can stun agents in team "B".We can add the following code to RunAtBallBrain.py, after we set deltaRot

if myTeam[0].team.name == "A":
   for agent in enemyTeam:
     actions.append(Stun(agent, 5))

This is fairly simple, we check what our team name is , if we are team A , we want to stun every agent in team B.

Now the stun range is not infinite and is restricted by the agent body, also repeated stun's do not add up, a stun is applied only if the agent is currently not stunned.

Kicking a Ball

Firstly we need to make it behave using laws of physics rather than manually setting its position.

Enabling a physics based ball When you create a ball in the simulator you can now mark it to be dynamic as follows.

ball = Ball(array([0, 0, 0]))
ball.isDynamic = True

Now in the fixedLoop() function you can call the ball's updatePhysics() method so that it is moved with physics. This is done as follows:

for ball in self.world.balls:
ball.updatePhysics(self.world)

The updatePhysics() method needs a reference to the world so that the ball knows the bounds and obstacles of the world so it can bounce off them.


The Kick Action

Now add the following lines to RunAtBallBrain.

actions.append(Kick(balls[0], array([1, 0, 0]), 100)

This tells the Agent to kick the ball forward(+ve x) with an intensity of 100.

If you run the simulator using the changes made to RunAtBAllBrain suggested above you should see the following results.