Make a Behavior - northern-bites/nbites GitHub Wiki

Pt I:

Write a behavior that makes the robot walk close to the ball, then stop.

For help, look at existing behaviors. Useful things to use are 'player.brain.nav.goTo(dest)' and RelRobotLocation.

You can make a set of new states in an existing player (pBrunswick, or pNone) or use this file to make a new pWalkToBall player (which may be simpler).

Good luck! [Here] (https://raw.github.com/wiki/northern-bites/nbites/WalkToBallStates.py) is one (very simple) solution. See if you can do better!

Pt. II:

1) Pan the head until a ball is found

*note: Found does not mean saw a ball for 1 frame. It means the ball was seen for a reliable amount of time. For example 5 frames in a row or 4 out of the last 6 frames

2) Walk toward the ball until it is 20 cm in front of the robot.

*note: the robot should actively be following the ball with its head while walking

3) Walk directly left until the ball is no longer seen

*note: again this does not mean losing the ball for one frame

**note: side-stepping might be unstable so get ready to catch your robot if it falls

4) Come up with a strategy for finding the ball, you can assume it isn't going to move

This should be structured the way we normally write a behavior so here are some conventions, rules, and tips:

  • All of the behaviors code can be found at .../nbites/src/man/behaviors

  • There are sub directories within behaviors. The important ones for you are navigator (where walking commands are defined), headtracker (where head motions are defined), player (this is where each 'player' or high-level set of behaviors are defined. This is where you will write your code as well).

  • Our behaviors are implemented as an FSA (https://en.wikipedia.org/wiki/Finite-state_machine), yours MUST be as well. Simply, think of the robot as having a number of states that it can occupy. At any moment it is in one of these states and that state has conditions that cause the robot to move to the next state. Each of the steps 1-4 should each be there own state. To understand the states look at CalibrationPanStates. 2 states simply oscillate between each other.

  • Transitions are given by

    return player.goNow('[name_of_next_state]') or

    return player.goLater('[name_of_next_state]')

    return player.stay()

Now means this frame, later means next frame. Stay means stay in this state. If not transitioning to another state, you must return player.stay(). Be careful, goNow can lead to an infinite loop:

def foo(player):

    # x is not actually a real variable of player, just for demo purposes

    if player.x < 100:

        ...

        ...

        ...

    else:

        return player.goNow('bar')

def bar(player):

    # x is not actually a real variable of player, just for demo purposes

    if player.x < 200:

        ...

        ...

        ...

    else:

        return player.goNow('foo')

if player.x is ever greater than 100, there will be an infinite loop.

  • Write the behavior in two files: p[your_name] and [your_name]States (e.g. pDnavarro.py and DnavarroStates.py)
  • the first file should look a lot like the file linked to after pBrunswick or pNone in Pt. I
  • the second file should look like the solution to Pt. I. Include the same first two states for playing and set. Set is the state entered after the chest button has been pressed a second time and playing is the state after the third chest button press. Playing should transition to the behavior. Following playing, you should define 4 states to execute the above behavior